cancel
Showing results for 
Search instead for 
Did you mean: 

Issues Generating PWM on Timer 2

Aaron Derbyshire
Associate II
Posted on June 05, 2018 at 17:09

Hi,

I have been doing a little work recently with the STM8S003k3 Discovery board, where I attempting to create a 800Hz signal with a 80/20 duty cycle. The issue I am experiencing is that I have no output on the pin!

Now I'm almost certain that loading values etc are correct and this is instead a order of operations issue, with that being said, what is the correct procedure for register configuration etc? 

At the moment I am working as follows:

1. Set HSI and enable clock to timer 2

2. Initialise GPIO for input floating no interrupt PB6 & PB7.

3. Initialise GPIO for output push-pull fast mode PD2 (Timer 2 CH3).

4. Set prescaler and set ARR (*MSB first), (**PSCR LSB first).

5. Set CCR3 with value to obtain 80% duty cycle.

6. Set CCER2->CC3P = 0, active high.

7. Set CCMR3->OCM = 6, PWM 1 mode.

8. Set CCER2->CC3E = 1, enable CAPCOM3 output.

9. Set CR1-> CEN = 1, run the timer.

I understand that there is constraints regarding the order in which certain registers can be set which I have tried to avoid. 

Can anyone see what I'm missing or suggest some recommendations? 

Many Thanks,

A.D

#timer-2 #pwm #stm8s #pwm-configuration
1 ACCEPTED SOLUTION

Accepted Solutions
Artur IWANICKI
ST Employee
Posted on June 06, 2018 at 09:05

Hi

Derbyshire.Aaron

‌,

The reason of this is that PD2 can be used as TIM2_CH3, but after you remap it within option bytes (using STVP or STVD). Option bytes are stored in non volatile memory, thus it would be kept till next reprogramming of those values.

By default PC3 is connected to TIm2_CH3.

Best Regards,

Artur

View solution in original post

3 REPLIES 3
Artur IWANICKI
ST Employee
Posted on June 06, 2018 at 09:05

Hi

Derbyshire.Aaron

‌,

The reason of this is that PD2 can be used as TIM2_CH3, but after you remap it within option bytes (using STVP or STVD). Option bytes are stored in non volatile memory, thus it would be kept till next reprogramming of those values.

By default PC3 is connected to TIm2_CH3.

Best Regards,

Artur

Aaron Derbyshire
Associate II
Posted on June 06, 2018 at 10:15

Hi

iwanicki.artur

,

Thank you forthe prompt response!

As you've mentioned I've clearly overlooked pinout!

But just to add completeness, I believe we have both made the same mistake, TIM2 CH3 is mapped by default to PA3.

Thanks for the spot! Immediately got it up and running.

Thanks,

A.D

Artur IWANICKI
ST Employee
Posted on June 06, 2018 at 10:30

Hi

Derbyshire.Aaron

You are right, screen switching + memory overflow effect Of course TIM2_CH3 is by default assigned to PA3. Thank you for your remark.

Was it possible for you to see PWMs on desired pins?

Best Regards,

Artur