DigitalPulse() on 1V66

Posted on
  • Am I doing something wrong here.

    
    //test_puls01
    
    var thePin = LED1;
    var theDummy = LED2;
    
    /*
    // Both turn on at the same time, then LED2 off, and then LED1 off.
      digitalPulse(thePin,1,800);
      digitalPulse(theDummy,1,400);
    // This is normal.
    */
    
    // First turn LED1 on, then LED2 on, and off almost simultaneously.
      digitalPulse(thePin,1,800);
      digitalPulse(thePin,0,0);
      digitalPulse(theDummy,1,400);
    // Something wrong here
    
    
    /* _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v66 Copyright 2014 G.Williams
    >echo(0);
    =undefined
    Uncaught [object Object]
     at line 1 col 26
      digitalPulse(thePin,0,0);
                              ^
    > 
    */
    
    
  • Isn't it supposed to be:

    digitalPulse(thePin,1,0);

    to wait for the current pulse to finish?
    That's what the reference shows, at least.

    Not sure if that's the issue here - if you caught the exception and printed it out, it might give you more information.

  • It does not matter whether it is 0.0 or 1.0, it gives the same error as seen in the bottom of the list.

    Uncaught [object Object]
    at line 1 col 26
    digitalPulse(thePin,0,0);

  • Strangely, after testing other pieces of software, I tried again and now it works without error.

  • Thanks. I've managed to reproduce this so I'll try and fix it...

  • Ok, looks like the error should have been reported as Timeout on Utility Timer. There were some bugs that meant that InternalError wasn't converted to a string properly.

    It's because Espruino will only block for ~0.5 seconds waiting for the timer before it gives up. You'd be better off writing the code as:

     digitalPulse(thePin,1,800);
     setTimeout(function() {
       digitalPulse(thePin,0,0);
       digitalPulse(theDummy,1,400);
     }, 700);
    

    That way at least Espruino can be doing other stuff for 700 of the 800 ms.

    There's also the slightly hidden 'writeAtTime' method, which allows you to queue stuff up without blocking at all:

    var t = getTime();
    LED1.write(0); // set as output
    LED1.writeAtTime(1,t+1);
    LED1.writeAtTime(0,t+2);
    LED1.writeAtTime(1,t+3);
    LED1.writeAtTime(0,t+4);
    

    Thanks for pointing it out - while debugging I found out that 1v67 had a huge regression that totally broke digitalPulse, so it's good that it got found before I made a release!

  • That explains, why the fault disappeared, that was because I have set my timing to <= 300.
    Thank you for looking into it.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

DigitalPulse() on 1V66

Posted by Avatar for Frida @Frida

Actions