Uncaught InternalError: Timeout on ADC

Posted on
  • I am receiving this error and don't know why or how to fix this:

    Uncaught InternalError: Timeout on ADC at line 6 col 30 var vOut =
    E.getAnalogVRef() * E.sum(view)/(view.length*65...

    Code:

    var w = new Waveform(128/* your buffer size */,{doubleBuffer:true, bits:16});
    
    w.on("buffer", function(myarr) {
      myarr.sort();
      // cut off first and last 2 elements
      var view = new Uint16Array(myarr.buffer, 2/*sizeof(uint16)*/*2, n-4);
    
      var vOut = E.getAnalogVRef() * E.sum(view)/(view.length*65536); // if you attached VOUT to Ao
      var vZero = 0.4;
      var tCoeff = 19.5 / 1000;
      var tempinc = (vOut - vZero) / tCoeff;
      var tempinf = tempinc * (9 / 5) + 32;
    
      console.log("Temp in C: " + tempinc);
      console.log("Temp in F: " + tempinf);
      //console.log(E.sum(view)/(view.length*6­5536));
    });
    
    w.startInput(A0,2000 /* Samples per second */,{repeat:true});
    

    Console output:

    Uncaught InternalError: Timeout on ADC at line 6 col 30 var vOut =
    E.getAnalogVRef() * E.sum(view)/(view.length*65...

                              ^ in function called from system Temp in C: 23.71055210571 Temp in F: 74.67899379028 Temp in C: 23.79099063384
    

    Temp in F: 74.82378314091 Temp in C: 23.64845636164 Temp in F:
    74.56722145096 Temp in C: 23.66374898568 Temp in F: 74.59474817422 Temp in C: 23.74768151969 Temp in F: 74.74582673545 Temp in C:
    23.74994383879 Temp in F: 74.74989890983 Temp in C: 23.80151123724 Temp in F: 74.84272022703 Temp in C: 23.82175939511 Temp in F:
    74.87916691119 Temp in C: 23.81015918605 Temp in F: 74.85828653489 Temp in C: 23.89451469519 Temp in F: 75.01012645134 Temp in C:
    24.03446761515 Temp in F: 75.26204170727 Temp in C: 23.78549651722 Temp in F: 74.81389373101 Temp in C: 23.70157938435 Temp in F:
    74.66284289184 Temp in C: 23.76887558668 Temp in F: 74.78397605602 Temp in C: 23.74900409502 Temp in F: 74.74820737105 Temp in C:
    23.81278517307 Temp in F: 74.86301331153 Temp in C: 23.78265742766 Temp in F: 74.80878336979 Temp in C: 23.82784904577 Temp in F:
    74.89012828240 Uncaught InternalError: Timeout on ADC at line 6 col 30 var vOut = E.getAnalogVRef() * E.sum(view)/(view.length*65...

                              ^ in function called from system
    
  • Ahh, that's frustrating. It's because you're using an analog input while the Waveform is also trying to use it. I'll file a bug for that and will try and fix it.

    Right now your best solution would be to just forget about the analogVRef and hard-code the voltage:

      var vOut = 3.3 * E.sum(view)/(view.length*65536); // if you attached VOUT to Ao
    

    Either that or work it out beforehand:

    var vref = E.getAnalogVRef();
    w.on("buffer", function(myarr) {
     // ...
      var vOut = vref * E.sum(view)/(view.length*65536); // if you attached VOUT to Ao
    

    Or... you could not use the double-buffer but instead just use a single buffer that stops reading when it is full:

    var w = new Waveform(128/* your buffer size */,{doubleBuffer:false, bits:16});
    setInterval(function() {
      var myarr = w.buffer;
      myarr.sort();
      // cut off first and last 2 elements
      var view = new Uint16Array(myarr.buffer, 2/*sizeof(uint16)*/*2, n-4);
      var vOut = E.getAnalogVRef() * E.sum(view)/(view.length*65536); // if you attached VOUT to Ao
      var vZero = 0.4;
      var tCoeff = 19.5 / 1000;
      var tempinc = (vOut - vZero) / tCoeff;
      var tempinf = tempinc * (9 / 5) + 32;
      console.log("Temp in C: " + tempinc);
      console.log("Temp in F: " + tempinf);
      //console.log(E.sum(view)/(view.length*6­5536));
      // start it again
      w.startInput(A0,2000 /* Samples per second */);
    }, 1000*150/2000 /* so slightly over the 128/2000 sec required for the waveform*/);
    
  • ...where is the n in line 6 come from / defined? - I assumed this is the buffer size... (see example in post).

  • @Gordon, are you saying there is a lower limit for the sampling/output rate in WafeForm?

  • Yes, looks like n needs to change, but that's not the issue here.

    It's not that waveform has a lower limit, it's that it is using the adc in the background. If you use it and then access the adc with analogRead, occasionally they may try and use it at the same time, and you'll have problems

  • #ADC #conflict

    ...using THE adc in the background...

    Espruino has 3 ADCs... does the user have control over which ADC is mapped to which port?... or from your wording: is only one ADC available to Javascript?

  • I think there are only 2 ADCs? But yes, only one ADC is available. While switching to ADC2 for Waveform would be a simple fix, unfortunately the F401 in the Pico only has 1 ADC, so I need to come up with a fix that works for both.

  • @Gordon I was playing around with waveform and I see two major improvements: the IDE is still responsive and the code seems to run quicker than my original temp code. Thank you for the help and the recommendation to use waveform :)

  • No problem! Glad it helped :)

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

Uncaught InternalError: Timeout on ADC

Posted by Avatar for d0773d @d0773d

Actions