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.
Tool/software: Code Composer Studio
Hi all,
I'm trying to implement a simple routine to toggle one Led every 10s.
For that, i would like to set the source ACLK which in this lunchpad is 32.768 kHz, in continuous mode and Input divider 1.
Timer(s) = 65535/ 32768 =~ 2s
Each overflow would occur within 2s. The problem is that, what i'm seeing is the the toggle frequency much lower than this. Can someone help me?
This is the code:
#include <msp430.h>
#include <hlcd.h>
unsigned Global_Timer0_Count = 0;
unsigned Global_Count = 0;
int main( void )
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
TA0CTL |= TACLR;
TA0CTL |= MC_2 | TASSEL_1 | ID_0;
TA0CTL |= TAIE;
P1DIR |= BIT0; // P1.0 is Led output
P1OUT = 0x01; // Set led on
PM5CTL0 &= ~LOCKLPM5;
__enable_interrupt();
__bis_SR_register(GIE); // LPM0 with interrupts enabled
while (1)
{
}
}
// Timer A0 interrupt service routine
#pragma vector = TIMER0_A1_VECTOR
__interrupt void TIMERA0_ISR0(void)
{
Global_Timer0_Count ++;
if(Global_Timer0_Count == 5){
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
Global_Timer0_Count = 0;
TA0CTL &= ~BIT0;
}
Hello Hernani,
I found a code example very similar to yours that uses Timer0_A to time an interrupt every 2 seconds to toggle P1.0. Use this link to the TI Resource Explorer in order to find the msp430fr413x_ta0_04.c project. Import this project and compare it to your code to see the difference and see how the example properly implements a 2 second interrupt.
Once you confirm that the code works and the interrupt fires every 2 seconds, then add your global variables to determine whether 10 seconds have passed to toggle your LED. Another possibility for you is to use the Timer clock divider in order to divide the Timer A clock down by 8 so that you don't have to use global variables to determine if 10 seconds have passed. When you divide the clock by 8, an overflow would occur at 16 seconds so then you'd have to use the Timer in "Up Mode" and count up to a certain value in TA0CCRx to determine if 10 seconds has passed.
Hope this helps!
Best regards,
Matt Calvo
**Attention** This is a public forum