Encoder read-out inconsistency, Quadrature::OFF / ON

Hi,
I try to develop a DIY BLDC-motor for driving at low speed, typically 3 rad/s. But I need constant speed with high accuracy. The motor is 20 magnets / 10 pole pairs, 15 coils axial flux design (7.4Ohm/phase). I tried to run it in open loop, it turns but not smooth at present. So I wanted to try it with the encoder…
The encoder is a BEI Kx21 optical encoder with 1024 ppr square wave TTL output. I used it some years ago without any trouble reading directly with Arduino. However, the read-out with simple foc (starting from your example https://docs.simplefoc.com/encoder point 4, standalone sensor) is strange, it appears that quadrature is not working. I get correct angle values with
Encoder encoder = Encoder(2, 3, 1024, 21), independent on encoder.quadrature = Quadrature::OFF or ON.
I checked the encore with an oscilloscope, and A and B channels look ok, 1024 ppr is correct.
Any ideas ? THX !!!

Hey @mbtt,

What does it mean exactly that it is not working, can you be a bit more specific?
For start I’d use only A and B channel until you’re sure that everything works well.

Can you also share your exact code?

Hi! Thanks for the quick reply. According to https://docs.simplefoc.com/encoder “For quadrature mode you will have CPR = 4xPPR” I should put
Encoder encoder = Encoder(2, 3, 4096, 21), with ppr=1024. But the angle output is the same for encoder.quadrature = Quadrature::OFF and
encoder.quadrature = Quadrature::ON, and correct if I use ppr=cpr=1024. Code is really the same as your example, only that I added index pin 21 (Arduino Mega), and converted the angle to degree, which is just more easy for me :slight_smile:

So the code is written in a way to return the same value if you put quadrature on or off. :slight_smile:
The library will automatically calculate the cpr inside so you won’t see the change in angle value.
In the constructor you always put the ppr so 1024.

What will change is the precision and the number if interrupts per rotation. You should see that with quadrature mode you have much more precise measurements of angle. :smiley:

ok, Thanks ! But then the encoder doc above should be amended:
It notes: ```
// Encoder(int encA, int encB , int cpr, int index)
// - encA, encB - encoder A and B pins
// - ppr - impulses per rotation (cpr=ppr4)*
// - index pin - (optional input)
Encoder encoder = Encoder(2, 3, 8192, A0);

Thanks ! bon we !

Ah, it’s possible but if I’m not mistaken:

  • PPR is number (im)pulses per revolution. This is a hardware number which tells you how many impulses you have physically ok your encoder disk ( and this is the one the library takes as input)
  • CPR is the number of counts per revolution which is the number which depends how you count the impulses. If you count them directly then CPR=PPR if you count them using quadratic mode then CPR=4PPR.

So in my opinion the docs are ok, you don’t agree with this? :smiley:

EDIT: I see what you mean, you’re completely right. I’ll make sure to update the docs. Thanks! :smiley: