AC Motor Control HUZZAH32 ESP32

Hello,

I am trying to convert the zero crossing detection for speed modulation of an AC motor over to ESP 32 and I am having trouble finding the information I need. Currently I have a .cpp and .h library that uses a MOC3010M and a H11AA1 to get the zero crossing and then control a gate to send out AC voltage that is cut exposing the motor to different amount of AC thus changing the speed. However my working code is for an Arduino Uno and I would like to switch over to the HUZZAH ESP32 that I bought with the Featherwing touch screen.

Arduino has alot of different registers that can be used to get the timer value, trigger interupts compare values ([TCNT1] [TCCR1A / TCCR1B] [OCR1A] [ICR1] [TIMSK and TIFR]). http://www.avrbeginners.net/architectur ... imers.html

What is used for ESP32 instead? I can find basic timer and alarm but that is with predetermined time amounts. https://techtutorialsx.com/2017/10/07/e ... nterrupts/

Below the main segment of code that needs to be replaced. Any suggestions?

// Interrupt Service Routines ISR (PCINT2_vect) { // Peak detection pin - must be one of PORTD pins (digital pin 0-7). ACControl::PCINT2_ISR(); }

void ACControl::PCINT2_ISR() { if (switchState == NORMAL || switchState == SWITCH_ON) { // Make sure we're not in full on or full off mode. if (digitalRead(syncPin) == LOW) { // Falling edge detected. OCR1A = TCNT1 + ZC_DELAY; // Set the comparator A to ZC_DELAY from the current reading of the counter. TCCR1B = 0x03; // Start timer with divide by 64 input = 4 us per tick at 16 MHz. peakDetected = true; // We just detected a peak. } } }

ISR(TIMER1_COMPA_vect) { // Comparator A match: zero crossing is now. ACControl::OCR1A_ISR(); }

void ACControl::OCR1A_ISR() { if (switchState == SWITCH_ON) { // Switch on at zero crossing. - for ACControl: on() digitalWrite(gatePin, HIGH); // Switch on the TRIAC constantly. switchState = ON; // Record that we're now switched on. TCCR1B = 0x00; // Disable timer; we just want to keep it on. } else { OCR1B = TCNT1 + pulseDelay; // Set the comparator B to start the TRIAC pulse at pulseDelay from now. peakDetected = false; // No peak yet within this switching cycle. } }

ISR(TIMER1_COMPB_vect) { // Comparator B match: time to switch the TRIAC (on or off). ACControl::OCR1B_ISR(); }

void ACControl::OCR1B_ISR() { if (gateOn == false) { // Gate is off, so we have to switch on the TRIAC now. digitalWrite(gatePin, HIGH); // Set TRIAC gate to high. (AC goes through to motor) gateOn = true; // Record TRIAC state. OCR1B += PULSE; // When PULSE ticks passed, we have to come back and switch off the gate again. } else { digitalWrite(gatePin, LOW); // Set TRIAC gate to low. (AC is stopped) gateOn = false; // Record TRIAC state. if (peakDetected == false) { // No peak detected yet, so we switched before the next peak. TCCR1B = 0x00; // Disable timer to stop unintended triggers. } }