You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Thanks for posting up the C code - hopefully that'll really help some others as well.

    Robin's got a good point with the 'setWatch' link - by using the data pin argument you could use a single setWatch with JS. It'll only have half the accuracy but it should be capable of going much faster than the plain JS version (not your C version).

    Totally untested but:

    count=0;
    setWatch(function(e) {
      count+=(e.state^e.data)-0.5;
    }, PINA, {data:PINB,repeat:true});
    

    As far as I can tell the QDEC hardware seems pretty easy to use - I'd just use the http://www.espruino.com/modules/NRF52LL.­js file as a basis and fill in the registers from the datasheet.

    As far as I can tell for the simplest setup you need to:

    • ENABLE=1
    • set PSEL.A/B to the two pin numbers
    • TASKS_START=1

    Then when you want to read:

    • TASKS_RDCLRACC=1
    • Read ACCREAD

    You could also be fancy and use a new feature I added in 2v04 to access the registers as if they were variables: http://www.espruino.com/Reference#l_E_me­moryMap

    The gotcha here is you'll have to poll the reader (unless you're willing to waste 2 external pins so you can setWatch one and then use NRF52LL to toggle the pin state when an 'event' is generated from the QDEC).

    Also your current solution looks like it's actually the most power efficient. I could be wrong here but it looks like QDEC doesn't use edge detection - it repeatedly polls to check the values. That means that it'll require the high speed oscillator to be left on when it runs, which will cause at least 1mA (IIRC) power drain. Your method will draw basically nothing when idle.

About

Avatar for Gordon @Gordon started