RevPiModIO cycleloop seems to skip cycles on a regular basis
Posted: 05 Jul 2024, 11:15
Hello,
I have an application where I want to measure an incoming digital signal and check if it matches what I expect. My setup is capable of a cycletime of 5 ms, but my signal can have durations of only 20 ms. I measure in a cycleloop, and allow an error of 10 ms, so I should not detect errors where there are no errors in my signal. BUT I do detect errors, while my oszilloscope tells me there was no error in the signal. A little bit of digging broke it down to this problem:
This pice of code should toggle my signal every 5 ms, but my oszilloscope tells me, that, on a regular basis, the revpi skipps a cycle. With a cycletime of 5 ms, every third high Signal has a length of 10 ms:
This error shifts with changing cycletimes, so a 10ms Signal is sent for example every 5th toggle time, but it barely vanishes. I assume, that this phenomenon occures on reads as well, so my measurement has a possible error of 3 cycle times.
Why does this happen, and is there a way to avoid this?
I have an application where I want to measure an incoming digital signal and check if it matches what I expect. My setup is capable of a cycletime of 5 ms, but my signal can have durations of only 20 ms. I measure in a cycleloop, and allow an error of 10 ms, so I should not detect errors where there are no errors in my signal. BUT I do detect errors, while my oszilloscope tells me there was no error in the signal. A little bit of digging broke it down to this problem:
Code: Select all
rpi = revpimodio2.RevPiModIO(True)
CT = 5
SL = 1.05
actual_time = time.perf_counter()
def main(ct):
global actual_time
rpi.io.DO_3.value = not rpi.io.DO_3.value # type: ignore
new_time = time.perf_counter()
if abs(new_time - actual_time) > CT * SL:
print("Failed")
actual_time = new_time
rpi.cycleloop(main, cycletime=CT)
Why does this happen, and is there a way to avoid this?