XMega Timer and Microseconds

馋奶兔 提交于 2019-12-11 03:30:24

问题


I'm trying to bit bang out some data out of an atxmega128a3u and need to toggle a pin as fast as 4us but so far I'm not getting anywhere close to that...

Here I'm setting my timer for 88us but am getting around 146us.

    int main(void)
    {

    //CRYSTAL SETUP
        OSC_XOSCCTRL = OSC_FRQRANGE_12TO16_gc | OSC_XOSCSEL_XTAL_16KCLK_gc; // 16Mhz Crystal
        OSC_CTRL |= OSC_XOSCEN_bm;
        while(!(OSC_STATUS & OSC_XOSCRDY_bm)); //Wait for crystal to stabilize.
        CCP = CCP_IOREG_gc;
        CLK_CTRL = CLK_SCLKSEL_XOSC_gc;
        //END CRYSTAL SETUP

        cli();
        TCC0.PERL = 0x80; //88us
        TCC0.PERH = 0x05;
        TCC0.CTRLA = 0x01;
        TCC0.INTCTRLA = 0x02;
        PMIC.CTRL = 0x02;
        sei();
    }
ISR(TCC0_OVF_vect) {
   PORTF.OUTTGL = PIN3_bm;
}

How can I get a faster and more accurate response time?


回答1:


Is that your complete code? If yes, the controller would reset after executing sei(); since the end of the program code has been reached. The delay you see on the oscilloscope probably is the start-up and crystal setup time.

Use a

while(true); 

construct at the end of the main. I put the volatile NOP instruction there to prevent the compiler from optimizing the empty while-loop away. You can omit it if there is any other code in the loop.



来源:https://stackoverflow.com/questions/28787388/xmega-timer-and-microseconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!