<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Stepper Motor Control with Raspberry Pico PIO and DRV8711 driver- Part 6: autonomous PIO with speed control</title><link>/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-5-autonomous-pio-with-speed-control</link><description>The Pico has a set of PIO co-processors. They are real-time controllers that can execute logic with deterministic timing. Ideal to run strict-timed sequences and state machines. And to implement extra peripherals.In this series, I&amp;#39;m trying t...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Stepper Motor Control with Raspberry Pico PIO and DRV8711 driver- Part 6: autonomous PIO with speed control</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-5-autonomous-pio-with-speed-control</link><pubDate>Sat, 12 Apr 2025 19:31:49 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:6908389d-8e75-40fe-b264-f91446f88f7b</guid><dc:creator>DAB</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Nice update Jan.&lt;/p&gt;
&lt;p&gt;You are making great progress.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28822&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Stepper Motor Control with Raspberry Pico PIO and DRV8711 driver- Part 6: autonomous PIO with speed control</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-5-autonomous-pio-with-speed-control</link><pubDate>Sat, 12 Apr 2025 19:07:49 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:6908389d-8e75-40fe-b264-f91446f88f7b</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I added an interrupt option. The PIO will raise an interrupt when it has completed the number of steps requested.&lt;/p&gt;
&lt;p&gt;It&amp;#39;s optional, but useful if you want to do other activities when the motor has done some activities - and you don&amp;#39;t ant to rely on calculations/estimations of time passed.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;[mention:fc48193383514ad18b3997352ebcdb02:f7d226abd59f475c9d224a79e3f0ec07]&amp;nbsp;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28822&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Stepper Motor Control with Raspberry Pico PIO and DRV8711 driver- Part 6: autonomous PIO with speed control</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-5-autonomous-pio-with-speed-control</link><pubDate>Thu, 10 Apr 2025 21:01:51 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:6908389d-8e75-40fe-b264-f91446f88f7b</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;It&amp;#39;s not possible to debug a PIO, but there&amp;#39;s a nice emulator:&amp;nbsp;&lt;a id="" href="https://rp2040pio-docs.readthedocs.io/en/latest/index.html" rel="noopener noreferrer nofollow" target="_blank" data-e14adj="t"&gt;https://rp2040pio-docs.readthedocs.io/en/latest/index.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That one allows you to step and watch registers, FIFOs, and simulate in and out (either data or pins)&lt;/p&gt;
&lt;p&gt;Here, it&amp;#39;s loaded with my stepper design, running on WSL ubuntu:&lt;/p&gt;
&lt;p&gt;&lt;img height="276" src="/resized-image/__size/998x552/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-6908389d-8e75-40fe-b264-f91446f88f7b/pastedimage1744318840159v1.png" width="499" alt=" " /&gt;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28822&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Stepper Motor Control with Raspberry Pico PIO and DRV8711 driver- Part 6: autonomous PIO with speed control</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-5-autonomous-pio-with-speed-control</link><pubDate>Thu, 10 Apr 2025 15:30:14 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:6908389d-8e75-40fe-b264-f91446f88f7b</guid><dc:creator>ahsrabrifat</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;This is the first time I have come across PIO codes. Are these based on assembly language?&amp;nbsp;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28822&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: Stepper Motor Control with Raspberry Pico PIO and DRV8711 driver- Part 6: autonomous PIO with speed control</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-5-autonomous-pio-with-speed-control</link><pubDate>Wed, 09 Apr 2025 13:47:36 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:6908389d-8e75-40fe-b264-f91446f88f7b</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;em&gt;&amp;gt;&amp;nbsp; The granularity is still rough. With these slow signals (850 Hz as fastest that my motor can handle in full-step mode), each delay adds 2 extra ticks. &lt;br /&gt;&amp;gt;&amp;nbsp; One tick is added to each half &lt;/em&gt;&lt;em&gt;of the pulse. It&amp;#39;s a lot. Making it more granular is something for a next exercise ...&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have a solution for this. A compromise for the developer, but works well. No changes to the PIO state machine.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In my first approach, I brough down the clock to a reasonable speed for a stepper motor. By default, it&amp;nbsp;churns out&amp;nbsp;pulses at several MHz.&lt;br /&gt;By dividing the clock, it dropped to a range that makes sense for steppers.&lt;br /&gt;But that has as side effect, that each extra clock tick I steal to make the motor go slower, is rather big.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What I&amp;#39;ve done now, is make the clock divider programmable by the end user. That way they can choose how fine the delay mechanism acts.&lt;br /&gt;At the cost of having to set a delay that&amp;#39;s in the 1000s. Each delay step will add 2 clockticks of the frequency the PIO runs at to each pulse&amp;#39;s period.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So if you set a high clock (say: keep PICO clock, or divide it by 2), you have to set high delays, but they are very fine and give precise control.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you set that divider to a higher value, you may not have to use delay at all, or lower values of delay. But the granularity at each delay step becomes rough.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In the end, there is no efficiency gain&amp;nbsp;for one vs the other. It&amp;#39;s a choice.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Here is an example function that steps with delay:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:3378b21b-f8fc-4f7d-8da8-dfaadfc4965f:type=c_cpp&amp;text=void%20demo_with_delay%28const%20std%3A%3Aspan%3Ccommand%3E%20%26%20cmd%2C%20uint32_t%20delay%29%20%7B%0D%0A%20%20%20%20pio_pwm_set_delay%28piostep%2C%20sm%2C%20delay%29%3B%0D%0A%20%20%20%20for%28auto%20c%20%3A%20cmd%29%20%7B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%20printf%28%22Steps%20%3D%20%25d%5Cn%22%2C%20c.steps%29%3B%0D%0A%20%20%20%20%20%20%20%20pio_stepper_set_steps%28piostep%2C%20sm%2C%20c.steps%2C%20c.reverse%29%3B%0D%0A%20%20%20%20%7D%0D%0A%7D]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and code that uses it:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:c182fe11-e09e-477b-9858-9165d5bffae2:type=c_cpp&amp;text=%20%20%20%20std%3A%3Aarray%3Ccommand%2C%206%3E%20cmd%7B%7B%0D%0A%20%20%20%20%20%20%20%20%7B200%20%2A%20microstep_multiplier%2C%20true%7D%2C%20%0D%0A%20%20%20%20%20%20%20%20%7B200%20%2A%20microstep_multiplier%2C%20false%7D%2C%0D%0A%20%20%20%20%20%20%20%20%7B200%20%2A%20microstep_multiplier%2C%20false%7D%2C%0D%0A%20%20%20%20%20%20%20%20%7B400%20%2A%20microstep_multiplier%2C%20false%7D%2C%0D%0A%20%20%20%20%20%20%20%20%7B250%20%2A%20microstep_multiplier%2C%20true%7D%2C%0D%0A%20%20%20%20%20%20%20%20%7B350%20%2A%20microstep_multiplier%2C%20true%7D%7D%0D%0A%20%20%20%20%7D%3B%0D%0A%0D%0A%20%20%20%20%7B%0D%0A%20%20%20%20%20%20%20%20wakeup_drv8711%20w%3B%20%2F%2F%20wake%20up%20the%20stepper%20driver%0D%0A%20%20%20%20%20%20%20%20sleep_ms%281%29%3B%20%2F%2F%20see%20datasheet%0D%0A%0D%0A%20%20%20%20%20%20%20%20demo_with_delay%28cmd%2C%204300%29%3B%0D%0A%20%20%20%20%20%20%20%20sleep_ms%282000%29%3B%20%2F%2F%20give%20enough%20time%20to%20complete%20the%20action%0D%0A%20%20%20%20%20%20%20%20demo_with_delay%28cmd%2C%207000%29%3B%0D%0A%20%20%20%20%20%20%20%20sleep_ms%283000%29%3B%20%2F%2F%20give%20enough%20time%20to%20complete%20the%20action%0D%0A%20%20%20%20%20%20%20%20demo_with_delay%28cmd%2C%209000%29%3B%0D%0A%20%20%20%20%20%20%20%20sleep_ms%284500%29%3B%20%2F%2F%20give%20enough%20time%20to%20complete%20the%20action%0D%0A%20%20%20%20%7D]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I divided the PIO clock by 2 for this example:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:b8b12751-bd72-473f-bf8c-ea6003e40728:type=c_cpp&amp;text=const%20float%20clock_divider%20%3D%202.0%3B%20%2F%2F%20works%20well%20for%208%20microsteps%0A%0A%2F%2F%20...%0A%20%20%20%20uint%20offset%20%3D%20pio_add_program%28piostep%2C%20%26stepper_program%29%3B%0A%20%20%20%20stepper_program_init%28piostep%2C%20sm%2C%20offset%2C%20dir%2C%20clock_divider%29%3B%0A%20%20%20%20pio_sm_set_enabled%28piostep%2C%20sm%2C%20true%29%3B%0A%2F%2F%20...]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28822&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>