MSP430 で高度なコンパイラー最適化を使用してタイマー A を使用しましたが、高度なコンパイラー最適化を使用するとタイマー コードが失敗することがわかりました。最適化を使用しない場合、コードは正常に動作します。
このコードは、1 ミリ秒のタイマー ティックを達成するために使用されます。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ミリ秒の割り込みを達成するために間違って使用していますか?