Hello TI community,
some less important text
I have switched from the MSP430 F series to the G series when doing things for personal use (cheaper and i can use the launchpad as a programmer - plus the F series is mostly overkill).
I'm starting off by programming some basic functionalities to make my future life with the G series easier.
what i try to do
Im trying to program a sleep function that puts the device to sleep for a defined time (either n seconds or n / 10 milliseconds), independent of the selected clock source and speed.
current status
I have written two functions:
- Initilization function with clock source (TACLK, ACLK ...) and clock speed as parameters (will be oboslete later as im looking to calculate this automated in future - if not external clock).
- sleep function with sleep time and unit (either s or 10th ms): the function calculates how many timer clocks are necessary to create a delay of the given time, calculates the number of necessary timer overflows and the number of cycles for the final timer run. Puts the device to LPM0 and wakes it after the calculated number of overflows and final run are done.
what is achieved
I ran tests with the timer set to 5 seconds and 50,000 1/10 ms, so 5 seconds in both cases. After each run, an LED is toggled.
I measured how long it takes to have the LED toggle five times and got good results (~ 25 seconds) using SMCLK. I tested 8MHz and 1MHz for the DCO and tried all SMCLK clock dividers for both. I also tested 12MHz with SMCLK dividers of 1 and 8.
the problem
There is one exception that does not lead to good results: Setting the SMCLK divider to 8 resulted in a total time of 36 seconds (1 MHz), 28 seconds (8MHz) and 27 seconds (12MHz) instead of 25 seconds. Any other SMCLK divider works well and leads to a result of 25±0,3 seconds (manually triggered stopwatch).
I would guess that my code works fine, as it works for all other dividers and for 1,8,12 MHz. I input the SMCLK frequency manually into the function, so a huge amount of values is covered by going from Div4 on 1MHz to Div0 at 12MHz. The SMCLK divider is not used in any calculation.
I do not understand why the system behaves differently as soon as the divider is set to 8 and would appreciate any hints and tips.
Thank you for your time and help,
Lars Heinrichs