Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion TimerOne.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Modified April 2012 by Paul Stoffregen - portable to other AVR chips, use inline functions
* Modified again, June 2014 by Paul Stoffregen - support Teensy 3.x & even more AVR chips
* Modified July 2017 by Stoyko Dimitrov - added support for ATTiny85 except for the PWM functionality
* Modified August 2024 by Nathan Cheek - added support for ATmega128
*
*
* This is free software. You can redistribute it and/or modify it under
Expand Down Expand Up @@ -171,7 +172,7 @@ class TimerOne

#elif defined(__AVR__)

#if defined (__AVR_ATmega8__)
#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega128__)
//in some io definitions for older microcontrollers TIMSK is used instead of TIMSK1
#define TIMSK1 TIMSK
#endif
Expand Down Expand Up @@ -278,14 +279,23 @@ class TimerOne

void attachInterrupt(void (*isr)()) __attribute__((always_inline)) {
isrCallback = isr;
#if defined(__AVR_ATmega128__)
TIMSK1 |= _BV(TOIE1);
TIMSK1 &= ~(_BV(TICIE1) | _BV(OCIE1A) | _BV(OCIE1B));
#else
TIMSK1 = _BV(TOIE1);
#endif
}
void attachInterrupt(void (*isr)(), unsigned long microseconds) __attribute__((always_inline)) {
if(microseconds > 0) setPeriod(microseconds);
attachInterrupt(isr);
}
void detachInterrupt() __attribute__((always_inline)) {
#if defined(__AVR_ATmega128__)
TIMSK1 &= ~(_BV(TOIE1) | _BV(TICIE1) | _BV(OCIE1A) | _BV(OCIE1B));
#else
TIMSK1 = 0;
#endif
}
static void (*isrCallback)();
static void isrDefaultUnused();
Expand Down
7 changes: 7 additions & 0 deletions config/known_16bit_timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@
//#define TIMER1_ICP_PIN 8
//#define TIMER1_CLK_PIN 5

#elif defined (__AVR_ATmega128__)
#define TIMER1_A_PIN 13 // PB5
#define TIMER1_B_PIN 14 // PB6
#define TIMER1_C_PIN 15 // PB7
#define TIMER1_ICP_PIN 22 // PD4
#define TIMER1_CLK_PIN 24 // PD6

// Sanguino
//
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=TimerOne
version=1.1.1
author=Stoyko Dimitrov, Jesse Tane, Jérôme Despatis, Michael Polli, Dan Clemens, Paul Stoffregen
author=Stoyko Dimitrov, Jesse Tane, Jérôme Despatis, Michael Polli, Dan Clemens, Nathan Cheek, Paul Stoffregen
maintainer=Paul Stoffregen
sentence=Use hardware Timer1 for finer PWM control and/or running an periodic interrupt function
paragraph=
Expand Down