Pico PIO using an external clock. #14418
Replies: 4 comments 2 replies
-
I think you need something like: @rp2.asm_pio(sideset_init=PIO.OUT_LOW)
def clock_divby10():
wrap_target()
wait(0, pin, 0) .side(0)
wait(1, pin, 0) .side(0)
wait(0, pin, 0) .side(0)
wait(1, pin, 0) .side(0)
wait(0, pin, 0) .side(0)
wait(1, pin, 0) .side(0)
wait(0, pin, 0) .side(0)
wait(1, pin, 0) .side(0)
wait(0, pin, 0) .side(0)
wait(1, pin, 0) .side(0)
wait(0, pin, 0) .side(1)
wait(1, pin, 0) .side(1)
wait(0, pin, 0) .side(1)
wait(1, pin, 0) .side(1)
wait(0, pin, 0) .side(1)
wait(1, pin, 0) .side(1)
wait(0, pin, 0) .side(1)
wait(1, pin, 0) .side(1)
wait(0, pin, 0) .side(1)
wait(1, pin, 0) .side(1)
wrap() Instead of |
Beta Was this translation helpful? Give feedback.
-
I have found some code that enables a 10 MHz external clock to be connected to GPIO20 (pin 26). The code then divides this clock into different frequencies and provides them on GPIO pins. The code is here: https://github.com/dorsic/PicoDIV?tab=readme-ov-file This is written in C but a Micropython version would be easier for me to use. I'd appreciate if someone could indicate how this could be moved to Micropython. |
Beta Was this translation helpful? Give feedback.
-
I suppose this is using the PWM peripheral on the RP2, which may be set up to count incoming pulses on a pin. |
Beta Was this translation helpful? Give feedback.
-
Thank you for pointing out that blog page which is very interesting. Since I'm building a GPS locked 10 MHz VCXO then I can't tolerate any jitter in the divided 10 MHz clock. I have tried using a PWM to divide the Pico clock to 1 MHz and that appears to work OK. The issue is that I can't find away to use an external clock to drive the PWM when using Micropython. |
Beta Was this translation helpful? Give feedback.
-
I've tested this code that sets the Pico PIO clock to 10 MHz, divides it by 10 then delivers 1 MHz to Pin 17. This works fine.
import utime
from rp2 import PIO, asm_pio
from machine import Pin
@asm_pio(set_init=rp2.PIO.OUT_HIGH)
def divide10():
wrap_target()
set(pins,1) [4] # set output high for 5 cycles
set(pins,0) [4] # set output low for 5 cycles
wrap()
sm = rp2.StateMachine(0, divide10, freq = 10000000, set_base=Pin(17))
sm.active(1)
Instead of using the internal clock I'd like to use an external GPS locked 10 MHz clock connected to say Pin 16 to run the code. That way the 1 MHz clock would be very accurate and stable.
I've not been able to find any code that does this and would appreciate some assistance please.
Beta Was this translation helpful? Give feedback.
All reactions