AnsweredAssumed Answered

Issues Generating PWM on Timer 2

Question asked by Aaron Derbyshire on Jun 5, 2018
Latest reply on Jun 6, 2018 by Artur I

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

Outcomes