analogRead() and PuckJS

Posted on
  • Is analogRead(pin) the quickest way and how accurate is this?

    Does switching of NRF improve reads?

  • I'm not 100% sure I understand the question?

    For single reads, analogRead is easiest. For multiple reads you could use Waveform and I think that should be slightly faster.

    You can also configure the nRF52 hardware to just take readings automatically which is probably the fastest - see https://www.espruino.com/NRF52LL#read-a-­buffer-of-data-from-the-adc

  • Does switching of NRF improve reads?

    Should NRF.sleep() be called if accurate analogRead() are required?

    You can also configure the nRF52 hardware to just take readings automatically which is probably the fastest

    Ok, have to look into that module

  • Should NRF.sleep() be called if accurate analogRead() are required?

    It may help - I haven't really done any tests.

    But the NRF52LL module will give you a lot of options - for instance taking slower readings for higher quality - that Espruino doesn't usually expose

  • first test with the NRF52LL module

    var ll = require("NRF52LL");
    
    var saadc = ll.saadc({
      channels : [ { // channel 0
        pin:D4,
        gain:1/4,
        tacq:40,
        refvdd:true,
      } ]
    });
    
    setInterval(()=>{print(saadc.sample());}­,1E3);
    
    /* output
    [ 4 ]
    [ 12 ]
    [ 65528 ]
    [ 8 ]
    [ 4 ]
    [ 65524 ]
    [ 40 ]
    [ 0 ]
    [ 12 ]
    [ 12 ]
    [ 20 ]
    [ 16 ]
    [ 8 ]
    */
    

    Is the result a 16 bit signed integer and presenting a -32767 to +32767 digital value ?

  • Is the result a 16 bit signed integer and presenting a -32767 to +32767 digital value ?

    Yes... although the value you get is 14 bits usually (depending on how you configure it).

    It's a bit odd that you get negative values, but it does happen when you're measuring a value near 0v (it sometimes happens with analogRead too)

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

analogRead() and PuckJS

Posted by Avatar for MaBe @MaBe

Actions