in my programm i have a endless while loop which needs to run in a fixed frequency to give da constant datarate. My idea (which I copied from github) was to get a timestamp outside the loop and inside the loop, and use the delta as my frequency.
import time
time_after_loop = time.process_time() # initalisation
frequency = 0.05
while True:
time_before_loop = time.process_time()
if time_before_loop - time_after_loop >= frequency:
real_frequency = time_before_loop - time_after_loop
print(real_frequency)
# main programm
time_after_loop = time.process_time()
I use windows 10 and python 3.8 and the print values show some interessting behavierous
frequency = 0.5 --> real_frequency = 0.5
frequency = 0.1 --> real_frequency = 0.109375
frequency = 0.05 --> real_frequency = 0.0625
frequency = 0.001 --> real_frequency = 0.015625 --> max frequency
It looks like a systematic error, not a problem in the code? Does someone know what happend here and how to fix it?