定时器a在高编译优化模式下在msp430中的使用
我在MSP430中使用了高度编译器优化的定时器A,但发现当使用高度编译器优化时我的定时器代码失败。 当不使用优化时,代码可以正常工作。
此代码用于实现 1 ms 定时器滴答。 timeOutCNT 在中断中增加。
以下是代码,
//Disable interrupt and clear CCR0
TIMER_A_TACTL = TIMER_A_TASSEL | // set the clock source as SMCLK
TIMER_A_ID | // set the divider to 8
TACLR | // clear the timer
MC_1; // continuous mode
TIMER_A_TACTL &= ~TIMER_A_TAIE; // timer interrupt disabled
TIMER_A_TACTL &= 0; // timer interrupt flag disabled
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 500;
TIMER_A_TACTL &= TIMER_A_TAIE; //enable timer interrupt
TIMER_A_TACTL &= TIMER_A_TAIFG; //enable timer interrupt
TACTL = TIMER_A_TASSEL + MC_1 + ID_3; // SMCLK, upmode
timeOutCNT = 0;
//timeOutCNT is increased in timer interrupt
while(timeOutCNT <= 1); //delay of 1 milisecond
TIMER_A_TACTL = TIMER_A_TASSEL | // set the clock source as SMCLK
TIMER_A_ID | // set the divider to 8
TACLR | // clear the timer
MC_1; // continuous mode
TIMER_A_TACTL &= ~TIMER_A_TAIE; // timer interrupt disabled
TIMER_A_TACTL &= 0x00; // timer interrupt flag disabled
有人可以帮我解决这个问题吗?我们是否可以通过其他方式使用计时器 A,使其在优化模式下正常工作?还是我错误地使用了 1 ms 中断?
I have used timer A in MSP430 with high compiler optimization, but found that my timer code is failing when high compiler optimization used.
When none optimization is used code works fine.
This code is used to achieve 1 ms timer tick. timeOutCNT is increamented in interrupt.
Following is the code,
//Disable interrupt and clear CCR0
TIMER_A_TACTL = TIMER_A_TASSEL | // set the clock source as SMCLK
TIMER_A_ID | // set the divider to 8
TACLR | // clear the timer
MC_1; // continuous mode
TIMER_A_TACTL &= ~TIMER_A_TAIE; // timer interrupt disabled
TIMER_A_TACTL &= 0; // timer interrupt flag disabled
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 500;
TIMER_A_TACTL &= TIMER_A_TAIE; //enable timer interrupt
TIMER_A_TACTL &= TIMER_A_TAIFG; //enable timer interrupt
TACTL = TIMER_A_TASSEL + MC_1 + ID_3; // SMCLK, upmode
timeOutCNT = 0;
//timeOutCNT is increased in timer interrupt
while(timeOutCNT <= 1); //delay of 1 milisecond
TIMER_A_TACTL = TIMER_A_TASSEL | // set the clock source as SMCLK
TIMER_A_ID | // set the divider to 8
TACLR | // clear the timer
MC_1; // continuous mode
TIMER_A_TACTL &= ~TIMER_A_TAIE; // timer interrupt disabled
TIMER_A_TACTL &= 0x00; // timer interrupt flag disabled
Can anybody help me here to resolve this issue? Is there any other way we can use timer A so it works fine in optimization modes? Or do I have used is wrongly to achieve 1 ms interrupt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的变量(例如 timeOutCNT)是否在中断处理程序中被修改?
如果是这样,请确保将它们声明为
易失性
,例如,这可以防止编译器进行假设 timeOutCNT 未被中断处理程序或其他线程修改的优化。
Are any of your variables (e.g. timeOutCNT) modified in an interrupt handler?
If so, ensure that you declare them as
volatile
, e.g.This prevents the compiler from making optimisations that assume that timeOutCNT is not modified by interrupt handlers or other threads.