AC dimmer / ESP32-Wroom32d
Posted: Mon Mar 06, 2023 8:08 pm
Hello, I am making Leading Edge AC dimmer with ESP32-Wroom32d. I have problem with esp timer intterupts.
So I want to create a delay after zero-crossing(z.c.) (7ms) and then turn on Ac Pump and leave it on untill next z.c..
My problem is that timer interupt generates nonuniform pulses visible in the attachments (screenshot from osiloscope.)
What am I doing wrong?
code:[Codebox]/*
* timer_frequency = clock_frequency / prescaler
* timer_duration = 7ms
* B = timer_frequency * timer_duration
* B = (80MHz / 16) * 7ms
* B = 35000
*
*
*/
volatile int B = 0;
hw_timer_t * timer = NULL;
int pumpa = 26;
void IRAM_ATTR skozi_nic() {
digitalWrite(pumpa, LOW);
timerAlarmWrite(timer, B, true);
timerAlarmEnable(timer);
}
void IRAM_ATTR tim0_poln() {
timerAlarmDisable(timer);
digitalWrite(pumpa, HIGH);
}
void setup() {
pinMode(pumpa, OUTPUT);
Serial.begin(115200);
timer = timerBegin(0, 16, true); // timer 0, prescaler 16, count up
timerAttachInterrupt(timer, &tim0_poln, true);
//timerAlarmWrite(timer, 240, true);
attachInterrupt(digitalPinToInterrupt(17), skozi_nic, RISING);
}
void loop() {
Serial.println("Dimmer zatemnitev");
B = 35000; // 5000
}[/Codebox]
So I want to create a delay after zero-crossing(z.c.) (7ms) and then turn on Ac Pump and leave it on untill next z.c..
My problem is that timer interupt generates nonuniform pulses visible in the attachments (screenshot from osiloscope.)
What am I doing wrong?
code:[Codebox]/*
* timer_frequency = clock_frequency / prescaler
* timer_duration = 7ms
* B = timer_frequency * timer_duration
* B = (80MHz / 16) * 7ms
* B = 35000
*
*
*/
volatile int B = 0;
hw_timer_t * timer = NULL;
int pumpa = 26;
void IRAM_ATTR skozi_nic() {
digitalWrite(pumpa, LOW);
timerAlarmWrite(timer, B, true);
timerAlarmEnable(timer);
}
void IRAM_ATTR tim0_poln() {
timerAlarmDisable(timer);
digitalWrite(pumpa, HIGH);
}
void setup() {
pinMode(pumpa, OUTPUT);
Serial.begin(115200);
timer = timerBegin(0, 16, true); // timer 0, prescaler 16, count up
timerAttachInterrupt(timer, &tim0_poln, true);
//timerAlarmWrite(timer, 240, true);
attachInterrupt(digitalPinToInterrupt(17), skozi_nic, RISING);
}
void loop() {
Serial.println("Dimmer zatemnitev");
B = 35000; // 5000
}[/Codebox]