现在在做的温控部分算法,需要每隔0.25s采集一次温度数据,然后计算出相应的控制量,并以PWM的形式输出。为了实现这个功能,时钟系统是不可或缺的,现就MSP430F5438A的时钟系统进行研究。
MSP430F5438A 里面有三个计时器,如下图所示
这三个计时器为TA0,TA1,TB0。TA0有5个capture/compare 寄存器, TA1有3个, TB0 有7个。
TA0 is a 16-bit timer/counter (Timer_A type) with five capture/compare registers. It can support multiple capture/compares, PWM outputs, and interval timing. It also has extensive interrupt capabilities. Interrupts may be generated from the counter on overflow conditions and from each of the capture/compare registers.
也就是说TA0计时器可以实现计时功能,也可以产生大量的中断,这些中断可以来自于计数器的溢出和每一个capture/compare寄存器。
好了,现在可以来深入了解这些东西了。
Timer_A features include:
• Asynchronous 16-bit timer/counter with four operating modes
• Selectable and configurable clock source
• Up to seven configurable capture/compare registers
• Configurable outputs with pulse width modulation (PWM) capability
• Asynchronous input and output latching
• Interrupt vector register for fast decoding of all Timer_A interrupts
就像其他的模块一样,Timer模块同样需要选择时钟,也需要选择模式,现将一些主要的寄存器列在下面:
(1)TAxR Register: Timer_A register. The TAxR register is the count of Timer_A.它会在时钟沿信号处增加或者降低,TAxR可以被软件读写,而且,当它溢出时,计时器会产生中断。
通过设置TACLR位,TAR可以清零,Setting TACLR also clears the clock divider counter logic (the divider setting remains unchanged) and count direction for up/down mode.
increments or decrements (depending on mode of operation) with each rising edge of the clock signal. TAxR can be read or written with software. Additionally, the timer can generate an interrupt when it overflows.
(2)