Any way to restart PWM on Timer0 (FTM0)

Status
Not open for further replies.
Hello Everyone,

I was just wondering if there would be any way to use a command similar to Timer1.restart() or Timer3.restart() on the additional PWM pins on FTM0.

I only need one pin to output PWM at a time and therefore if this were not possible, would the best way to accomplish another "pin" on one of these timers be to use two transistors as a sort of branching path? For example, using the emitter of each as a pin and connecting the collectors together on pin 3 (or 4, 25, 32).

I have attached an basic circuit schematic below (I know it says Arduino but it gets the point across hopefully).

TransistorSplitter.png

Thank you all for your help,
Jake


SOLUTION:

In case anyone else needs this functionality, you can use these functions directly inside the Arduino IDE to reset timer0.

Code:
void stopT() {
  FTM0_SC = FTM0_SC & (FTM_SC_TOIE | FTM_SC_CPWMS | FTM_SC_PS(7));
}
void resumeT() {
  FTM0_SC = (FTM0_SC & (FTM_SC_TOIE | FTM_SC_PS(7))) | FTM_SC_CPWMS | FTM_SC_CLKS(1);
}
void startT() {
  stopT();
  FTM0_CNT = 0;
  resumeT();
}

void restartT() {
  startT();
}
 
Last edited:
Would there be any way to do this or do you think it would create issues with core functions on the teensy?
 
Last edited:
As far as I can see, there is no risk of interfering with the core functions if you rewrite occasionally the counter register of a FTM channel.
 
Before saying anything more, I want to emphasize the DIY nature of directly accessing the hardware registers. You can accomplish a lot, but you're going to have to read the reference manual FTM chapter, or at least the first portion if you don't ever enable the other complex/advanced PWM features.

As you'll see documented in the reference manual, some registers are protected from writing while the FTM is running, or have other limitation of when and how they can be written. Other registers, mostly the PWM stuff, are double buffered and update the actual hardware at the beginning of each PWM cycle.

Whether frequent updating based on Ethernet communication or any other reason would cause problems depends on the specific details of *how* you do these writes, and to which registers. There's no single quick and easy answer. The fine details matter, which is why there's a detailed reference manual.
 
Thank you so much for your help Paul. Everything seems to be working per the code I posted above and thank you for pointing me in the right direction.
 
Status
Not open for further replies.
Back
Top