ESP32 Arduino timer and interrupt Help is needed to make code for dimming

Imran-Aslam
Posts: 1
Joined: Tue Jun 26, 2018 7:55 pm

ESP32 Arduino timer and interrupt Help is needed to make code for dimming

Postby Imran-Aslam » Tue Jun 26, 2018 8:26 pm

Hello friends, i new to Arduino and specially with ESP32
I need a litter bit help from the community to make same code for esp32. Function i need
1. timer start
2. timer overflow
3. comparator and ISR for compair match

I am not able find proper function with flags for esp32 arduino.

#include <avr/io.h>
#include <avr/interrupt.h>
#define DETECT 2 //zero cross detect
#define GATE 9 //triac gate
#define PULSE 4 //trigger pulse width (counts)
void setup(){
// set up pins
pinMode(DETECT, INPUT); //zero cross detect
digitalWrite(DETECT, HIGH); //enable pull-up resistor
pinMode(GATE, OUTPUT); //triac gate control
// set up Timer1
//(see ATMEGA 328 data sheet pg 134 for more details)
OCR1A = 100; //initialize the comparator
TIMSK1 = 0x03; //enable comparator A and overflow interrupts
TCCR1A = 0x00; //timer control registers set for
TCCR1B = 0x00; //normal operation, timer disabled
// set up zero crossing interrupt
attachInterrupt(0,zeroCrossingInterrupt, RISING); //IRQ0 is pin 2. Call zeroCrossingInterrupt on rising signal
}
//Interrupt Service Routines
void zeroCrossingInterrupt(){ //zero cross detect
TCCR1B=0x04; //start timer with divide by 256 input
TCNT1 = 0; //reset timer - count from zero
}
ISR(TIMER1_COMPA_vect){ //comparator match
digitalWrite(GATE,HIGH); //set triac gate to high
TCNT1 = 65536-PULSE; //trigger pulse width
}
ISR(TIMER1_OVF_vect){ //timer1 overflow
digitalWrite(GATE,LOW); //turn off triac gate
TCCR1B = 0x00; //disable timer stopd unintended triggers
}
void loop(){ // sample code to exercise the circuit
OCR1A =450; //set the compare register brightness desired.
}

Who is online

Users browsing this forum: Majestic-12 [Bot] and 141 guests