www.geehy.com Page 165
Input capture application
Input capture is used to capture external events, and can give the time flag to
indicate the occurrence time of the event and measure the pulse jump edge
events (measure the frequency or pulse width), for example, if the selected edge
appears on the input pin, the TMRx_CCx register will capture the current value of
the counter and the CCxIFLG bit of the state register TMRx_STS will be set to 1;
if CCxIEN=1, an interrupt will be generated.
In capture mode, the timing, frequency, period and duty cycle of a waveform can
be measured. In the input capture mode, the edge selection is set to rising edge
detection. When the rising edge appears on the capture channel, the first
capture occurs, at this time, the value of the counter CNT will be latched in the
capture register CCx; at the same time, it will enter the capture interrupt, a
capture will be recorded in the interrupt service program and the value will be
recorded. When the next rising edge is detected, the second capture occurs, the
value of counter CNT will be latched in capture register CCx again, at this time, it
will enter the capture interrupt again, the value of capture register will be read,
and the cycle of this pulse signal will be obtained through capture.
Output Compare
There are eight modes of output compare: freeze, channel x is valid level when
matching, channel x is invalid level when matching, flip, force is invalid, force is
valid, PWM1 and PWM2 modes, which are configured by OCxMOD bit in
TMRx_CCMx register and can control the waveform of output signal in output
compare mode.
Output compare application
In the output compare mode, the position, polarity, frequency and time of the
pulse generated by the timer can be controlled.
When the value of the counter is equal to that of the capture/compare register,
the channel output can be set as high level, low level or flip by configuring the
OCxMOD bit in TMRx_CCMx register and the CCxPOL bit in the output polarity
TMRx_CCEN register.
When CCxIFLG=1 in TMRx_STS register, if CCxIEN=1 in TMRx_DIEN register,
an interrupt will be generated; if CCDSEL=1 in TMRx_CTRL2 register, DMA
request will be generated.
PWM Output Mode
PWM mode is an adjustable pulse signal output by the timer. The pulse width of
the signal is determined by the value of the compare register CCx, and the cycle
is determined by the value of the auto reload AUTORLD.
PWM output mode contains PWM mode 1 and PWM mode 2; PWM mode 1 and
PWM mode 2 are divided into count-up, count-down and edge alignment
counting; in PWM mode 1, if the value of the counter CNT is less than the value
of the compare register CCx, the output level will be valid; otherwise, it will be
invalid.