PaulStoffregen / TimerOne

TimerOne Library with optimization and expanded hardware support
http://www.pjrc.com/teensy/td_libs_TimerOne.html
470 stars 209 forks source link

Add support for ATmega128 #67

Open nathancheek opened 3 months ago

nathancheek commented 3 months ago

This PR adds support for the ATmega128.

PWM Test Program

#include <TimerOne.h>

int pwmPinA = TIMER1_A_PIN;
int pwmPinB = TIMER1_B_PIN;
int pwmPinC = TIMER1_C_PIN;
float dutyCycleA = 30.0;
float dutyCycleB = 50.0;
float dutyCycleC = 70.0;

void setup() {
  Timer1.initialize(40);  // 40 us = 25 kHz
  Timer1.pwm(pwmPinA, (dutyCycleA / 100) * 1023);
  Timer1.pwm(pwmPinB, (dutyCycleB / 100) * 1023);
  Timer1.pwm(pwmPinC, (dutyCycleC / 100) * 1023);
}

void loop() {
}

The above program outputs the following waveforms on pins PB5, PB6, and PB7, respectively:

pwm_test

Interrupt Test Program

The examples/Interrupt/Interrupt.ino program outputs the following waveform on LED_BUILTIN (PB5):

interrupt_test