2015-11-14 10:02 AM
Hi.
I'm using timer in PWM mode to control LED. If output is always 1 (CCR register is equal to ARR), LED is green. If output is 0 (CCR is always 0), LED is red. If I set duty cycle to 50% at high frequency, LED is orange. And if I increase a prescaler when duty cycle is 50%, I achieve visible toggling.Now, I would like to achieve one more thing: When LED is constantly green, I would like to make it red for 200 ms when an error occurs and after that it should go back to green (CCR constantly equal to ARR). Of course, I would like to do that without looping in a while loop for 200 ms. Do you have any idea how to achieve that?I am using F303. #pwm2015-11-15 01:13 AM
How about a one-shot timer configured for 200ms?
If an error occurs, set the CCR register to zero and trigger the one-shot timer. Within the timer interrupt reset the CCR register to ''green'' (ARR).2015-11-15 06:36 AM
2015-11-15 07:06 AM
What frequency are you running the PWM? I don't see any reason why you'd spend 200ms waiting for something, if the PWM was 1KHz, you could just count 200 interrupts, and then switch the pulse width.
2015-11-15 08:00 AM
2015-11-15 10:29 AM
You can complexity by using a timer in trigged mutlibyte dma bursts, 1 byte is red
second byte is green, third is brown... for example. No interrupts at all just dma.But as allready mentioned why waist 200ms on waiting? Anti flicker is very low frequency process.2015-11-15 12:48 PM
2015-11-15 02:14 PM
So get a free running timer, and park a CC event 200 ms in the future. Have that interrupt or poll it periodically as your code runs on. ie TIM2->CCR1 = TIM2->CNT + 20000; for 10us ticker
You're really going to have to own your design and its constraints, and get a lot more familiar with the chip.2015-11-16 11:48 AM
I think I can do this with timer One-pulse mode. With increased prescaler, I could achieve 200 ms long pulse.
But is it possible to make inverted pulse? I mean, not pulse from 0 -> 1 and back to 0. But from 1 -> 0 and then back to 1.