Files

60 lines
1.9 KiB
C++
Raw Permalink Normal View History

2023-03-17 11:59:21 +00:00
/*
* Interrupt and PWM utilities for 16 bit Timer1 on ATmega168/328
* Original code by Jesse Tane for http://labs.ideo.com August 2008
* Modified March 2009 by Jérôme Despatis and Jesse Tane for ATmega328 support
* Modified June 2009 by Michael Polli and Jesse Tane to fix a bug in setPeriod() which caused the timer to stop
* Modified Oct 2009 by Dan Clemens to work with timer1 of the ATMega1280 or Arduino Mega
* Modified April 2012 by Paul Stoffregen
* Modified again, June 2014 by Paul Stoffregen
2024-09-24 16:54:39 +00:00
* Modified July 2017 by Stoyko Dimitrov - added support for ATTiny85 except for the PWM functionality
2023-03-17 11:59:21 +00:00
*
* This is free software. You can redistribute it and/or modify it under
* the terms of Creative Commons Attribution 3.0 United States License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
*/
#include "TimerOne.h"
TimerOne Timer1; // preinstatiate
unsigned short TimerOne::pwmPeriod = 0;
unsigned char TimerOne::clockSelectBits = 0;
2024-09-24 16:54:39 +00:00
void (*TimerOne::isrCallback)() = TimerOne::isrDefaultUnused;
2023-03-17 11:59:21 +00:00
// interrupt service routine that wraps a user defined function supplied by attachInterrupt
2024-09-24 16:54:39 +00:00
#if defined (__AVR_ATtiny85__)
ISR(TIMER1_COMPA_vect)
{
Timer1.isrCallback();
}
#elif defined(__AVR__)
2023-03-17 11:59:21 +00:00
ISR(TIMER1_OVF_vect)
{
Timer1.isrCallback();
}
2024-09-24 16:54:39 +00:00
#elif defined(__arm__) && defined(TEENSYDUINO) && (defined(KINETISK) || defined(KINETISL))
2023-03-17 11:59:21 +00:00
void ftm1_isr(void)
{
uint32_t sc = FTM1_SC;
#ifdef KINETISL
if (sc & 0x80) FTM1_SC = sc;
#else
if (sc & 0x80) FTM1_SC = sc & 0x7F;
#endif
Timer1.isrCallback();
}
2024-09-24 16:54:39 +00:00
#elif defined(__arm__) && defined(TEENSYDUINO) && defined(__IMXRT1062__)
void TimerOne::isr(void)
{
FLEXPWM1_SM3STS = FLEXPWM_SMSTS_RF;
Timer1.isrCallback();
}
2023-03-17 11:59:21 +00:00
#endif
2024-09-24 16:54:39 +00:00
void TimerOne::isrDefaultUnused()
{
}