Timers with us



  • Hello,

    It seems there is a problem using timers with intervals under 1ms. Taking an example of a pin toggle using interrupts every 0.5ms here is the output based on a logic analyzer:

    0_1531319041417_probe.PNG

    code used:

    from machine import Pin
    from machine import Timer
    
    test_pin = Pin('P11', mode=Pin.OUT)
    test_pin(True)
    
    class Clock:
    
        def __init__(self):
            self.loops = 0
            self.__alarm = Timer.Alarm(self._seconds_handler, us=500, periodic=True)
    
        def _seconds_handler(self, alarm):
            self.loops += 1
            test_pin.toggle()
            
            if self.loops == 20:
                alarm.cancel()
    
    clock = Clock()
    

    this happened also with

    self.__alarm = Timer.Alarm(self._seconds_handler, s=0.0005, periodic=True)
    

    PWM seems to working fine for the same Pin / Frequency. If a change the period to 1ms and above everything is working fine.


 

Pycom on Twitter