Part Number: MSP430F5510
Hello,
I am trying to do an efficient blocking delay for my university project. What i have right now working:
volatile int32_t counter;
void timers_init(void) {
TA0CTL |= TASSEL__SMCLK | MC__UP;
TA0CCR0 = 16000; //SMCLK is 16MHz so this way we count to 1 ms every interrupt
}
void wait_ms(uint32_t delay) {
counter = delay;
TA0CTL |= TACLR;
TA0CCTL0 |= CCIE;
__bis_SR_register(LPM0_bits + GIE);
while(counter > 0);
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void timer0_A0_ISR(void) {
--counter;
if (counter == 0) {
__bic_SR_register_on_exit(LPM0_bits);
TA0CCTL0 &= ~(CCIE);
}
TA0CCTL0 &= ~(TA0IV_TA0IFG);
}
Is there any way to make it more efficient? The precision of the delay is not a priority but i don't want to settle by only "it's working"
Any help will be appreciated!