[Dprglist] PID-tuned Clock in Python?

Murray Altheim murray18 at altheim.com
Fri Feb 19 16:49:14 PST 2021


On 20/02/21 8:43 am, John Swindle via DPRGlist wrote:
> Folks:
> 
> Looks like I stuck a stick in an ant hill.

Hi John,

All in good fun... I take their very generous guidance seriously,
and it's very much appreciated.

[...]
> Regarding a sync, Murray added an external interrupt to time 
> the loop (not to timestamp the sensors together as I am doing).
> For the loop timing, why not use the hardware timers built into
> the local interrupt controllers instead of an external source?
> Maybe I'm wrong here (because I haven't tried it, and I don't
> need to try it), but all of the local interrupt controllers  
> that I've read about have hardware timers that can be programmed
> to give repeating interrupts. I see that this is available on
> Android. I read that the Android average timing will be the 
> programmed timing unless the ISR takes more time than the 
> interval between interrupts. One interrupt can be posted, but a
> second interrupt at the same level is discarded if the first has
> not been cleared. Makes sense.

I'm not sure what you mean by an interrupt controller in the context
of what I'm doing (or maybe you're speaking more generally). I've got
a Raspberry Pi-based robot that doesn't have any other devices onboard
except say, my motor controller (which is I2C-based) and some sensors.
I added the Itsy Bitsy M4 (Cortext M4) as the second CPU/device, which
is providing me that external clock.

But I don't have any other devices on the robot, and as we know the
Raspberry Pi doesn't have "true" interrupt support, only the RPi.GPIO
and pigpio libraries that permit listening on a GPIO pin, with a
callback. So it's like an interrupt, but not. It polls the pin.

I was trying to find the polling rate (which I think even I provided
in a message a few weeks ago, something like 5-50µs) but couldn't
locate the source. I'm not sure how this compares with the ST
microcontroller boards that David uses for his robots, but even while
a Raspberry Pi running Linux is a time-sharing OS, it is still a
pretty quick CPU (generally 1.2-1.4GHz, compared with ~16-240MHz on
microcontrollers) so the clock speed is certainly sufficient.

Talking about the performance of two main libraries for dealing with
GPIO pins on the Pi I found this:

   "Both libraries perform well for frequencies of up to 5 KHz with
    accuracy above 99%. The accuracy of the Rpi.GPIO library
    deteriorates over 5 KHz and at 50 KHz it is incapable of performing
    this task.

    The PIGPIO library performs comparably better, with its accuracy
    being above 99% for frequencies up to 20 KHz. Above that frequency,
    its performance gradually deteriorates and at 110 KHz it cannot
    read correctly any phrase at all."

    https://raspberrypi.stackexchange.com/a/120614

So there are hardware limitations but really, as David and Karim have
rightly noted, this is more of a hardware architecture question. A
Pi is not a microcontroller, and it has its own idiosyncracies. That
doesn't make it unsuitable for robotics (clearly, as it is very widely
used) but it has limitations, just as do microcontrollers. They're just
different sorts of limitations. It's all trying to figure out what one's
requirements, predilections, goals, etc. are, and finding the right
balance.

A Raspberry Pi-compatible SBC with real interrupts is something I've
been looking for for about a year now. I've bought a few oddball boards
trying to find something that hits the sweet spot, but nothing yet;
there always seems to be some hitch. Recently Kipton mentioned that cool
STM32MP157A-DK1 hybrid microcomputer/microcontroller board which might
just work:

    https://www.mouser.com/ProductDetail/STMicroelectronics/STM32MP157A-DK1/?qs=9r4v7xj2LnkgRwGGD4%252BIjQ%3D%3D

I'm still thinking about that as it's NZ$106, something that shouldn't
end up gathering dust on my shelf if it doesn't work out... I like having
cool things lying around my playroom as much as the next boy, but it can
get a bit expensive...

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