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.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
Tips:
Create headers by underlining text with ==== or ----
To *italicise* text put one asterisk each side of the word
To **bold** text put two asterisks each side of the word
Embed images by entering: ![](https://www.google.co.uk/images/srpr/logo4w.png) That's the hard one: exclamation, square brackets and then the URL to the image in brackets.
* Create lists by starting lines with asterisks
1. Create numbered lists by starting lines with a number and a dot
> Quote text by starting lines with >
Mention another user by @username
For syntax highlighting, surround the code block with three backticks:
```
Your code goes here
```
Just like Github, a blank line must precede a code block.
If you upload more than 5 files we will display all attachments as thumbnails.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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
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 thePSM
pin on the dimmer board to engage the triac. The triac will then remain engaged until the nextZ-C
firing. Configuring the delay between when theZ-c
pin pulses and when I send myPSM
pulse should allow me to control the brightness. The issue that I'm running into is that the pulse sent to thePSM
pin is too slow, resulting in a poor signal to the dimming board and flickering of attached lights. Here is some example code:Oscilloscope readings
The yellow line is the reading from the
ZC
pin and the blue line is the reading from thePSM
pin being output from the esp32. The yellow line is a constant and the blue line appears to berunning
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.