mirror of
https://github.com/k3ng/k3ng_rotator_controller.git
synced 2024-12-18 20:57:56 +00:00
43 lines
1.4 KiB
C++
Executable File
43 lines
1.4 KiB
C++
Executable File
/*
|
|
* Interrupt and PWM utilities for 16 bit Timer5 on ATmega640/1280/2560
|
|
* 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 Aug 2011 by RobotFreak to work with timer5 of the ATMega640/1280/2560 or Arduino Mega/ADK
|
|
*
|
|
* 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 <avr/io.h>
|
|
#include <avr/interrupt.h>
|
|
|
|
#define RESOLUTION 65536 // Timer5 is 16 bit
|
|
|
|
class TimerFive
|
|
{
|
|
public:
|
|
|
|
// properties
|
|
unsigned int pwmPeriod;
|
|
unsigned char clockSelectBits;
|
|
|
|
// methods
|
|
void initialize(long microseconds=1000000);
|
|
void start();
|
|
void stop();
|
|
void restart();
|
|
void pwm(char pin, int duty, long microseconds=-1);
|
|
void disablePwm(char pin);
|
|
void attachInterrupt(void (*isr)(), long microseconds=-1);
|
|
void detachInterrupt();
|
|
void setPeriod(long microseconds);
|
|
void setPwmDuty(char pin, int duty);
|
|
void (*isrCallback)();
|
|
};
|
|
|
|
extern TimerFive Timer5;
|