cancel
Showing results for 
Search instead for 
Did you mean: 

PWM change not initially happening

mlickess
Associate II
Posted on September 14, 2015 at 16:40

Hello Everybody.

I am observing some strange behavior on the scope for a PWM output. I am driving it at 800kHz with alternating high time of 400ns and 800ns.

In the TIM1_UP_TIM10_IRQHandler I am alternating the high time value: -

if(TIM1->CCR4 == 33)

{

TIM1->CCR4 = 66; /* pulse on for 800ns */

}

else

{

TIM1->CCR4 = 33; /* pulse on for 400ns */

}

On the scope I am looking for 800ns - 400ns - 800ns - 400ns

But I see 800ns - 800ns - 400ns - 400ns - 800ns - 800ns - 400ns - 400ns 

Thus two pulses at each high time.

I have the Auto-reload preload disabled (TIM1->CR1 ARPE bit = 0) so it is not buffering the previous value.

I was wondering it the register write was too slow at this speed and if DMA would help?

Any help appreciated!

Thank you

#pwm #timer-synchronisation
4 REPLIES 4
Posted on September 14, 2015 at 16:47

And you're using what part, running at what frequency?

800 KHz is on the high side for interrupts. Are you doing this code in the CC or Update Interrupt? Advancing the CCR in the CC interrupt, with preload, runs the risk of getting an interrupt twice within the same period.

Yes, if I were modulating a 400/800 ns pulse train, I'd put the pattern buffer in memory, and use DMA.

Yet another LED driver?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mlickess
Associate II
Posted on September 14, 2015 at 17:00

Yes, you're quite correct; another LED driver!

I'm running on a NUCLEO - F401RE dev board at 84MHz.

I am running in the update interrupt as I was concerned that the compare interrupt would fire twice if I advanced from 400 to 800, thus two interrupts for the same period.

I'm investigating the DMA process.

Thank you very much!

Matt
Posted on September 14, 2015 at 17:15

Yes, you're quite correct; another LED driver!

You should fish around on the forum some, this rapid modulation scheme and DMA has been covered before, several times.

The reference manual will help you associate specific TIM events with DMA channels/streams. TIM1 is 16-bit, others can be 32-bit so you have to watch the Half-Word vs Word settings for writing into CCRx/ARR registers.

You can decimate the interrupts using the DMA HT/TC ones instead, for larger run-lengths of LED lines.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mlickess
Associate II
Posted on September 14, 2015 at 17:47

Good advice,

Thank you!