[Dprglist] PID-tuned Clock in Python?

Murray Altheim murray18 at altheim.com
Thu Feb 18 19:36:15 PST 2021


Okay, here's my results. This is using the Adafruit ItsyBitsy M4 Express
I already had mounted on my robot as an external clock, with its ATSAMD51
32-bit Cortex M4 core running at 120 MHz:

    https://www.adafruit.com/product/3800

I assume any Arduino compatible would provide similar results. I wired up
power, ground, and one of the M4's pins to one of the Pi's GPIO pins.
They're both 3.3 volt devices. I used the Arduino IDE to load a simple
microsecond timer (set to toggle the output pin at 50ms) onto the M4.

I ran the test code on the Pi and executed "sudo apt update". The worst
case result was an error of 0.8ms but that only happened once. The vast
majority of 50ms pulses came in with errors of around 0-07-0.09ms, which
is entirely within the "reasonable" range for my purposes. I could try
stress tests of the Pi but obviously that wouldn't effect the M4 as the
clock source. This might be considered a waste of the M4 (which could
itself run a robot) but it was already mounted on my robot, unused.

Here's the test code:

    https://github.com/ifurusato/ros/blob/master/ext_clock.py
    https://github.com/ifurusato/ros/blob/master/microsecond_clock.ino

Now I don't claim this is very sophisticated, but it is an improvement
over what I had. No PID this time, just the M4 as an external clock.

Now all I need to do to replace my existing Clock is have the new one
generate TICK messages onto the MessageBus and I have a suitable,
sub-1ms-accurate timer that is unaffected by system load on the Pi.

Cheers,

Murray

...........................................................................
Murray Altheim <murray18 at altheim dot com>                       = =  ===
http://www.altheim.com/murray/                                     ===  ===
                                                                    = =  ===
     In the evening
     The rice leaves in the garden
     Rustle in the autumn wind
     That blows through my reed hut.
            -- Minamoto no Tsunenobu



More information about the DPRGlist mailing list