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
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
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
Device: RevPi Connect 4
Firmware version:
pi@RevPi106155:~/projects $ piTest -f
firmware is up to date: 1.5 >= 1.5
Pictory Configuration