You are reading a single comment by @Jofo and its replies. Click here to read the full conversation.
  • Tue 2019.08.20

    '. . . the low-level api to nRF52 is super-cool . . . and it is so quick to work with.'

    Welcome to Espruino Jonas @Jofo and we are glad to see your enthusiasm getting started.

    'in the nRF52832 Product Specification v1.1'

    Would you mind posting a link to that doc please so that we all may follow along. Specifying the section headings/numbers will speed our ability to respond more timely.

    'quadrature encoder '

    Datasheet on encoder specifications here also.

    '(working in software, but too slow)'

    What access speed is expected? How many pulses must read and over what duration? How is this being done in code? A code snippet would assist us in verifying/observing what is currently being attempted. Would 'inlineC' help here? Has coding in this manner been attempted?

    https://www.espruino.com/InlineC
    https://www.espruino.com/Assembler

     

    What functions/methods are being used to read the values? setWatch() or just digitalRead()? Is the read section embedded inside a setInterval() perhaps? Is this where the impression 'software is too slow' is occurring? What duration of timing is being observed in that section?

     

    ' connecting it to a counter '

    Has a specific model and make been selected? What is the doc link for that also?

  • Thanks Robin,

    The specification in question is http://infocenter.nordicsemi.com/pdf/nRF­52832_PS_v1.1.pdf section 36 starting on page 346, also linked from the low-level library page http://www.espruino.com/NRF52LL
    It is actually from there I found out that the chip indeed had hardware support for quadrature decoding. The encoder I use is RLS RM08 https://www.rls.si/en/fileuploader/downl­oad/download/?d=1&file=custom%2Fupload%2­FRM08D01_12.pdf, but I think it would work just as well with more common optical encoders like HEDL5540 etc.

    connecting it to a counter

    Has a specific model and make been selected? What is the doc link for that also?

    I meant counter in the nRF52, like how it is done for counting button clicks in the example of low level library. Maybe not necessary, I am a bit unused to the low-level specification documentation (linked above).

    What access speed is expected? How many pulses must read and over what duration?

    We have 1024 counts per revolution and in our case we use it to detect angle of a manual axis rotation so it is perhaps max 10.000 counts per second. My software solution was just intended as a proof of concept but it works if I rotate slowly (~4s per turn), but skips counts if i turn faster.

    Here is the js code. Thanks for the inlineC suggestion, I will try and see if I can use it too.

    // D25 Green A channel
    // D26 Grey  B channel
    const stable = [0,-1,1,0,1,0,0,-1,-1,0, 0,1, 0,1, -1, 0];
    var encoder_raw = [false, false];
    var counter = 0;
    var prev_state = -1;
    
    var  on = false;
    setInterval(function() {
      on = !on;
      LED1.write(on);
      console.log("Counter " + counter);
    }, 100);
    
    const encoder_callback = function(AB, value)
    {
        encoder_raw[AB]=value;
        var cur_state = encoder_raw[0] << 1 | encoder_raw[1];
        if(prev_state < 0) prev_state = cur_state;
        counter += stable[prev_state << 2 | cur_state];
        prev_state=cur_state;
    };
    
    setWatch(function(e) {encoder_callback(0,true); }, D25, { repeat: true, edge: 'rising' });
    setWatch(function(e) {encoder_callback(0,false);}, D25, { repeat: true, edge: 'falling' });
    setWatch(function(e) {encoder_callback(1,true); }, D26, { repeat: true, edge: 'rising' });
    setWatch(function(e) {encoder_callback(1,false);}, D26, { repeat: true, edge: 'falling' });
    
About

Avatar for Jofo @Jofo started