cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429 pwm

Daattavya Aggarwal
Associate II
Posted on August 09, 2017 at 20:05

I am using stm32f429 discovery board. When I use pwm on any timer, I am not getting correct outputs, that is my duty cycle is not matching the values in the ccr and arr registers.

void enable_gpio1()

{

RCC ->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;

GPIOA ->MODER |= GPIO_MODER_MODER6_1;

GPIOA ->OTYPER &= ~(GPIO_OTYPER_OT_6);

GPIOA ->OSPEEDR |= GPIO_OSPEEDER_OSPEEDR6_1;

GPIOA ->PUPDR &= ~(GPIO_PUPDR_PUPDR6);

GPIOA ->AFR[0] = GPIO_AF2_TIM3<<24;

}

void generate_pwm1()

{

TIM3 ->CCMR1 |= TIM_CCMR1_OC1M_2;

TIM3 ->CCMR1 |= TIM_CCMR1_OC1M_1;

TIM3 ->CCMR1 &= ~(TIM_CCMR1_OC1M_0);

TIM3 ->CCMR1 |= TIM_CCMR1_OC1PE;

TIM3 ->CR1 |= TIM_CR1_ARPE;

TIM3 ->EGR |= TIM_EGR_UG;

TIM3 ->CCER &= ~(TIM_CCER_CC1P);

TIM3 ->CCER |= TIM_CCER_CC1E;

TIM3 ->ARR = 500;

TIM3 ->CCR1 = 450;

TIM3 ->CR1 |= TIM_CR1_CEN;

}

Now on changing the values of ARR and CCR, the output is not matching. I am using upcounting mode.

#stm32 #pwm
3 REPLIES 3
Posted on August 09, 2017 at 20:32

Hi..

What you mean when you say ' the output is not matching.'?

for example if ARR=500-1  means 500 microsecond cycle , then if ARR=3000-1 the result must be 3000 usec cycle

You mean that have different kind of results when you change this value? (or ccr value)?

Posted on August 09, 2017 at 23:08

Hi. What I mean is the voltage across the pwm pin and ground pin is not varying in proportion to the changes I make in the values of the arr and ccr registers. For example, the if arr = 500 and ccr = 100, then the output voltage is almost the same as when arr = 500 and ccr = 200. According to the user manual I should get duty cycles of 100/500 * 100 and 200/500 * 100 ( In percentages).

Posted on August 10, 2017 at 01:25

Hi !

>> What I mean is the voltage across the pwm pin and ground pin is not varying in proportion to the changes

But PWM is pulse width modulation , digital pulses.

0690X00000607gEQAQ.png

In case you use an intergator after output(resistor-capacitor) you must have in mind the internal resistance of the GPIO output. (to add to your, in series resistor, and to calculate after the capacitor)

0690X00000607jSQAQ.png

Just remember that the Delta voltage of the capacitor  charged by a const voltage via a resistor, is

not proportional

to  width of pulse  .

So If you want to convert PWM to voltage, choose the resistance of intergrator to be multiple of intternal resistance to have a good dynamic range, and of course a small (nF scale) capacitor , to observe to an oscilloscope.

Arr changes the frequency ( cycle period)  and CCR the duty cycle  (0-100%)