Skip to content

Instantly share code, notes, and snippets.

@carlosdelfino
Created July 19, 2012 20:15
Show Gist options
  • Save carlosdelfino/3146470 to your computer and use it in GitHub Desktop.
Save carlosdelfino/3146470 to your computer and use it in GitHub Desktop.
// We'll use timers 3 and 4
HardwareTimer timer3(3);
HardwareTimer timer4(4);
void setup() {
// Pause the timer while we're configuring it
timer3.pause();
timer4.pause();
// Set up period
timer3.setPeriod(1000); // in microseconds
timer4.setPeriod(90); // in microseconds
timer3.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);
timer4.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);
timer3.setChannel1Mode(TIMER_OUTPUT_COMPARE);
timer4.setChannel1Mode(TIMER_OUTPUT_COMPARE);
timer3.setCount(0);
timer4.setCount(0);
timer3.setOverflow(3.,000);
timer4.setOverflow(30000);
timer3.setCompare(TIMER_CH1, 1000); // somewhere in the middle
timer4.setCompare(TIMER_CH1, 1000);
timer3.attachCompare1Interrupt(handler3);
timer4.attachCompare1Interrupt(handler4);
// Refresh the timer's count, prescale, and overflow
timer3.refresh();
timer3.refresh();
// Start the timer counting
timer3.resume();
timer4.resume();
}
void loop() {
}
void handler3(void) {
SerialUSB.println("Teste 1");
}
void handler4(void) {
SerialUSB.println("Teste 2");
}
@carlosdelfino
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment