Skip to content

Commit 6e5b8f5

Browse files
authored
Board specific frequencies and more accurate target blink rate (#26)
Use the machine.CPUFrequency() function to customize the frequency scaling to the working board. Also, in the form of "-3", account for the three clock cycles that the PIO takes to implement its fastest supported frequency blinking. This addresses #25 Signed-off-by: Tinkerer <[email protected]>
1 parent 3a8179f commit 6e5b8f5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

rp2-pio/examples/blinky/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ func main() {
2525
blinkPinForever(Pio.StateMachine(2), offset, machine.GPIO11, 1)
2626
}
2727

28-
func blinkPinForever(sm pio.StateMachine, offset uint8, pin machine.Pin, freq uint) {
28+
func blinkPinForever(sm pio.StateMachine, offset uint8, pin machine.Pin, freq uint32) {
2929
blinkProgramInit(sm, offset, pin)
30-
const clockFreq = 125000000
30+
clockFreq := machine.CPUFrequency()
3131
sm.SetEnabled(true)
3232
println("Blinking", int(pin), "at", freq, "Hz")
33-
sm.TxPut(uint32(clockFreq / (2 * freq)))
33+
sm.TxPut(uint32(clockFreq/(2*freq)) - 3)
3434
}

0 commit comments

Comments
 (0)