Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
stm32:peripherals:timer_compare [2016/06/28 11:56] – created feur | stm32:peripherals:timer_compare [2022/12/28 08:00] (current) – ruan | ||
---|---|---|---|
Line 3: | Line 3: | ||
\\ {{timer_output.svg}} \\ \\ | \\ {{timer_output.svg}} \\ \\ | ||
- | ===== Programming Example | + | ===== Configuration Registers |
- | The code snippet bellow shows how to configure and use a GPIO pin as input. | + | ==== TIMx_CCMR1/ |
- | <code c> | + | \\ {{timer_reg_ccmr1.svg}} {{timer_reg_ccmr2.svg}} \\ \\ |
- | #include " | + | |
- | RCC-> | + | **Output compare mode** |
- | RCC-> | + | |
- | /* configure output */ | + | |< 100% 5em 5em >| |
- | GPIOA->MODER |= (0x2 << 0u); /* Set pin 0 to AF */ | + | |OCxM|000|Frozen - The comparison between the output compare register TIMx_CCR1 and the counter TIMx_CNT has no effect on the outputs.(this mode is used to generate a timing base).| |
- | GPIOA-> | + | |::: |001|Set channel 1 to active level on match. OC1REF signal is forced high when the counter TIMx_CNT matches the capture/compare register 1 (TIMx_CCR1).| |
- | + | |::: |010|Set channel 1 to inactive level on match. OC1REF signal is forced low when the counter TIMx_CNT matches the capture/ | |
- | /* configure basic timer */ | + | |::: |011|Toggle - OC1REF toggles when TIMx_CNT=TIMx_CCR1.| |
- | TIM2->PSC = 84000u | + | |::: |100|Force inactive level - OC1REF is forced low.| |
- | TIM2->ARR = 512u; /* Count to 512 */ | + | |::: |101|Force active level - OC1REF is forced high.| |
+ | |::: |110|PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT< | ||
+ | |::: |111|PWM mode 2 - In upcounting, channel 1 is inactive as long as TIMx_CNT< | ||
- | /* configure timer output | + | **Input compare |
- | TIM2-> | + | |
- | TIM2-> | + | |
- | + | ||
- | TIM2-> | + | |
- | </ | + | |
- | \\ | + | |
- | > {{logo_hal.svg? | + | |< 100% 5em 5em >| |
- | > [[https://ennis.zhaw.ch/hal/structreg__tim__t.html | + | |ICxF|0000|No filter, f<sub>DTS</ |
- | > [[https://ennis.zhaw.ch/hal/hal__timer_8h.html | + | |::: |
- | \\ | + | |::: |
+ | |::: | ||
+ | |::: | ||
+ | |::: | ||
+ | |::: | ||
+ | |::: | ||
+ | |ICxPSC|00|no prescaler, capture is done each time an edge is detected on the capture input (reset state)| | ||
+ | |::: |01| capture is done once every 2 events| | ||
+ | |::: |10| capture is done once every 4 events| | ||
+ | |::: |11| capture is done once every 8 events| | ||
- | ===== Configuration Registers ===== | + | **Select mode** |
- | ==== CCMR1/2 ==== | + | |CCxS|00|CCx channel is configured as output| |
+ | |::: |01|CCx channel is configured as input, ICx is mapped on TIx| | ||
+ | |::: |10|CCx channel is configured as input, ICx is mapped on TIx| | ||
+ | |::: |11|CCx channel is configured as input, ICx is mapped on TRC. This mode is working only if an internal trigger input is selected through TS bit (TIMx_SMCR register)| | ||
+ | |::: | |//*Note: CCxS bits are writable only when the channel is OFF (CCxE = ‘0’ in TIMx_CCER).//| | ||
- | Capture/ | + | ==== TIMx_DIER - DMA / Interrupt enable register |
- | + | ||
- | \\ {{timer_reg_ccmr1.svg}} {{timer_reg_ccmr2.svg}} \\ \\ | + | |
- | + | ||
- | ==== DIER ==== | + | |
- | + | ||
- | DMA / Interrupt enable register | + | |
\\ {{timer_reg_dier.svg}} \\ \\ | \\ {{timer_reg_dier.svg}} \\ \\ | ||
Line 54: | Line 55: | ||
|::: |1|CCx interrupt enabled| | |::: |1|CCx interrupt enabled| | ||
- | ==== CCER ==== | + | ==== TIMx_CCER - Capture/ |
- | + | ||
- | Capture/ | + | |
\\ {{timer_reg_ccer.svg}} \\ \\ | \\ {{timer_reg_ccer.svg}} \\ \\ | ||
|< 100% 5em 5em >| | |< 100% 5em 5em >| | ||
+ | |CCxNP|0|OC1N active high| | ||
+ | |::: |1|OC1N active low| | ||
+ | |CCxNE|0|Off - OC1N is not active. OC1N level is then function of MOE, OSSI, OSSR, OIS1, OIS1N and CC1E bits.| | ||
+ | |::: |1|On - OC1N signal is output on the corresponding output pin depending on MOE, OSSI, OSSR, OIS1, OIS1N and CC1E bits.| | ||
+ | |::: | |// | ||
+ | |CCxP|0|OC1 active high| | ||
+ | |::: |1|OC1 active low| | ||
|CCxE|0|Capture/ | |CCxE|0|Capture/ | ||
- | |::: | + | |::: |1|Capture/ |
+ | ==== TIMx_CCRx - Capture/ | ||
+ | \\ {{timer_reg_ccrx.svg}} \\ \\ | ||
- | ===== Legend ===== | + | |< 100% 5em 5em >| |
+ | |CCRx|15: | ||
- | \\ {{legende.svg}} \\ \\ | + | ==== TIMx_BDTR - Break and dead-time register ==== |
+ | |||
+ | \\ {{timer_reg_bdtr.svg}} \\ \\ | ||
+ | |||
+ | |< 100% 5em 5em >| | ||
+ | |MOE|0|OC and OCN outputs are disabled or forced to idle state. (reset state)| | ||
+ | |:::|1| OC and OCN outputs are enabled if their respective enable bits are set (CCxE, CCxNE in TIMx_CCER register).| | ||
+ | |||
+ | ===== Programming Example ===== | ||
+ | |||
+ | The code snippet below shows how to configure and use a GPIO pin as input. | ||
+ | |||
+ | <code c> | ||
+ | #include " | ||
+ | |||
+ | RCC-> | ||
+ | RCC-> | ||
+ | |||
+ | /* configure output */ | ||
+ | GPIOA-> | ||
+ | GPIOA-> | ||
+ | |||
+ | /* configure basic timer */ | ||
+ | TIM2-> | ||
+ | TIM2-> | ||
+ | |||
+ | /* configure timer output */ | ||
+ | TIM2-> | ||
+ | TIM2-> | ||
+ | |||
+ | TIM2-> | ||
+ | </ | ||
+ | \\ |