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 Compose Studio [CCS]
Sir,
I have using MSP430G2553 Launchpad development tool. I want to generate timer for 1 sec and 1 min.
So How can I configuration or generate specific value for this timer?
Thanks for the response.
I followed link that you have shared but In all timer based example based on cycle or assign value to CCR0.
But How can I calculate value for 1 sec or 2 sec, etc. timer delay?
If your SMCLK is running at 1MHz, and you set ID=3 (/8) and set CCR0=(65536-1) [as big as it gets], the timer will cycle in (65536*8)/1000000=about 524 ms, just over half a second. So getting a full second is not trivial. You could:
1) Set CCR0=62500-1 and ID=3, which will give you (62500*8)/1000000=0.5 seconds, then use an interrupt (TA0CCTL0:CCIE) to count to 2 half-seconds. You could probably adapt one of those Examples to do this.
2) Divide SMCLK by /2 using BCSCTL2:DIVS and set CCR0=62500-1 and ID=3. This has the unfortunate side-effect of changing all the other users of SMCLK, so I don't really recommend it.
3) If you're good (or even adequate) at soldering, enable the Launchpad's 32kHz crystal by moving R3/R9 according to the markings on the silkscreen. Then use TASSEL__ACLK and CCR0=32768-1 (and ID=0), which will give you a full second.
I think the only practical way to do 1 minute is by software.
[Edit: Showed my arithmetic. And then fixed a small mistake.]
Hi Bhautik,
I haven’t heard from you for a couple of days now, so I’m assuming you were able to resolve your issue.
If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information.
If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.
I have used below code for generate time for 10 sec. but I want to generate time for 5-6 min so how can i achieve that timer.
Let me know if any changes is require in below code.
// 10 seconds, assuming 32768 Hz ACLK source and divider 8
#define TIMER_PERIOD (10u * (32768 / 8))
void initTimer(void)
{
// reset timer A config (not strictly needed)
TACTL = TACLR;
// ACLK as clock source, divider 8, continuous mode, interrupt enabled
TACTL = TASSEL_1 | ID_3 | MC_2 | TAIE;
// set the period
TACCR1 = TIMER_PERIOD;
// enable capture/compare interrupts for CCR1
TACCTL1 = CCIE;
_enable_interrupts();
LPM1;
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A(void)
{
switch (TAIV) {
case 0x02:
print("TIMER INTERRUPT \r\n");
P1OUT &= ~RED;
// set the time of the next interrupt
TACCR1 += TIMER_PERIOD;
break;
}
}
Hi Bhautik,
You won't be able to do this with the timer alone. In the timer ISR you need to use a variable to keep track of the number of interrupts.
For example, if you set the timer to generate a 1sec timeout, in the ISR your variable is incremented every one second. When the variable reaches 300, then you know 5min (60sec x 5) has elapsed.
**Attention** This is a public forum