285
/
838
Nations Technologies Inc.
Tel
:
+86-755-86309900
:
Address: Nations Tower, #109 Baoshen Road, Hi-tech Park North.
Nanshan District, Shenzhen, 518057, P.R.China
11.3.9
Output compare mode
User can use this mode to control the output waveform, or to indicate that a period of time has elapsed.
When the capture/compare register and the counter have the same value, the output compare function’s operations
are as follow:
TIMx_CCMODx.OCxMD is for output compare mode, and TIMx_CCEN.CCxP is for output polarity. When
the compare matches, if set TIMx_CCMODx.OCxMD=000, the output pin will keep its level;if set
TIMx_CCMODx.OCxMD=001, the output pin will be set active;if set TIMx_CCMODx.OCxMD=010, the
output pin will be set inactive;if set TIMx_CCMODx.OCxMD=011, the output pin will be set to toggle.
Set TIMx_STS.CCxITF.
If user set TIMx_DINTEN.CCxIEN, a corresponding interrupt will be generated.
If user set TIMx_DINTEN.CCxDEN and set TIMx_CTRL2.CCDSEL to select DMA request, and DMA request
will be sent.
User can set TIMx_CCMODx.OCxPEN to choose capture/compare shawdow regisete using capture/compare preload
registers(TIMx_CCDATx) or not.
The time resolution is one count of the counter.
In one-pulse mode, the output compare mode can also be used to output a single pulse.
Here are the configuration steps for output compare mode:
First of all, user should select the counter clock.
Secondly, set TIMx_AR and TIMx_CCDATx with desired data.
If user need to generate an interrupt, set TIMx_DINTEN.CCxIEN.
Then select the output mode by set TIMx_CCEN.CCxP, TIMx_CCMODx.OCxMD, TIMx_CCEN.CCxEN, etc.
At last, set TIMx_CTRL1.CNTEN to enable the counter.
User can update the output waveform by setting TIMx_CCDATx at any time, as long as the preload register is not
enabled. Otherwise the TIMx_CCDATx shadow register will be updated at the next update event.
Here is an example.