This gits implements function millis()
known from
Arduino ecosystem.
What it does is that it counts number of milliseconds since the program started. It uses timer TA3, set to UP mode with
custom TA3CCR0
value.
When user runs function millis()
, it returns value from the counter.
This timer is set to UP mode. It means that the timer counts up to the value stored in TA3CCR0
register.
When the value stored in TA3CCR0
is reached, an interrupt is generated. In interrupt service routine, counter
TIMER_MS_COUNT
storing number of ms since the program started is incremented.
Since TA3 is sourced from SMCLK
(which itself is sourced from DCO
set to 1MHz) with divider set to 1, it means that
each second, timer is incremented by 1 000 000. And each millisecond, timer is incremented by 1 000. This is why
setting TA3CCR0
to 1 000 means, that each millisecond, and interrupt will be generated.
UART part of this Gist is just to show, that millis()
function is working properly.
In this Gist, delay()
function was implemented in a very naive way. It supports only most used CPU frequencies.
Thank you Keith Barkley and Bruce McKenney for helping me figure out why my code did not run.
- https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1030645/msp430fr50431-implementing-millis-function/3810669#3810669
- http://software-dl.ti.com/trainingTTO/trainingTTO_public_sw/MSP430_LaunchPad_Workshop/v4/Chapters/MSP430m06_TIMERS.pdf