cancel
Showing results for 
Search instead for 
Did you mean: 

Timer with a relax period

Sigifredo
Associate

HI

I need a simple timer that can make a PWM signal BUT with custom pauses or a relax period every number of pulses ... I have the code working very well with no relax , but I do not know how to write the relax period in the timer script itself...

Here is my actual code :

void SwitchPulse(){
TimerPulse.pause();
PeriodCyc = (Current[curMark] + Current[curSpace]) * (F_CPU/1000000.0);
Prescaler = (PeriodCyc / MAX_RELOAD) + 1.0;
TimerPulse.setPrescaleFactor(Prescaler);
Overflow = (PeriodCyc + (Prescaler / 2.0)) / Prescaler;
TimerPulse.setOverflow(Overflow);
DutyCyc = Overflow*Current[curMark]/(Current[curMark]+Current[curSpace]);


pwmWrite(PinPulse,DutyCyc);

TimerPulse.refresh();
TimerPulse.resume();

}

 

 

I wonder if it can be done more directly with the timer registers...

 

 

 

 

3 REPLIES 3

You could perhaps use a pattern buffer for CCRx values that load via DMA triggered on the Update.

Then the length and circular nature of the buffer could be used to modulate the PWM active, and PWM inactive sequences/counts generated at the pin.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for the response... Any example of how to do that?

15+ Years ago, perhaps using SPL, today in Arduino, No

You could modulate the TIMx->CCRx settings in the Update interrupt too, if DMA isn't practical

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..