RevPi DIO Encoder - forward counts twice as fast as moving backwards.

Topics about the Software of Revolution Pi
Post Reply
daniel_123
Posts: 3
Joined: 30 Jan 2025, 01:11

RevPi DIO Encoder - forward counts twice as fast as moving backwards.

Post by daniel_123 »

I am investigating the use of the RevPi DIO encoder functionality to capture position information from a quadrature encoder. During my investigations I have found that when moving forward the encoder counts at twice the rate as when moving backwards (for the same frequency signal). Is this behaviour expected? Any ideas on how I can change this?

To test encoder functionality I am using a signal generator to simulate encoder wave forms, varying the phase of these signals to simulate moving forwards and backwards.

Code to capture output data
I have also confirmed the same behaviour using piTest.

Code: Select all

import time

# Testing an input output loop, with the output 1 wire connected to input 1
# PiCtory configuration needs to be set appropriately
# with OutputValue_1 and InputValue_1 set to 0-5V
import revpimodio2

# Initialize the RevPi communication
rpi = revpimodio2.RevPiModIO(autorefresh=True)
print(rpi.cycletime)

rpi.io["Counter_3"].reset()
rpi.io["Counter_4"].reset()

rpi.io["Counter_3"].signed = True
rpi.io["Counter_4"].signed = True

time.sleep(1)

start_time = time.time()

previous_count = 0
previous_time = start_time
while True:


    time_now = time.time()
    counter1 = rpi.io["Counter_3"].value
    counter2 = rpi.io["Counter_4"].value

    print("Count3: " + str(counter1) + " Count4: " + str(counter2) +" delta: " + str(counter1 - previous_count) + " time_delta: " + str(time_now-previous_time))

    previous_count = counter1
    previous_time = time_now
    time.sleep(1)  # Sleep for 1 second
Simulated encoder signals moving backwards
encoder backwards waveform.jpg

Code: Select all

Count3: 35534 Count4: 0 delta: -10 time_delta: 1.000213384628296
Count3: 35524 Count4: 0 delta: -10 time_delta: 1.0002143383026123
Count3: 35513 Count4: 0 delta: -11 time_delta: 1.0002446174621582
Count3: 35503 Count4: 0 delta: -10 time_delta: 1.0002529621124268
Count3: 35492 Count4: 0 delta: -11 time_delta: 1.0002257823944092
Count3: 35482 Count4: 0 delta: -10 time_delta: 1.000220537185669
Simulated encoder signals moving forwards
encoder forward waveform.jpg

Code: Select all

Count3: 35045 Count4: 0 delta: 20 time_delta: 1.0002079010009766
Count3: 35065 Count4: 0 delta: 20 time_delta: 1.0002102851867676
Count3: 35085 Count4: 0 delta: 20 time_delta: 1.0002093315124512
Count3: 35105 Count4: 0 delta: 20 time_delta: 1.000211238861084
Count3: 35125 Count4: 0 delta: 20 time_delta: 1.0002107620239258
Count3: 35145 Count4: 0 delta: 20 time_delta: 1.0002062320709229
Note that output 1 on the signal generator is plugged into DIO I4 and output 2 is plugged into I3

Device: RevPi Connect 4

Firmware version
:
pi@RevPi106155:~/projects $ piTest -f
firmware is up to date: 1.5 >= 1.5

Pictory Configuration
pictory config 2.png
User avatar
dirk
KUNBUS
Posts: 2214
Joined: 15 Dec 2016, 13:19

Re: RevPi DIO Encoder - forward counts twice as fast as moving backwards.

Post by dirk »

Hello daniel_123, Foremost, thanks for all the information that I am still collecting, as a first idea so far - can you try to solve the problem by activating debouncing? Here is the spot in the video tutorial:
https://youtu.be/cBxmCPLKnlk?list=PLwce ... hNZu&t=329
daniel_123
Posts: 3
Joined: 30 Jan 2025, 01:11

Re: RevPi DIO Encoder - forward counts twice as fast as moving backwards.

Post by daniel_123 »

Hi Dirk,

Thanks for your reply.

I have tried with all different debouncing settings (no debouce, 25us, 750us and 3ms) the behaviour is still the same.

Let me know if you have any other ideas.

Cheers
Post Reply