Avatar for Montana

Montana

Member since Oct 2024 • Last active Oct 2024
  • 1 conversations
  • 1 comments

Most recent activity

  • in ESP32
    Avatar for Montana

    Issue

    I'm using the setWatch function on my esp32 board. How could one create a 'native' function to be called in the interrupt itself?

    From the documentation

    // Advanced: If the function supplied is a 'native' function (compiled or assembly)
    // setting irq:true will call that function in the interrupt itself
    irq : false(default)

    E.compiledC is unavailable for the esp32 board (understandably so) and I can't seem to find very much information on how to accomplish this. I've also begun trying to create a library to make some native code available following the guide here, but have had issues compiling.

    Context

    I'm working with a RobotDyn AC Dimmer that I want to be controlled by my esp32 board running Espruino. I have setWatch() function watching the Z-C pin from the dimmer board. When the watch fires, I can issue a quick pulse to the PSM pin on the dimmer board to engage the triac. The triac will then remain engaged until the next Z-C firing. Configuring the delay between when the Z-c pin pulses and when I send my PSM pulse should allow me to control the brightness. The issue that I'm running into is that the pulse sent to the PSM pin is too slow, resulting in a poor signal to the dimming board and flickering of attached lights. Here is some example code:

    // Define the required pins
    const zcPin = D34;
    const psmPin = D27;
    
    // Configure the pins
    pinMode(zcPin, 'input_pullup');
    pinMode(psmPin, 'output');
    
    setWatch(
            function() {
                // Send a brief 1ms pulse to the ZC pin
                digitalPulse(psmPin, true, 1);
            },
            zcPin,
            { repeat: true, edge:'rising', debounce: 0, hispeed : true}
    )
    

    Oscilloscope readings

    The yellow line is the reading from the ZC pin and the blue line is the reading from the PSM pin being output from the esp32. The yellow line is a constant and the blue line appears to be running and somewhat random. The blue line should be perfectly in sync with the yellow line and pulse immediately after the rising edge, but neither of these is happening. Additionally, the 1ms pulse being sent is also not 1ms.



    Postulated solution

    My idea for a solution to this is to have a bit of native code compiled such that I can call if from within the interrupt itself and achieve the required performance to achieve a consistent dimming.

Actions