• Have you tried what's suggested here? http://www.espruino.com/Waveform
    I'm not sure repeated analog writes will help, but the Waveform class will probably work well.

    For the moment I'd use one of the DAC pins (A4 or A5) as the PWM pins could maybe cause problems with when they update.

    It could be that the JS execution speed is what's throwing the digitalPulse out... If you try creating a new Uint8Array(bits) and then pre-calculating the high and low periods as you say, that will probably work fine too.

    But yes, if you did want to do a manchester encoding function, making jswrap_io_manchesterWrite function is how you'd go about it. The specially formatted comments above each function are parsed during the build process, and then used to automatically make the function callable from JavaScript.

    However I wouldn't go as far as adding something to jshardware. When called from native code, I reckon that jshPinOutputAtTime as used by digitalPulse (if I remember right) will be more than fast enough for what you need.

    Personally I'd give standard JavaScript digitalPulse another try with the precalculated array though. Something like this should push out the pulses very fast once you've calculated them:

    var pulses = new Uint8Array(...);
    ...
    pulses.forEach(function(period,idx) {digitalPulse(pin, idx&1, 1234*period);});
    
About

Avatar for Gordon @Gordon started