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 @@ -7,6 +7,7 @@
* 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 March 2021 by Hagen Patzke - add ESP32 support for TZXDuino on ODROID-GO
* 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 @@ -180,7 +181,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 @@ -287,14 +288,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
10 changes: 9 additions & 1 deletion config/known_16bit_timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,15 @@
#define TIMER1_B_PIN 11
//#define TIMER1_ICP_PIN 8
//#define TIMER1_CLK_PIN 5


// ATmega128
#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.2
author=Stoyko Dimitrov, Jesse Tane, Jérôme Despatis, Michael Polli, Dan Clemens, Paul Stoffregen, Hagen Patzke
author=Stoyko Dimitrov, Jesse Tane, Jérôme Despatis, Michael Polli, Dan Clemens, Paul Stoffregen, Hagen Patzke, Nathan Cheek
maintainer=Paul Stoffregen
sentence=Use hardware Timer1 for finer PWM control and/or running an periodic interrupt function
paragraph=
Expand Down