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?