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

Wrong Output Freq on Teensy 3.2 #17

Open
zshivers opened this issue Aug 25, 2016 · 0 comments
Open

Wrong Output Freq on Teensy 3.2 #17

zshivers opened this issue Aug 25, 2016 · 0 comments

Comments

@zshivers
Copy link

I believe there is a bug in this library, related to the binary search tree logic in setPeriod().

The logic never sets clockSelectBits to 2, where the previous implementation (commented code) can.

Specific case which can cause incorrect frequency output:

#include <TimerOne.h>

void pulse(void);

void setup() {  
  pinMode(17, OUTPUT);
  Timer1.initialize(1e6/92); // 92 Hertz
  Timer1.attachInterrupt(pulse);
}

void loop() {
}

// create short pulse every interrupt
void pulse(void) {
  digitalWrite(17, LOW);
  delay(1);
  digitalWrite(17, HIGH);
}

The resulting logic probe capture, showing an output frequency of 185 Hz:
timerone-output

This bug seems not to be present when disabling the binary tree optimized code, and using the original version.

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

1 participant