You are reading a single comment by @user135646 and its replies. Click here to read the full conversation.
  • Hi All,
    Working on something that needs to produce accurate-ish (+/-20%) pulses down to 20us every 10ms for 1s. I'm currently using a combination of setInterval() and digitalPulse() (see snippet below if interested).

    With a bit of dialling-in, the 1s duration is reliable enough, setInterval() is working great at 100Hz, and digitalPulse() gives good results at 200us and passable ones at around 140us.

    digitalPulse can do 32us, but there's about +40/-0 us of variation in it so it's not ideal. For stuff around 100us things could be fudged so that the +40us sits as +/-20% around 100us, but it doesn't work once you get faster than that.

    So the question is, what timers are free to use that don't interfere with Espruino? What timers (if any) does digitalPulse() use? Was thinking of using a one-shot timer triggered over and over by setInterval().

    // Timeouts of OFFSET_MS used to account for speed of js execution. Obtain OFFSET_MS empirically.
    // Timeout to start pulses.
    setTimeout( () =>   { tmp1 = setInterval( () => { 
                    digitalPulse( PULSE_PIN, true, pulseDuration_ms );
                }, CNST_PERIOD_MS )
            },  OFFSET_MS
        );
    // Timeout to stop pulses after some time.
    setTimeout( function(){ PULSE_PIN.reset(); clearInterval(tmp1); }, Duration1_ms+OFFSET_MS);
    
About

Avatar for user135646 @user135646 started