Tool/software: Code Composer Studio
I'am trying to measure the operating time of the SPI slave device by timerA using SMCLK.
but result of timerA is weird.
It operates 400Hz. I measured it, but the accuracy was very high.
I need only 200 data, so it works only 0.5 second.
SMCLK (=MCLK) is 16MHz, input divider is 8, so..
The expected result is 1M.
16M / 8 / 2 = 1,000,000
but actual result is 930,000 ~ 950,000.
I didn't change LPM mode.
Interrupt and SPI communication are used while the SPI slave device is operating.
FLL is enabled. if disabled, result is around 770,000.
Why does this happen?
this code is my setting of timerA.
void init_timerA()
{
// starting the timer. user guide page 370
// TAIE - Timer_A interrupt enable. This bit enables the TAIFG interrupt request
// Timer_A clock source select 10b = SMCLK
// InputDivider. 0xC0 = /8
// ID. Input divider. 00b = /1, 11b = /8.
// ID_3 (3*0x40u) /* Timer A input divider: 3 - /8 */
// TASSEL1 = 10b = SMCLK\
// TASSEL0 = 01b = ACLK.
TA0CTL |= TASSEL1 + ID_3 + TAIE; // + 0xC0;
//CM0 = 0x4000 , 10b = Capture on falling edge
//CCIS_3 (3*0x1000u) /* Capture input select: 3 - Vcc */
//CAP (0x0100) /* Capture mode: 1 /Compare mode : 0 */
TA0CCTL0 = CM0 + CCIS_3; //
// 1. Write 1 to the TACLR bit (TACLR = 1) to clear TAxR, clock divider state, and the counter direction.
TA0CTL |= TACLR; // + TAIE; // Timer_A clear. Setting this bit resets TAxR, the timer clock divider logic (the divider setting remains unchanged), and the count direction.
// 2. If necessary, write initial counter value to TAxR.
TA0R = 0;
// 3. Initialize TAxCCRn.
TA0CCR0 = 50000;
// 16M / 8(div) / 400(Hz) = 5000.
// 4. Apply desired configuration to TAxIV, TAIDEX and TAxCCTLn.
// 5. Apply desired configuration to TAxCTL including to MC bits.
// Mode control
//00b = Stop mode: Timer is halted
//01b = MC0 = Up mode: Timer counts up to TAxCCR0
//10b = MC1 = Continuous mode: Timer counts up to 0FFFFh
//11b = Up/Down mode: Timer counts up to TAxCCR0 then down to 0000h
TA0CTL |= MC0;
}