-
Thanks Robin,
The specification in question is http://infocenter.nordicsemi.com/pdf/nRF52832_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/download/download/?d=1&file=custom%2Fupload%2FRM08D01_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' });
Tue 2019.08.20
Welcome to Espruino Jonas @Jofo and we are glad to see your enthusiasm getting started.
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.
Datasheet on encoder specifications here also.
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?
What functions/methods are being used to read the values?
setWatch()
or justdigitalRead()
? Is the read section embedded inside asetInterval()
perhaps? Is this where the impression 'software is too slow' is occurring? What duration of timing is being observed in that section?Has a specific model and make been selected? What is the doc link for that also?