本文介绍了XMega计时器和微秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从atxmega128a3u中释放一些数据,并且需要以最快4us的速度切换一个引脚,但是到目前为止,我还没有找到一个接近它的地方...
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...
在这里,我将计时器设置为88us,但是大约是146us.
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?
推荐答案
这是您的完整代码吗?如果是,控制器将在执行sei()之后复位;因为已经到达程序代码的末尾.在示波器上看到的延迟可能是启动时间和晶振建立时间.
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.
使用
while(true);
在主体末尾构造.
这篇关于XMega计时器和微秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!