Raspberry Pi GPIO: Hardware Timing (e.g. Interrupts) - raspberry-pi3

I've been trying to find any way to do hardware timing control on the Raspberry Pi but have been unable to find anything.
I need to be able to generate stable timing over the GPIO pins on the RasPi (e.g. to communicate with an FPGA at high-bandwidths) and need upwards of a 10-100MHz clock on the GPIO pins.
Everything I've seen so far uses delays to achieve timing, which is a really bad way of doing timing. For one, you don't get timing guarantees and get clock jitter; on top of this, I can't get a 10-100 MHz clock uwith usleep.
How do I get an interrupt or some other hardware-controlled timing for GPIO?

Related

Measure PWM Duty Cycle on RP2040 using micropython

I'm trying to use a Raspberry Pi Pico to measure an incoming PWM signal duty cycle and use the value to drive an I2C digital potentiometer. I'd like to use micropython as I know some of this already. The I2C output I have working with no problems. However I can't find where to start with the PWM measurement.
The RP2040 datasheet suggests it is possible to use the PWM slices to measure duty cycle, but the micropython PWM commands don't seem to utilise this (https://docs.micropython.org/en/latest/library/machine.PWM.html)
I can't see how to access the PWM slices directly in micropython
The "rp2" micropython — functionality specific to the RP2040 does not reference PWM as far as I can see. (https://docs.micropython.org/en/latest/library/rp2.html)
There are ways to measure PWM by using some coding but I would like to do it using the hardware as this frees up the processor for other tasks and it should also be more accurate I believe.
Perhaps I am just missing some documentation - any pointers much appreciated.
Chris
EDIT: I have found a useful module which covers a large part of this query:
https://github.com/phoreglad/pico-MP-modules/tree/main/PWMCounter

How to do an edge counter/clock detector for a Raspberry PI(as linux kernel driver)?

Hej
I connected to one of my raspberry pi pins to a voltage controlled oscillator. A change of one of the oscillator capacity changes the output frequency. My question is how to realize the frequency detection?
There some constraints:
1st.) I like to keep the cpu consumption low.
2nd.) I like to have a file based interface, which my user space app can query for the actual frequency.
I was checking the Linux GPIO driver. But I see no possibility to configure a pin as an edge counter.
The raspberry pi soc data sheet describes at page 86 (chapter "6 General Purpose I/O (GPIO)")registers to configure a gpio to detect edges.
Any ideas how to configure these registers in a kernel character device driver?

[Common Clock Framework]: How to set rate of a muxed clock if its parent clock unable to set?

Studying Common Clock Framework and have a doubt related to muxed clocks.
If we want to set particular rate of a muxed clock and the current parent of the clock is unable to set the desirable rate (parent have lesser rate).
Then, Is there any function or mechanism who switches the parent of the clock (from its parent list) automatically and sets the desire rate?
One possible solution, we can call the set_parent() manually and then call set_rate(), which can set desire rate. But what if we just call set_rate() and it swithces parent of the clock automatically and sets desirable rate.
Some clocks may up-scale a timer using a PLL. So having a parent that has a lower clocking doesn't mean that automatically trying to increase the parent clock is the best solution. The Common clock framework (CCF) is meant to allow multiple drivers/sub-systems access to a shared resource. The CCF doesn't try to be intelligent as the way different clock trees behave is difficult to know generically.
One possible solution, we can call the set_parent() manually and then call set_rate(), which can set desire rate.
I think you mean to call get_parent() and then use set_rate? Some of the time, it is not easy to call set_parent() as it maybe fixed. You need to read your SOC documentation. In some cases, there are multiple input clocks available. Ie, the real clock hierarchy is not a tree but a DAG although the active hierarchy is tree-like.
But what if we just call set_rate() and it switches parent of the clock automatically and sets desirable rate.
This might make sense for your SOC clock that you are looking at but not generically. There maybe dozens of clocks dependant on a parent and it maybe possible to re-rate grand-parents, etc. It is probably not the best choice to re-rate the system clock because an audio driver wants a clock that is a few HZ out?
It is possible to write the clock driver so that it will re-rate the parent if a request is made on a child that doesn't work. However, this is part of the clock drivers and not the CCF generally.
Example
For instance, an SOC might have an audio clock with three input sources,
A dedicated 48000khz
Some low speed bus clock (platform general)
A USB clock
Option 1 is the best sound quality with the highest power consumption. Option 2 is meant to be generic but may not match sound rates well resulting in sub-optimal DAC/wave/sound generation. Option three might be good for some sort of USB sound slave, but if you are not using USB this may be expensive for power consumption.
In the case above, set_parent() maybe a way to get the desired rate, if the SOC clock driver supports it.
There is no intelligence in the CCF; if there is some flexibility it is in the clock driver but this depends on the clock hardware. It is up to a programmer to read the SOC documentation and determine what is the best way to configure the clock tree. Probably you should also examine the clock driver for your SOC and Linux version to see what it is supporting. You can not generically change the clock rate of parents in a driver as other devices may depend on them. If you need this for a particular SOC in an SOC family, you need to special case it by examining a device tree to see which SOC the driver is running on. This is the case where you can use get_parent() and set_rate() for the particular SOC.
Reference: A question on older Linux clock structure.

Measure input voltage of Raspberry Pi B+ running Ubuntu

I just learned that a red flashing LED indicates voltage below 4.63V on a Raspberry Pi Model B+.
Is there a command to determine the voltage programmatically?
I tried vcgencmd measure_volts. But it yields 1.2000V, independent of the input source and the LED status. And it doesn't seem to be related to the 4.63V mentioned above.
Update
Let me describe the situation in a bit more detail:
I'm powering the Raspberry Pi with a lead-acid battery built into a moving robot. After operating the robot for a while, the voltage seams to drop below a critical minimum, causing potential damage to the file system. Therefore, I'd like to detect low voltage automatically (and trigger the robot to return to the charging station).
I'm asking here in StackOverflow, since I assume the solution not to be robotic-specific, but generally applicable to other machines.
Yes you can, as it is said in this topic Under-voltage warnings you can know the low voltage reading the GPIO 35. For reading GPIO, you can refer to this topic:
Python Script to read one pin
Have a look at the adafruit ina219 sensor https://learn.adafruit.com/downloads/pdf/adafruit-ina219-current-sensor-breakout.pdf .
This sensor can be put between the battery and the raspberry and measures the current and the voltage along this connection (0-26V and max. 3.2A). It communicates via i2c bus. Together with an Arduino you can easyly build an battery watchdog for your raspberry. A sample program and the arduino driver can be found here: https://github.com/adafruit/Adafruit_INA219.
According to https://raspberrypi.stackexchange.com/questions/7414/is-it-possible-to-detect-input-voltage-using-only-software it's not possible to do it on software level without other hardware.

gps time synchronization accuracy

i have a GPS NTP Time server synchronizing my PC.
HOW am i able to compare 1PPS of the GPS receiver with clock pulse of my PC to see how much accurately it is synced to the GPS time?(with an oscilloscope maybe!)
I've designed experiments of this sort before. In my case, I wrote a device driver that would -- inside the kernel -- watch the PC's clock in a tight loop waiting for it to roll over to a new second. As soon as it did, I would raise one of the pins high on the PC parallel port. Then I attached that pin of the parallel port and the PPS signal output of the GPS receiver to an oscilloscope and had it measure the time difference between the two pulses.

Resources