Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
stm32:peripherals:timer_compare [2021/10/11 08:19] – frtt | stm32:peripherals:timer_compare [2022/12/28 08:00] (current) – ruan | ||
---|---|---|---|
Line 2: | Line 2: | ||
\\ {{timer_output.svg}} \\ \\ | \\ {{timer_output.svg}} \\ \\ | ||
- | |||
- | ===== Programming Example ===== | ||
- | |||
- | The code snippet bellow 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-> | ||
- | </ | ||
- | \\ | ||
- | |||
- | > {{logo_hal.svg? | ||
- | > [[https:// | ||
- | > [[https:// | ||
- | \\ | ||
===== Configuration Registers ===== | ===== Configuration Registers ===== | ||
- | ==== CCMR1/2 ==== | + | ==== TIMx_CCMR1/2 - Capture/ |
- | + | ||
- | Capture/ | + | |
\\ {{timer_reg_ccmr1.svg}} {{timer_reg_ccmr2.svg}} \\ \\ | \\ {{timer_reg_ccmr1.svg}} {{timer_reg_ccmr2.svg}} \\ \\ | ||
Line 53: | Line 20: | ||
|::: |110|PWM mode 1 - In upcounting, channel 1 is active as long as TIMx_CNT< | |::: |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< | |::: |111|PWM mode 2 - In upcounting, channel 1 is inactive as long as TIMx_CNT< | ||
- | |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).// | ||
**Input compare mode** | **Input compare mode** | ||
Line 70: | Line 32: | ||
|::: | |::: | ||
|::: | |::: | ||
+ | |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| | ||
- | ==== DIER ==== | + | **Select mode** |
- | DMA / Interrupt enable register | + | |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).// | ||
+ | |||
+ | ==== TIMx_DIER - DMA / Interrupt enable register | ||
\\ {{timer_reg_dier.svg}} \\ \\ | \\ {{timer_reg_dier.svg}} \\ \\ | ||
Line 83: | Line 55: | ||
|::: |1|CCx interrupt enabled| | |::: |1|CCx interrupt enabled| | ||
- | ==== CCER ==== | + | ==== TIMx_CCER - Capture/ |
- | + | ||
- | Capture/ | + | |
\\ {{timer_reg_ccer.svg}} \\ \\ | \\ {{timer_reg_ccer.svg}} \\ \\ | ||
Line 100: | Line 70: | ||
|::: |1|Capture/ | |::: |1|Capture/ | ||
- | ==== CCRx ==== | + | ==== TIMx_CCRx - Capture/ |
- | + | ||
- | Capture/ | + | |
\\ {{timer_reg_ccrx.svg}} \\ \\ | \\ {{timer_reg_ccrx.svg}} \\ \\ | ||
Line 109: | Line 77: | ||
|CCRx|15: | |CCRx|15: | ||
- | ===== Legend ===== | + | ==== TIMx_BDTR - Break and dead-time register |
- | \\ {{legende.svg}} \\ \\ | + | \\ {{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-> | ||
+ | </ | ||
+ | \\ |