PWM output Experiment

First, the macro definition spaces

Such as: #ifndef __LED_H

Two, PWM

1, PWM is a pulse width modulation, referred to as pulse width modulation.

2, STM32 timer except TIM6 and 7. Other timers may be used to generate the PWM output. One senior set

When TIM8 is TIM1 and may generate up to seven PWM output simultaneously.
3, except for a few registers (ARR, PSC, CR1, etc.) in the previous chapter, we will use the four registers (general-purpose timers in only 3), to control the PWM output
Out. These four registers are: Capture / Compare mode register (TIMx_CCMR1 / 2), Capture / Compare Enable Register
(TIMx_CCER), capture / compare register (TIMx_CCR1 ~ 4) and the brake and dead register (TIMx_BDTR).
4, the capture / comparison mode register (TIMx_CCMR1 / 2), which registers a total of 2, TIMx _CCMR1
And TIMx _CCMR2. TIMx_CCMR1 control CH1 and 2, the control TIMx_CCMR2 CH3 and 4.
5, the capture / compare enable register (TIMx_CCER), this register controls all input and output through
Switch channel.
6, capture / compare register (TIMx_CCR1 ~ 4), the total of four registers corresponding to four input channels CH1 ~ 4.

Three, the PWM input mode

This model is a special case of the capture mode input, except for the following differences, input acquisition mode operation is the same:
● ICx two signals are mapped to the same input TIx.
● the two signals ICx edge-active, but opposite polarity.
● TIxFP wherein a signal is inputted as a trigger signal from the mode controller is configured to reset mode.
For example, you need to measure the length of the input (the TIMx_CCR1 Register) and the duty cycle (TIMx_CCR2 PWM signal on TI1
Register), the specific steps are as follows (depending on the value and frequency of the prescaler CK_INT)
● selecting the active input TIMx_CCR1: CC1S TIMx_CCMR1 register set 01 = (selected TI1).
● selecting the active polarity TI1FP1 (used to capture the data and clear counter TIMx_CCR1): set CC1P = 0 (rising edge).
● selecting the active input TIMx_CCR2: CC2S TIMx_CCMR1 register set 10 = (selected TI1).
● selecting the active polarity TI1FP2 (to capture data TIMx_CCR2): set CC2P = 1 (falling edge).
● choose effective trigger input signal: TIMx_SMCR register set TS = 101 (selection TI1FP1).
● configuration from the reset mode to the controller mode: set TIMx_SMCR in SMS = 100.
● Enable capture: TIMx_CCER register set CC1E = 1 and CC2E = 1.
 

Guess you like

Origin www.cnblogs.com/youwei666/p/11831767.html