Page 1 of 1

ESP32 interupt and timers

Posted: Fri Mar 10, 2023 6:18 pm
by SimonS
Hi
I need to do simple thing, but I got big problem!
My project is to make PID temperature control for water heater.
I need to control (cut) sinusoidal. This is easy job. I have one optocuppler to detect zero cross and then after xx time open SCR
I got one interpret to detect zero cross and start timer. When timer reach value open SCR and wait few uS and
Everything working random and non stable. ESP is crashing. What do I do wrong?

Code: Select all

void IRAM_ATTR vhod1_ISR() {      //interupt zero cross
  timerAlarmEnable(int_timer);  
}

void IRAM_ATTR prozi_SCR(){    // interupt timer
  digitalWrite(grelec,HIGH);
  delayMicroseconds(100);
  digitalWrite(grelec,LOW);
 timerAlarmDisable(int_timer);
}
 

Code: Select all

  attachInterrupt(nula, vhod1_ISR, RISING);   // zero cross interupt
  
  int_timer = timerBegin(0, 80, true);          // timer
  timerAttachInterrupt(int_timer, &prozi_SCR, true);
  timerAlarmWrite(int_timer, 1000000, true);
in ptogram I use timerWrite(int_timer, PID_value); to set new value of timer

Re: ESP32 interupt and timers

Posted: Mon Mar 13, 2023 2:55 pm
by noweare
Do you have a snubber network to control emi/spikes that occur when you open and close the scr.
Normally for a resistive load like a heater you do not need them. But it sounds like each time
the scr turns on/off you get emi that disturbs your esp32.

Can you move the scr further away from the esp32 for testing ?

Also they have Zero crossing Triac modules that turn on or off Triac at zero cross.
You will not have phase control but it may work for you. Basically instead of using the phase control
you use pwm to control the temperature. It will still work using PID control except change the output
to a pwm signal. So 50% pwm means the heat is on 50% of the time, etc.

Check out MOC3043M : 6-Pin DIP Zero-Cross Triac Driver Output Optocoupler
It will simplify your circuit quite a bit.

Re: ESP32 interupt and timers

Posted: Mon Mar 13, 2023 5:43 pm
by SimonS
Hi
Thanks for replay.
No there is nothing connected to board yet, so it cannot be disturbs.
I know PWM with zero-cross optocupler, but I'd like now this method. Like this I have control of direct power of heater. I have filling, that it will work better.