cancel
Showing results for 
Search instead for 
Did you mean: 

Timer 3 PWM - strange behaviour on first pulse

Rogers.Gary
Senior II
Posted on February 18, 2015 at 23:50

Hello,

I am programming Timer 3 for PWM mode. Please see the attached image. The yellow trace is Timer 3, the green is Timer 4, which follows Timer 3 by a period of 180 degrees shift.

The top PWM train (Timer 3) seems to want to momentarily go high for about 100ms then low, and it doesn't agree with anything I am programming it for. There are supposed to be exactly 4 pulses at this frequency, which there are  - however, that first initial 100ms pulse is not supposed to be there. You can see that Timer 4 (green) follows Timer 3, including the initial pulse - which can be expected. I can post some code, but perhaps someone has experienced something like this before, or knows why it might be doing this. All the other pulses are perfectly fine, and behave exactly as expected.

If I insert a break right at the Timer 3 interrupt clear, the very first interrupt, before it's had a chance to process the interrupt, the scope trace shows the output pin for Timer 3 pin is HIGH, which does not make sense, as it's set as a ''GPIO_PuPd_NOPULL'', the same as Timer 4's pin, and that pin initializes and is low at the start.

It's a bit confusing as it doesn't appear to be related to the timer, but the pin configuration, yet both Timer 3 and 4 pins are configured exactly the same.

Any suggestions would be appreciated - thank you.

#timer-3-pwm
5 REPLIES 5
Posted on February 19, 2015 at 09:16

> I can post some code

Do so.

This most probably has nothing to do with GPIO setup.

JW

Rogers.Gary
Senior II
Posted on February 19, 2015 at 17:04

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6hr&d=%2Fa%2F0X0000000btf%2F_In8v_Ln_MF9x8lnUAEWSSpvFpRH4gmO4NM.dnMXi2U&asPdf=false
Posted on February 20, 2015 at 12:42

>     TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);         

>     TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Disable);        

RM0090, comment under TIMx_CCMR1.OC1PE bit description:

2: The PWM mode can be used without validating the preload register only in one-

pulse mode (OPM bit set in TIMx_CR1 register). Else the behavior is not guaranteed.

Similarly, in RM0090, 18.3.9 PWM mode:

You must enable the corresponding preload register by setting the OCxPE bit in the TIMx_CCMRx register [...]

So, enable preload, and if needed, force update through setting TIMx_EGR.UG (surely there is a function in the ''library'' for that, but I don't speak the library gobbledygook).

JW

PS. Don't cross-post; but if you must so, place a link in both instances to point to the other.

Posted on February 20, 2015 at 12:47

One more thing, did you check if those pins don't collide with on-board peripherals on the DISCOVERY board?

JW

Rogers.Gary
Senior II
Posted on February 20, 2015 at 18:26

wj,

Thank you for the post. It has proven very useful.

Problem resolved. The one thing I forgot is to check the already assigned peripheral mapping. That pin was assigned to the accelerometer.

I moved the mapping to channel 2 and it now functions as it should. Hopefully someone else that might have the same issue will find this post.