Hello all,
I need help in configure a timer in CTC mode to have an ISR every about 120ms. I was using the Atmega328 pro mini, but, I had to change the zero mini due to lake of memory and I didn't study Zero timers yet because I need to finish the project (a robot) for my grandson“s birthday till March 8th.
I am using a Adafruit library but I am only getting about 87ms with a prescaller value of 64 or 384ms with a prescaller of 256. I do not know how to change the compare value to adjust the time. The code I am using is the following:
#include <Arduino.h>
#include "Adafruit_ZeroTimer.h"
// timer tester
Adafruit_ZeroTimer zt3 = Adafruit_ZeroTimer(3);
//define the interrupt handlers
void TC3_Handler(){
Adafruit_ZeroTimer::timerHandler(3);
}
// the timer 3 callbacks
void Timer3Callback0()
{
// digitalWrite(12, LOW);
digitalWrite(12, digitalRead(12) ^ 1);
}
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
analogWriteResolution(10);
analogWrite(A0, 128); // initialize the DAC
Serial.begin(115200);
Serial.println("Timer callback tester");
/********************* Timer #3, 16 bit, two PWM outs, period = 65535 */
zt3.configure(TC_CLOCK_PRESCALER_DIV256, // prescaler
TC_COUNTER_SIZE_16BIT, // bit width of timer/counter
TC_WAVE_GENERATION_NORMAL_PWM // frequency or PWM mode
);
zt3.setCompare(0, 0xFFFF/16);
zt3.setCallback(true, TC_CALLBACK_CC_CHANNEL0, Timer3Callback0); // this one sets pin low
zt3.enable(true);
}
void loop() {
}
Your help is appreciated.
thanks in advance
regards
Manuel