Encoder library suggestion

drgry

New member
Hello,

I am trying to use your excellent encoder library in my automation project on Arduino.

Project will use encoder library in interrupt mode, servo library for controlling two brushless motors and RTOS48 (realtime OS for Arduino).

I find encoder library very useful and I have a question/suggestion:

Encoder position is maintained in one 32bit variable which is maintained inside ISR (? a think). This involves some processing time. Also when reading this variable interrupts are (if I understand correctly) disabled for short period of time.
I do not know exact effect of this to timer interrupt used both in servo and RTOS48 libraries, so any help on this would be appreciated:).

My suggestion on library would be:

Since I come with industrial automation background i do understand use of 32bit variable for encoder position, all industrial motor drives use this. But use of encoder position in user program is usually like this:

1. read current position form drive (equivalent of Encoder::read() function).
2. since this position can overflow and most control algorithms require floating point arithmetic and usually we need delta position (speed) do following:
2.1 find delta position by comparing current position and previous scan position.
2.2 If absolute value for delta is greater than some predefined maximum value use delta from previous scan (overflow detection)
3. maintain position in float variable for further calculation by accumulating deltas.

Basically my proposition is following: In ISR maintain delta position, by reading encoder inputs and processing them, in smaller size variable (8 or 16 bit). If delta is 8 bit, Arduino native, it would give +/- 127 pulses buffer between two consecutive reads. In my experience 127 pulses buffer is adequate for most control applications realised on Arduino (assuming control cycle of 10 to 50 ms) so we do not have any position error.
Read function would read 8 bit encoder delta and then reset it to 0. User program would be responsible for reading delta position fast enough so delta does not overflow.

In this way ISR would be faster and read function may or may not require disabling interrupts.

I have no idea on how to implement this in the manner encoder library is written and do not know if this would speed encoder evaluation significantly so I am asking for opinions and help.

Best regards.
 
Back
Top