MSP430FR5972, CCS v7
Hello I need help to generate delay using Timer without ISR but Timer should be use in a single program the functions are
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
MSP430FR5972, CCS v7
Hello I need help to generate delay using Timer without ISR but Timer should be use in a single program the functions are
Even I also use this code for 5 sec but not working (it works for around 4.3 sec). code are below :
#include <msp430.h>
#include "stdint.h"
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Configure GPIO
P1DIR |= BIT0;
P1OUT |= BIT0;
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
TA0CCTL0 = CCIE; // TACCR0 interrupt enabled
TA0CCR0 = 20479;
TA0CTL = TASSEL_1 | ID_3 | MC_2; // ACLK, divider 1, continuous mode, clear
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
__no_operation(); // For debugger
}
// Timer0_A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer0_A0_ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer0_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
TA0CCR0 += 20479; // Add another second
P1OUT ^= P1OUT; // Toggle LED
}
plz reply
Section 3.2 of the User's Guide says:
… the CS module default configuration is:
LFXT is selected as the oscillator source for LFXTCLK. LFXTCLK is selected for ACLK (SELAx = 0) and ACLK is undivided (DIVAx = 0).[…] but LFXT is disabled. […] the fault control logic immediately causes ACLK to be sourced by LFMODCLK
And LFMODCLK is 5 MHz / 128 = 39 kHz, which would result in a delay of 4.2 s, which is exactly what you're seeing. (And MODCLK isn't too accurate to begin with.)
If you want to use a 32.768 kHz clock, you have to correctly start up the crystal. (See the example programs for how to do this.)
**Attention** This is a public forum