[Dprglist] PID-tuned Clock in Python?
David Anderson
davida at smu.edu
Fri Feb 19 19:25:17 PST 2021
Howdy,
Well now that Karim and I are officially ensconced in the realm of
oldfartdom, it occurs to me that this is true of most of the DPRG. Sad
but true. And we would have gotten away with it too, if it hadn't been
for you nosy kids. And get off my lawn (been waiting my whole life to
say that). And on that note:
On 2/19/21 6:49 PM, Murray Altheim via DPRGlist wrote:
> A Pi is not a microcontroller,
The Pi most certainly is a micro controller. What software is run on
the hardware does not change the nature of the device. I'm not sure
where you got this idea, but I've heard you repeat it before. Perhaps
you believe Linux is the difference.
The reason Linux is not run on the STM32 Nucleo family is not because
they are "micro controllers." But rather it is because of a lack of
memory; not because they are basically some different sort of beast.
They are not. In fact, Embedded Linux DOES run on the STM boards ...
see eLinux.org. But running Linux or embedded Linux on the device does
not change it's nature. It is still a micro controller. And so is the
Pi, with or without Linux.
Along the same lines, I think you are using a Rasberry Pi2 or Pi3? Those
devices use a quad core Arm Cortex-A53. That means there are actually
FOUR sets of hardware timers, one associated with each core. The
generic timers so provided have 32 bit and 64 bit modes and are
integrated into the ARM Nested Vectored Interrupt Controller. The ones
in Core0 is the only ones used by the Linux implementation. I believe
they provides a 1 MHz clock. The others are available without
constraints to the user. That's you.
I'm not sure it has occurred to you that the timing signal you are
currently deriving from an external ARM Teensy and then read by an
interrupt on a Pi GPIO pin can instead more simply be generated
internally from one of those hardware timers and interrupts on the Pi
itself. No external devices or GPIO pins required. Yes the Pi ARM
processor does have a nested vectored interrupt controller. It's very cool.
Perhaps this is not possible with python, I don't know. But it's
certainly possible in C/C++, the language in which Linux is written.
(Python itself is written in C, I believe the base is actually called
CPython.) So while it might not be possible for you to access those
timers from python, that is a limit of the chosen language, not the Pi
hardware.
So thinking that "A Pi is not a microcontroller" is not only untrue but
also probably limits one's understanding of what the device is capable.
Now if one were to rephrase that as "Linux is not an RTOS" (but both run
on micro controllers) then you get no argument from me. Like "Photoshop
is not a MySQL Database" (but both are software) or "Cheese is not fried
chicken" (but both are food).
So just a hint, and I'll retire from the field. You currently have an
ARM Teensy generating a timing pulse to try to get the Linux/Python on
the Pi to do something that it is not suited to do, which is precise
real time timing. The somewhat Rube Goldberg-esque "rabbit hole" to
which Karim refers. But you also have the Teensy, which is ideally
suited to do those real time tasks, sitting there basically unused. A
lonely micro controller crying out in the wilderness, "Murray! Murray!
Use me! I can do the real time stuff and report the results to the Pi!
I've got GPIO pins, timers, interrupts! And I'm already here! Turn me
loose!"
So my advice, which I recognize is unsolicited (and perhaps unwelcome):
listen to that cute little fellow.
cheers!
dpa
More information about the DPRGlist
mailing list