Measure PWM Duty Cycle on RP2040 using micropython - slice

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

Related

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

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?

Can a clock be set in VHDL using an internal oscillator?

I am trying to learn VHDL, an am writing a simple transmitter for serial data. However, I encountered a problem - I need a clock to run it, and the datasheet for my FPGA (MAX II) says this:
Output of the internal oscillator for MAX II devices: 3.3-5.5 MHz
So there is no way to reliably set the frequency of the internal FPGA oscillator? And if there is, how do you do it efficiently?
Thanks!
No, there is no way to set the frequency of the internal oscillator. It's most likely an RC oscillator built into the die, so its frequency will depend heavily on silicon process variations and temperature.
If you need something more precise, it'll need to be external to the CPLD.

What is the simplest way to transmit a signal over MGT of Xilinx FPGA?

I want to send signals (doesn't matter what type of signal, just random binary) over MGT lanes of a Xilinx FPGA. This is for testing the MGT traces on the PCB. What is the simplest way I can achieve this? For a regular IO I would simply use an output buffer (OBUF) and send out the signal to the output pins. What would be the equivalent of this (or the simplest equivalent of this) for MGT bank pins?
EDIT:
I want to stay away from ipcores as much as possible. I'm looking for a really simple solution to somehow buffer signals to MGT pins.
If you have both TX and RX lanes then I would suggest to perform loopback test. FPGA would produce data on TX link, receive it on RX and compare results.
To do so you can connect TX lanes to RX lanes on PCB connector and use FPGA Ibert core that will automatically create transmit, receive and compare circuits and produce nice results for each lane.
For 7 series here is the link to Ibert core
http://www.xilinx.com/products/intellectual-property/ibert_7series_gtx.html
For other families Ibert is also available.

TSMP77000 IR Receiver Code

I'm using tsmp77000 IR Sensor module for air conditioner remote control system.
datasheet
I instructed remote controller device of the air conditioner to sensor module and i saw voltage outputs(active low) on the oscilloscope. Then, i need to transmit this signals with IR transmitter led for control air conditioner. But, there is voltage outputs, there isn't frequency graph. How to i convert to pwm output of this signal? Frequency, duty cycle?
And I saw frequency value on the ossiloscope, but it is 833Hz. Whereas,range of IR receiver sensor module is 20-60kHz.
Thank you!
Here is a good explanation of how IR remote signals work by Adafruit: https://learn.adafruit.com/ir-sensor/ir-remote-signals
The 833Hz you are seeing on the oscilloscope are most likely the "wide" bands. If you zoom in, you should see that each pulse is actually made up of many, faster, PWM pulses.
Your best bet will be determining the frequency of the fast IR pulses, setting your PWM pin to that frequency, and then manually enable/disable the PWM pin for the appropriate time intervals, as per the oscilloscope reading.

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.

Resources