The perf_counter() function returns the float value of time in seconds. It uses a performance counter, i.e. a clock with the highest available resolution to measure a short duration. It includes time elapsed during sleep and is system-wide. The reference point of the returned value is undefined, so you must measure at the start and then compare to the end of the period you want to measure and compare the values

Checking an IO operation completed within a time in uS

import time

    start_counter = time.perf_counter()
    #Do something here you want to ensure occurs fast enough
    GPIO.output(self._pd_sck, True)
    GPIO.output(self._pd_sck, False)
    end_counter = time.perf_counter()
    if end_counter - start_counter >= 0.00006:
            print('Not enough fast while reading data')
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *