Arduino Forum

Products => Arduino Due => Topic started by: 01Tester01 on Apr 09, 2019, 10:21 am

Title: Reading two quadrature encoders using Encoder.h library
Post by: 01Tester01 on Apr 09, 2019, 10:21 am
Hi!

I'm running into a problem right now with a project I'm working on.

I have to control the position of 2 DC motors and therefore have attached an encoder (HEDM-5500) with 1000 counts per revolution to each one of them.

I'm running my motor control loop at 1kHz (Timer interrupt), where I generate my position setpoint, handle the PID calculation and measure some data with the ADC.

If I'm only ever reading one of the encoders using the Encoder (https://github.com/PaulStoffregen/Encoder) library from Paul Stoffregen everything works fine, but If I start to control both motors and therefore read both encoder values one of the starts to temporarily not count steps.

I think I'm running into a problem with the interrupts not being called, but I don't know.

My PID calculation stuff is definitely fast enough, it takes at max. 750 µs out of the 1000 µs available, but even if I lower the control loop frequency and therefore give the system more idle time nothing changes with the encoder behaviour.

I hope someone can help me out with my problem.
Title: Re: Reading two quadrature encoders using Encoder.h library
Post by: ard_newbie on Apr 09, 2019, 11:43 am
You could consider using the 2 hardware quadrature decoders of the DUE. They are capable of handling a very high number of encoder edges per second.

The Arduino DUE has two hardware quadrature decoder QDEC0 and QDEC1

QDEC0:
Timer Counter 0 channel 0 / TIOA and TIOB of channel 0
PHA  TIOA0 = pin 2
PHB  TIOB0 = pin 13
Timer Counter 0 channel 1 / TIOB of channel 1
INDEX  TIOB1 = pin A6

QDEC1:
Timer Counter 2 channel 0 / TIOA and TIOB of channel 0
PHA  TIOA6 = pin 5
PHB  TIOB6 = pin 4
Timer Counter 2 channel 1 / TIOB of channel 1
INDEX  TIOB7 = pin 10

For example sketches to record position or speed (from reply 84):
https://forum.arduino.cc/index.php?topic=140205.75 (https://forum.arduino.cc/index.php?topic=140205.75)

Title: Re: Reading two quadrature encoders using Encoder.h library
Post by: 01Tester01 on Apr 09, 2019, 03:59 pm
I have tried the hardware quadrature decoder, but was only successful with the one on TC0, additionally I was not yet able to properly reset the counter whenever I want to.

Have you tried "resetting" the output register before?
Title: Re: Reading two quadrature encoders using Encoder.h library
Post by: ard_newbie on Apr 09, 2019, 06:18 pm
I have tried the hardware quadrature decoder, but was only successful with the one on TC0
Why ?