Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rac1 opened this issue Apr 20, 2015 · 1 comment
Open

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

rac1 opened this issue Apr 20, 2015 · 1 comment

Comments

@rac1
Copy link

rac1 commented Apr 20, 2015

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants