2015-09-14 07:40 AM
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 - 400nsBut 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-synchronisation2015-09-14 07:47 AM
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?2015-09-14 08:00 AM
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!Matt2015-09-14 08:15 AM
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.2015-09-14 08:47 AM
Good advice,
Thank you!