Timer, PWM, and comparator used in msp430 microcontroller
[Copy link]
1. The timer uses two methods: query and interrupt. Most logic chips have a greater ability to output 0 than to output 1.
(1) Query mode: TMSEL determines the working mode of the watchdog. If it is set to 1, the watchdog works in the timing mode. SSEL selects the clock source of the watchdog timer. SSEL is set to 1. IS0IS1 determines the output frequency of the watchdog timer. (Note: When using the query mode, the interrupt flag must be cleared)
main()
{
...
while(True)
{
if(IFG1&0x01)
{
P1OUT ^= 0x01; //Flip status
IFG &=0xfe; // Clear interrupt flag
}
}
}
(2) Interrupt mode: WDTCTL is set in the same way as the query mode. In addition, the interrupt enable bit (WDTIE, located at IE1.0) needs to be set so that the microcontroller can respond to this interrupt.
#pragma vector=WDT_VECTOR
__interrupt void WDT_ISR()
{
P1OUT ^= 0x01;
}
main()
{
...
while(True);
}
2.PWM (implemented using timer A)
(1) The DA effect can be achieved by increasing the frequency, but in some cases it still cannot meet the requirements. In this case, an integrator circuit is needed to obtain the ideal DA effect.
(2) Setting of TA: Compare/capture module control register: capture compare register CCRx.
Note: The output PWM cycle should be much smaller than the integral constant of the integral circuit. To improve DA accuracy, CCR0 should not be too small.
3. Comparator
|