<?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 7: autonomous PIO with interrupt when done</title><link>/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-7-autonomous-pio-with-interrupt-when-done</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 7: autonomous PIO with interrupt when done</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-7-autonomous-pio-with-interrupt-when-done</link><pubDate>Wed, 16 Apr 2025 17:35:18 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:fc481933-8351-4ad1-8b39-97352ebcdb02</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Frequency of stepper motor pulses is 100s of Hz max, maybe a few&amp;nbsp;kHz for a specialised&amp;nbsp; motor in micro-steps. I use a clock divider and a programmable delay to get the pulses to a manageable range.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But if you wonder: what&amp;#39;s the maximum pulse speed of this design on a Pico 1 ([mention:0d133614bf01463a9e17ef49e25b2c0b:e9ed411860ed4f2ba0265705b8793d05]&amp;nbsp;, not overclocked!)?&lt;/p&gt;
&lt;p&gt;&lt;img height="299" src="/resized-image/__size/998x598/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-fc481933-8351-4ad1-8b39-97352ebcdb02/DS1Z_5F00_QuickPrint6.png" width="499" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;20MHz - definitely fast enough for anything stepper related for the next&amp;nbsp;decades.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28829&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 7: autonomous PIO with interrupt when done</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-7-autonomous-pio-with-interrupt-when-done</link><pubDate>Tue, 15 Apr 2025 19:30:58 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:fc481933-8351-4ad1-8b39-97352ebcdb02</guid><dc:creator>DAB</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Nice post Jan.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28829&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 7: autonomous PIO with interrupt when done</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-7-autonomous-pio-with-interrupt-when-done</link><pubDate>Tue, 15 Apr 2025 17:43:30 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:fc481933-8351-4ad1-8b39-97352ebcdb02</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;object oriented version:&amp;nbsp;&amp;nbsp;[mention:301aa380c4e84007a488aadeebc7fbd4:f7d226abd59f475c9d224a79e3f0ec07:label=Handle%20Raspberry%20Pico%20PIO%20%26quot%3Brelative%20interrupts%26quot%3B%20in%20C%2B%2B]&amp;nbsp;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28829&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 7: autonomous PIO with interrupt when done</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-7-autonomous-pio-with-interrupt-when-done</link><pubDate>Sun, 13 Apr 2025 10:14:07 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:fc481933-8351-4ad1-8b39-97352ebcdb02</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;The explanation of relative IRQ is a bit fuzzy. I&amp;#39;ve created a table with&amp;nbsp;what&amp;nbsp;the PIO actually throws (int) when choosing state machine (sm) 0 - 3 and IRQ 0 - 3&lt;/p&gt;
&lt;p&gt;&lt;img height="296" src="/resized-image/__size/994x592/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-fc481933-8351-4ad1-8b39-97352ebcdb02/pastedimage1744539070888v1.png" width="497" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf" rel="noopener noreferrer nofollow" target="_blank" data-e14adj="t"&gt;SDK&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img height="33" src="/resized-image/__size/982x66/__key/commentfiles/f7d226abd59f475c9d224a79e3f0ec07-fc481933-8351-4ad1-8b39-97352ebcdb02/pastedimage1744539198194v2.png" width="491" alt=" " /&gt;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28829&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 7: autonomous PIO with interrupt when done</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-7-autonomous-pio-with-interrupt-when-done</link><pubDate>Sat, 12 Apr 2025 19:22:00 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:fc481933-8351-4ad1-8b39-97352ebcdb02</guid><dc:creator>DAB</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Nice update Jan.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28829&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 7: autonomous PIO with interrupt when done</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-7-autonomous-pio-with-interrupt-when-done</link><pubDate>Sat, 12 Apr 2025 18:38:11 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:fc481933-8351-4ad1-8b39-97352ebcdb02</guid><dc:creator>ahsrabrifat</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Have you written any content on the introduction to PIO?&amp;nbsp;&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28829&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 7: autonomous PIO with interrupt when done</title><link>https://community.element14.com/products/raspberry-pi/b/blog/posts/stepper-motor-control-with-raspberry-pico-pi-and-drv8711-driver--part-7-autonomous-pio-with-interrupt-when-done</link><pubDate>Sat, 12 Apr 2025 18:31:03 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:fc481933-8351-4ad1-8b39-97352ebcdb02</guid><dc:creator>Jan Cumps</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;em&gt;&amp;gt;&amp;nbsp;watchout 1: each PIO can run 4 motors. I haven&amp;#39;t&amp;nbsp;added the logic yet to know which&amp;nbsp;motor is finished. That&amp;#39;s for a next blog.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I have this solved. You can add the state machine index to the interrupt # in PIO, by adding the &lt;strong&gt;rel&lt;/strong&gt; clause&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:414ba5c4-d3a5-4fa1-9a88-81905275b0ba:type=text&amp;text=%20%20%20%20irq%20PIO_IRQ_DONE%20rel%20%20%20%20%20%20%20%20side%200%20%3B%20flag%20that%20the%20job%27s%20done]&lt;/p&gt;
&lt;p&gt;In this case, state machine 0 will throw interrupt 0, SM 1 interrupt 1, ...&lt;/p&gt;
&lt;p&gt;In C, I had to change a few things to take that into account. First the handler:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:eaf348b2-f87f-470e-afa3-625e41d9ab32:type=c_cpp&amp;text=void%20pio_irq_handler%28void%29%7B%0D%0A%20%20%20%20if%28pio_interrupt_get%28piostep%2C%20stepper_PIO_IRQ_DONE%20%2B%20sm%29%29%20%20%20%20%20%7B%0D%0A%20%20%20%20%20%20%20%20pio_interrupt_clear%28piostep%2C%20stepper_PIO_IRQ_DONE%20%2B%20sm%29%3B%0D%0A%20%20%20%20%20%20%20%20commands_completed%20%3D%20commands_completed%20%2B%201%3B%0D%0A%20%20%20%20%7D%0D%0A%7D]&lt;/p&gt;
&lt;p&gt;(note: my code only entertains 1 motor. I&amp;#39;d&amp;nbsp;make an array of commands_completed if I had more motors.)&lt;/p&gt;
&lt;p&gt;And the interrupt register needs to be refined too:&lt;/p&gt;
&lt;p&gt;[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:ebd8534a-b43e-485f-933f-bbe047d71030:type=c_cpp&amp;text=%20%20%20%20pio_set_irq0_source_enabled%28piostep%2C%20static_cast%3Cpio_interrupt_source%3E%28std%3A%3Ato_underlying%28pis_interrupt0%29%20%2B%20sm%29%20%2C%20true%29%3B%20]&lt;/p&gt;
&lt;p&gt;That&amp;#39;s it. I&amp;#39;ll make a demo that runs 2 motors on the same state machine to showcase this.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=28829&amp;AppID=86&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>