You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • Things that are already time critical become even more so when handled interpretatively, as Espruino - to be precise: the JavaScript part of Espruino - is doing, even though events are queued to not slow down the catching and registering of them. In addition to that, for replay the pauses between the pulses matter as well and have to be considered (I do not know what the example does).

    My stab at this would be to just record the times in the loop and do all math afterwards... To prep the values for replay, you may even adjust them for the execution time used by Espruino.

    I have no feeling for the actual figures / numbers, I'm just thinking through what happens... and all needs time, and since you expect actually an over-all accuracy of 4 digits, 1 millisecond matters...

    pinMode(D1,"input_pullup");
    var rTs = []; // raw times
    var times = []; // calculated from raw times
    var recordingWatch;
    
    function startRecording() {
      rTs = []; 
      recordingWatch = setWatch(function(e) {
        rTs.push(e);
      }, D1, { repeat: true, edge: "both", debounce: 0 });
    }
    
    function stopRecording() {
      clearWatch(recordingWatch);
      currentWatch = null;
    }
    
    // times[] array will include calculates the pulse on and off times
    // even-indexed values are on-times,  odd-indexed ones are off-times
    function calculateTimes() {
      var tCurrent, tLast; // t-current and t-Last
      times = [];
      rTs.forEach(function(e, idx){
          if (idx === 1) {
             tLast = e.time;
          } else {
             times.push((tCurrent = e.time) - tLast);
             tLast = tCurrent;
          }
        });
      }
    

    Sequence of events are:

    1. upload code
    2. connect wires to remote
    3. console command startRecording()
    4. perform command on remote
    5. console command stopRecording()
    6. console command calculateTimes()
    7. console.command console.log(times) to show the calculated times

    Do you see any difference?

About

Avatar for allObjects @allObjects started