GD32F20x User Manual
340
and CHxDEN in TIMERx_DMAINTEN
Direct generation
: if you want to generate a DMA request or Interrupt, you can set CHxG by
software directly.
The input capture mode can be also used for pulse width measurement from signals on the
TIMERx_CHx pins. For example, PWM signal connect to CI0 input. Select channel 0 capture
signals to CI0 by setting CH0MS
to 2’b01 in the channel control register (TIMERx_CHCTL0)
and set capture on rising edge. Select channel 1 capture signal to CI0 by setting CH1MS to
2’b10 in the channel control register (TIMERx_CHCTL0) and set capture on falling edge. The
counter set to restart mode and restart on channel 0 rising edge. Then the TIMERx_CH0CV
can measure the PWM period and the TIMERx_CH1CV can measure the PWM duty.
Output compare mode
In output compare mode, the TIMERx can generate timed pulses with programmable position,
polarity, duration and frequency. When the counter matches the value in the CHxVAL register
of an output compare channel, the channel (n) output can be set, cleared, or toggled based
on CHxCOMCTL. When the counter reaches the value in the CHxVAL register, the CHxIF bit
is set and the channel (n) interrupt is generated if CHxIE = 1. And the DMA request will be
asserted, if CHxDEN = 1.
So the process can be divided to several steps as below:
Step1:
Clock Configuration. Such as clock source, clock prescaler and so on.
Step2:
Compare mode configuration.
* Set the shadow enable mode by CHxCOMSEN
* Set the output mode (Set/Clear/Toggle) by CHxCOMCTL.
* Select the active high polarity by CHxP/CHxNP
* Enable the output by CHxEN
Step3:
Interrupt/DMA-request enables configuration by CHxIE/CHxDEN.
Step4:
Compare output timing configuration by TIMERx_CAR and TIMERx_CHxCV
About the CHxVAL; you can change it on the go to meet the waveform you expected.
Step5:
Start the counter by CEN.
The timechart below shows the three compare modes toggle/set/clear. CAR=0x63,
CHxVAL=0x3
Summary of Contents for GD32F20 Series
Page 191: ...GD32F20x User Manual 191 Bits Fields Descriptions 31 0 TRNDATA 31 0 32 Bit Random data ...
Page 290: ...GD32F20x User Manual 290 conversion is ongoing ...
Page 325: ...GD32F20x User Manual 325 15 0 ALRM 15 0 RTC alarm value low ...
Page 385: ...GD32F20x User Manual 385 ...
Page 523: ...GD32F20x User Manual 523 clears AERR bit by writing 0 to it ...