NRF52LL Quadrature decoder #3076
Replies: 6 comments
-
|
Posted at 2019-08-20 by Robin 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?
Has a specific model and make been selected? What is the doc link for that also? |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-08-20 by Jofo 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
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).
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. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-08-20 by Jofo To follow up, here is the inlineC version, which actually is fast enough for my purpose! I am still interested in hardware support, maybe more power-efficient or leaving cpu for other tasks, but this could be good enough anyway. Super-cool that we can combine js and c this way, so thanks for that. |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-08-20 by Robin Tue 2019.08.20 Thank you @jofo for the additional detail, we now may follow along more easily. Surprised, and glad you were able to get the inline 'C' working quickly. My first attempts took me longer. Nothing appears out of the ordinary for the Javascript snippet. Proper use of setWatch() and not embedded with the setInterval() function. This is most likely understood, so forgive me if this is too obvious. I use a technique to allow a function call in the WebIDE Left-Hand console window to stop processing as at times Ctrl+C isn't always as responsive when updating at 100msec. L9 could be modified to:
Your post reminded me of another with an encoder issue, several days ago, and a link there shows a solution Gordon proposed that should be fast enough with Javascript and setWatch() data: options attribute. See the link 'Proper technique needed to nest a setWatch()' in #27 there
I'll continue to read up from your links, in the mean time I'll defer to others. . . . |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-08-20 by @allObjects Nice inline-C solution.... and it is portable between Espruino bards. Doing it with counters may not be much faster but much more complicated and keeps the processor still busy. Using the built-in QDEC spares the processor - depending how you setup the interrupts and interface with JS layer. To use the QDEC in poling mode - almost what you do in current solution - you can achieve with poking and and peeking. Looking at the power use, it is for sure much much lower than get thru the interrupt FIFO the JavaScript execution space going. It also does not / much much less compete with the interrupts other IO generate. Interesting to the QDEC implementation is that it already does great error detection and counting and has built in 'debounce' filtering (which btw uses timers when using debounce in |
Beta Was this translation helpful? Give feedback.
-
|
Posted at 2019-08-27 by @gfwilliams 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 Totally untested but: 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:
Then when you want to read:
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_memoryMap 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. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-08-20 by Jofo
Hello,
First I want to say that the espruino and the low-level api to nRF52 is super-cool. I could try some of the examples you have provided, and it is so quick to work with.
I would like to request or figure out how to use the QDEC - Quadrature decoder feature that is described in the nRF52832 Product Specification v1.1. I have a quadrature encoder with A and B pins connected to the MDBT42Q breakout board already (working in software, but too slow) and if I could use the hardware feature connecting it to a counter it would be awesome. Any suggestion how it could be done?
Best regards
Jonas
Beta Was this translation helpful? Give feedback.
All reactions