Problem with Timer1 on Teensy 3.1

Status
Not open for further replies.

Ira

Member
Using the Fan Speed example that comes with the Timer1 library everything works perfect except I can not figure out why I can't set a PWM percent higher than 55 or 56. 0-54% work perfect and then around 55 or 56 the actual percent (checked via oscilloscope) goes to zero. I've tried to follow the code in Timer1.h but my C++ is not nearly up to the task. Is there something I'm doing wrong?

Ira
 
So it's a bit later and I managed to make it work by making the following change to Timer1.h.

//FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_CPWMS | clockSelectBits | (sc & FTM_SC_TOIE);
FTM1_SC = FTM_SC_CLKS(1) | clockSelectBits | (sc & FTM_SC_TOIE);

Something with center aligned PWM it seems for as soon as I turned it off it worked just fine.

Sorry, given that I was just using the sample code you wrote and shipped with Teensyduino I didn't figure I needed to post it.

And thanks for the extra rapid response.

Ira
 
So I went back and tried to find the smallest piece of code that would cause the problem. It took a while but I figured it out and it's attached at the end of this message.

I eventually figured out that the center PWM has some limits with very slow PWM speed. Under something near 370 hz, the Timer1 PWM can no longer reach 100%. Changing the Timer1.h code as I showed above allows the PWM to work correctly below that frequency but also causes the actual frequency to double. I've tested the PWM down to 8hz with that change and it seems to work perfectly.


#include <TimerOne.h>
const int fanPin = 4;

void setup(void)
{
Timer1.initialize(1000000/10); // 40 us = 25 kHz
Serial.begin(9600);
}

void loop(void)
{
// slowly increase the PWM fan speed
//
for (float dutyCycle = 30.0; dutyCycle < 100.0; dutyCycle++) {
Serial.print("PWM Fan, Duty Cycle = ");
Serial.println(dutyCycle);
Timer1.pwm(fanPin, (dutyCycle / 100) * 1023);
delay(500);
}
}
 
OK, now that I have it all working for me is there interest in versions of Timer1 and maybe timer3 that work at much lower frequencies? If so would you like my modified version.
Also, is there a reason you choose center aligned PWM?

Ira
 
Status
Not open for further replies.
Back
Top