StefanWxx 2 Posted March 28, 2014 Share Posted March 28, 2014 Hello, I want to perform something simple like a time measurement. With AtTiny i can use the TCNT0 register/variable to read the current counter value and reset it with TCNT0 = 0; I used this Code for timer init: (MSP430G2533 ) TA1CCR0 = 1000-1; // Count limit (16 bit) TA1CCTL0 = 0x10; // Enable Timer A0 interrupts, bit 4=1 TA1CTL = TASSEL_2 + MC_1 + ID_0; // TASSEL_2 = SMCLK @ 1MHz, Up Mode, no prescaler Is this the correct syntax for reset the counter vaulue? TA1CTL |= TACLR How can i read the current counter value before it reaches the value TA1CCR0 ? Quote Link to post Share on other sites
basil4j 1 Posted March 28, 2014 Share Posted March 28, 2014 It might be different, but on the 430FR5xxx family, you simply read TAxR or TBxR, x being the timer number. So TA1R in your case. Again, this might be different for the G family, ive never used it and am new to the MSP Quote Link to post Share on other sites
StefanWxx 2 Posted March 28, 2014 Author Share Posted March 28, 2014 yes, it is! thanks for your quick response. .just read the datasheet. Timer_A register = TA1R I have long been looking for it, I could not bring in context 'Timer_A register' -> current counter value Quote Link to post Share on other sites
basil4j 1 Posted March 28, 2014 Share Posted March 28, 2014 Glad to help! Quote Link to post Share on other sites
pabigot 355 Posted March 28, 2014 Share Posted March 28, 2014 Reading TxR is the right answer to the first approximation. There are complexities, though. When the clock driving a timer is asynchronous to MCLK, a read of TxR may return garbage. If the clock source is much slower than MCLK, you can avoid this by reading in a loop until you see the same value twice (the "majority vote" technique). If the clock source is faster, you need to dedicate a capture/compare register and toggle CCIS0 in TxCCTL to synchronously capture the counter value. You can see code that implements these different read techniques in and around this part of BSP430's timer peripheral interface. Quote Link to post Share on other sites
StefanWxx 2 Posted April 3, 2014 Author Share Posted April 3, 2014 @@pabigot Thanky you very much for your hints, but I am overwhelmed with the very detailed timer.h file. Can you please direct me to a concrete example? Quote Link to post Share on other sites
pabigot 355 Posted April 3, 2014 Share Posted April 3, 2014 Thanky you very much for your hints, but I am overwhelmed with the very detailed timer.h file. Can you please direct me to a concrete example? Not really. The concrete examples simply invoke one of those functions. My intent was just to make you aware of issues that might become important in the future; most people use timers without worrying about these cases. In your original example, the timer is synchronous with MCLK because you're using SMCLK as the source, so you don't have anything to worry about. If you were using an external high-speed clock, you would need to be careful. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.