PaulStoffregen / TimerOne

TimerOne Library with optimization and expanded hardware support
http://www.pjrc.com/teensy/td_libs_TimerOne.html
470 stars 209 forks source link

0 dutycycle not working, gives %100 duty when trying to set 0. #3

Open rac1 opened 9 years ago

rac1 commented 9 years ago

Hi Firstly,Thanks for your project! I noticed that, when i want to setpwmduty to 0, it makes dutycycle %100. I editted your library like that;

void TimerOne::setPwmDuty(char pin, int duty) { unsigned long dutyCycle = pwmPeriod;

dutyCycle *= duty; dutyCycle >>= 10;

if( duty<=0) //newly added line both protection and prevent 0 dutycycle error. dutyCycle=1;

oldSREG = SREG; cli(); if(pin == 1 || pin == 9) OCR1A = dutyCycle; else if(pin == 2 || pin == 10) OCR1B = dutyCycle; Serial.print(dutyCycle); SREG = oldSREG; }

PaulStoffregen commented 9 years ago

Should this be merged into the library? Normally you'd send a pull request for that?

This code appears to have the actual pin numbers, rather than TIMER1_A_PIN, TIMER1_B_PIN, TIMER1_C_PIN. Was it actually tested with this version of TimerOne? Older versions were hard-coded for only AVR, and only certain AVR chips but not others.