Skip to main content
Visitor II
June 6, 2024
Question

Timer with a relax period

  • June 6, 2024
  • 1 reply
  • 904 views

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...

 

 

 

 

    This topic has been closed for replies.

    1 reply

    Graduate II
    June 6, 2024

    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.

    SigifredoAuthor
    Visitor II
    June 6, 2024

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

    Graduate II
    June 6, 2024

    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