The basic characteristics of PWM output of general timer 0/1/2 include 2 independent PWM outputs CHA, CHB, 1 complementary PWM output (CHA, CHB) + 1 independent PWM output (gate), 1 complementary PWM output (CHA, CHB) + 1 capture function (gate).
In the HC32L130_HC32L136 series user manual Rev1.8, the basic timer modes 2/3 are described together. The reason is that the functions are roughly the same in mode 2/3. The difference is that mode 2 is a sawtooth counting waveform, and mode 3 is a triangle counting waveform.
Comparison output OCREF can be configured as a single-point output, using the comparison register CCRA to control the output of OCREFA; OCREFA can also be configured as a dual-point comparison, using the comparison registers CCRA and CCRB to control the comparison output of OCREFA. For
OCREFB, only single-point comparison can be used, and the comparison register CCRB is used to control the comparison output of OCREFB.
OCREF output is selected using OCMx, where PWM mode 1/2 is selected, and the high and low levels of the two modes are opposite.
Sawtooth technology single point comparison OCREF output waveform (PWM mode 2)
The general process of OCREF comparison output of triangle wave counting single point comparison (PWM mode 2)
is as follows:
1. Configure the clock and enable;
2. Set the output pins of CHA and CHB;
3. Configure Tim0;
4. Set the reload value and comparison value;
5. Configure the channel comparison control structure.
Add interrupts, use the update event UEV generated by the repeat counter as the interrupt enable, and exchange the comparison values CCRA and CCRB to swap the waveforms of the dual channels every cycle.
Sawtooth mode output waveform
Triangle wave mode output waveform
Summary: By controlling the values of the two comparison registers CCRA and CCRB to control the duty cycle of the output waveform to output different waveforms.
For example: u16CompareAValue++;
Bt_M23_CCR_Set(TIM0, BtCCR0A, u16CompareAValue);
i++;
if(i == 65535)
{
for(i=65535;i--;i<1)
{
u16CompareAValue--;
Bt_M23_CCR_Set(TIM0, BtCCR0A, u16CompareAValue);
}
}Periodically control the duty cycle of the generated waveform.
|