Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8015

General • Re: Stepper control using Timers and PIO

$
0
0
Do you want something like this (completely untested)?

Code:

; pull out 16 bit integers from FIFO, and generate n+1 pwm pulses; autopull, joined FIFO.side_set 1.wrap_targetout y, 16 side 0loop_start:jmp y-- loop side 1.wraploop:jmp loop_start side 0
You'd write a 16 bit integer with value n-1 for n pulses, 50% duty cycle, to the FIFO.
And how do I set the PIO frequency give an output of exact frequency??
The PIO runs off the system clock, and you can divide it down with the SMx_CLKDIV registers. So for the PIO program from above running at 400 kHz for a 200 kHz output wave at a system clock of 100 MHz the divider would be 250.

I am using a Pico 2 so frequency is 150Mhz and each instruction is a cycle so 3 cycles each cycle is 2.5us then 7.5us would give clk div of 1125.

So I just need to use sm_put_blocking to give a value and this does the job

Statistics: Posted by akash614 — Mon May 05, 2025 5:05 pm



Viewing all articles
Browse latest Browse all 8015

Trending Articles