I have 2 puzzles and wonder if anyone can point out a solution to them.
- I am using a Pico W, Pico Display Pack 2.0 and MicroPython to make a small oscilloscope. I use DMA to accurately sample the ADC at specific sample time periods and the ADC data is stored into a buffer, which I then read, manipulate and display as a scope display.
The sampling time period for the DMA uses a 48MHz clock and the faster for the Pico ADC is 2uS (500kHz) and so 96 is stored into the DMA ADC clock div register (96 / 48MHz = 2uS period). This clock div register is 16 bits and so the max that can be entered is 65535, which when divided by 48MHz clock gives a sample period = 1365uS (732Hz).
I use core 0 to process the ADC-DMA sampling into a buffer and core 1 to handle the display and change of parameters, etc, using an encoder.
Q: is there any method that this 48MHz ADC-DMA clock can be divided/slowed down, so as to allow a much slower accurate sampling period down to say 1 sec. If the existing 16-bit ADC DMA clock divisor register was 32-bits it could be done but the 16-bit register limits the range. The data sheet shows there is a fractional 8-bit section, but this does not assist and extend the sampling period.
- I need to accurately measure the time period/width of a very fast pulse on a GPIO pin. I could read the status of a pin and when it goes low read and store the utime.tick_us() value, and when it returns high, read the utime.tick_us() value then calc the difference to get the pulse width. Apart from the time lag of detecting a pin change, the resolution of the utime.tick_us() is, as the name says, 1uS.
I need to have a resolution of around 20nS as I need to catch a very small change of pulse size, and so time.ticks_us() cannot be used.
A 100MHz clock has a clock period of 10nS and the Pico’s internal clock can be 125MHz or 133MHz and can even be faster.
Q: is there a method to speedily detect the change of status of a GPIO pin, then start a high speed counter (eg using the internal 125MHz) to be able to accurately measure the width of a pulse, with fine resolution.
I wonder if it is possible to use PIO programming to do this, but I do not know how to do this as yet and have never used it.
If anyone has done either of the above, could you please point me in the right direction.
Thanks for looking.