Skip to content

Commit

Permalink
Use IntervalTimer on Teensy 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStoffregen authored and bhagman committed Jun 7, 2018
1 parent 283f75d commit dd9a17c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions SoftPWM_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
// allow certain chips to use different timers
#if defined(__AVR_ATmega32U4__)
#define USE_TIMER4_HS // Teensy 2.0 lacks timer2, but has high speed timer4 :-)
#elif defined(__arm__) && defined(TEENSYDUINO)
#define USE_INTERVALTIMER // Teensy 3.x has special interval timers :-)
#else
#define USE_TIMER2
#endif
Expand Down Expand Up @@ -53,5 +55,16 @@
OCR4C = (ocr); \
TIMSK4 = (1 << OCIE4A); \
})
#elif defined(USE_INTERVALTIMER)
#define SOFTPWM_TIMER_INTERRUPT softpwm_interval_timer
#ifdef ISR
#undef ISR
#endif
#define ISR(f) void f(void)
#define SOFTPWM_TIMER_SET(val)
#define SOFTPWM_TIMER_INIT(ocr) ({\
IntervalTimer *t = new IntervalTimer(); \
t->begin(softpwm_interval_timer, 1000000.0 / (float)(SOFTPWM_FREQ * 256)); \
})
#endif

0 comments on commit dd9a17c

Please sign in to comment.