ESP32 timers vs AVR timers
Posted: Sun Mar 15, 2020 11:34 am
Hi,
I am trying to port a few lines of code written for an Arduino Uno over to an ESP32.
This is the original code (found here https://github.com/madlabdk/touche/blob ... _graph.ino):
It's manipulating internal Timer 1 in order to generate different output frequencies on PIN 9 (which are then read from PIN 0).
From reading the ESP32 docs, concepts like "Output Compare Register" don't seem to exist in the ESP32 realm. Is there any way to make this work on an ESP32?
I am trying to port a few lines of code written for an Arduino Uno over to an ESP32.
This is the original code (found here https://github.com/madlabdk/touche/blob ... _graph.ino):
Code: Select all
#define steps 128
void setup ()
{
pinMode (9, OUTPUT);
TCCR1A = 0;
TCCR1B = 0;
TCCR1A |= (1 << COM1A0); // Toggle OC1A on Compare Match.
TCCR1B |= (1 << WGM12); // CTC mode
Serial.begin(57600);
}
void loop () {
for (int i = 0; i < steps; i++) {
TCCR1B &= 0xFE; // turns off timer
TCNT1 = 0; // resets timer counter register
OCR1A = i; // changes frequency step
TCCR1B |= 0x01; // turns on timer
Serial.print(i,DEC);
Serial.print(" ");
Serial.println(analogRead(0), DEC);
}
}
From reading the ESP32 docs, concepts like "Output Compare Register" don't seem to exist in the ESP32 realm. Is there any way to make this work on an ESP32?