PIO on the Raspberry Pi Pico

Every time I’ve started to approach the use of the programmable IO (PIO) subsystem on the RP2040 or RP2350 (as used on the Raspberry Pi Pico), I’ve found myself essentially starting from scratch again and the examples quite opaque to me.

So this time as I’ve worked through it yet again, I’ve decided to write it all down 🙂

Here are some existing tutorials and projects that talk about getting going with the PIO:

Assembling PIO Code

The PIO has its own bespoke micro-instruction set that is very similar to many types of assembly language and it requires its own pio assembler to process it. The basic sequence is as follows:

  • PIO -> pioasm -> C header file -> include in C/C++ project and build

There are options for writing PIO in both Micropython and Circuitpython, which I have done in the past, but I’m sticking with the C route here. This requires the pioasm to take PIO code and produce a C header file that can then be included in a C project.

To use the RP2040/2350 Arduino environment, it is necessary to process PIO independently and then add the C file to the Arduino project. The Raspberry Pi C/C++ SDK can process PIO files directly as part of the main build.

There is also an option to use hardware SDK functions for dynamic creation of PIO code at runtime. The functions are a series of pio_encode_XX() functions representing the different PIO instructions as listed here: https://www.raspberrypi.com/documentation/pico-sdk/hardware.html#group_pio_instructions

There are two other novel approaches I found so far too:

The first is an online editing environment that creates the required processed PIO related code for the C/C++ SDK or Python which can then be included in your build environment as required.

The second is an alternative run-time approach that uses a range of C macros to allow the “assembling” of PIO code as part of the run-time execution. It does this by directly creating the HEX equivalents of PIO instructions, thereby effectively assembling in the fly. This means that the PIO code can be customised to the specific run-time situation.

At this stage I’m not sure what it gives over using the pio_encode_ SDK functions directly. I do note however there is an equivalent PIO emulator which means this approach will run equally well on real hardware or in emulation. I’ve bookmarked this to come back to at some point.

Running PIO Code

Regardless of how the PIO instructions become code, to use them requires setting up and configuring the PIO state machines at run time as part of a project. A common approach is to include an initialisation function within the PIO code itself that is destined for passing straight through to the C/C++ SDK. This will have access to all definitions used within the PIO code and also allows the appropriate configuration information to remain encapsulated with the code.

But I have to admit I find there is an awful lot of assumed “magic” going on when configuring and getting running PIO programs and state machines. And whilst there are plenty of examples to study, I don’t find that they are written so as to teach. Consequently, I’ve noted the following as “reminders to self” on how to read some of the examples. It doesn’t help that the SDK function list is very long and there are several ways to achieve the same things.

Taking the PIO PWM code from the pico_examples as a starting point (https://github.com/raspberrypi/pico-examples/tree/master/pio/pwm), I’ve added in some comments containing the full function prototypes for some of the calls to make them a bit easier to walk through.

pwm.pio:

;
; Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
;
; SPDX-License-Identifier: BSD-3-Clause
;

; Side-set pin 0 is used for PWM output
.pio_version 0 // only requires PIO version 0

.program pwm
.side_set 1 opt

pull noblock side 0 ; Pull from FIFO to OSR if available, else copy X to OSR.
mov x, osr ; Copy most-recently-pulled value back to scratch X
mov y, isr ; ISR contains PWM period. Y used as counter.
countloop:
jmp x!=y noset ; Set pin high if X == Y, keep the two paths length matched
jmp skip side 1
noset:
nop ; Single dummy cycle to keep the two paths the same length
skip:
jmp y-- countloop ; Loop until Y hits 0, then pull a fresh PWM value from FIFO

% c-sdk {
static inline void pwm_program_init(PIO pio, uint sm, uint offset, uint pin) {

// static void pio_gpio_init (PIO pio, uint pin)
pio_gpio_init(pio, pin);

// int pio_sm_set_consecutive_pindirs (PIO pio, uint sm, uint pins_base, uint pin_count, bool is_out)
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);

// A piece of pioasm "magic" based on .program pwm (see following notes)
pio_sm_config c = pwm_program_get_default_config(offset);

// static void sm_config_set_sideset_pins (pio_sm_config *c, uint sideset_base)
sm_config_set_sideset_pins(&c, pin);

// int pio_sm_init (PIO pio, uint sm, uint initial_pc, const pio_sm_config *config)
pio_sm_init(pio, sm, offset, &c);
}
%}

And its associated C code pwm.c:

/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdio.h>

#include "pico/stdlib.h"
#include "hardware/pio.h"
#include "pwm.pio.h"

// Write `period` to the input shift register
void pio_pwm_set_period(PIO pio, uint sm, uint32_t period) {
pio_sm_set_enabled(pio, sm, false);
pio_sm_put_blocking(pio, sm, period);
pio_sm_exec(pio, sm, pio_encode_pull(false, false));
pio_sm_exec(pio, sm, pio_encode_out(pio_isr, 32));
pio_sm_set_enabled(pio, sm, true);
}

// Write `level` to TX FIFO. State machine will copy this into X.
void pio_pwm_set_level(PIO pio, uint sm, uint32_t level) {
pio_sm_put_blocking(pio, sm, level);
}

int main() {
stdio_init_all();
#ifndef PICO_DEFAULT_LED_PIN
#warning pio/pwm example requires a board with a regular LED
puts("Default LED pin was not defined");
#else

// todo get free sm
PIO pio = pio0;
int sm = 0;
uint offset = pio_add_program(pio, &pwm_program);
printf("Loaded program at %d\n", offset);

pwm_program_init(pio, sm, offset, PICO_DEFAULT_LED_PIN);
pio_pwm_set_period(pio, sm, (1u << 16) - 1);

int level = 0;
while (true) {
printf("Level = %d\n", level);
pio_pwm_set_level(pio, sm, level * level);
level = (level + 1) % 256;
sleep_ms(10);
}
#endif
}

There are a few key things to remember to make sense of these examples:

  • The offset that is talked about is (I believe) the location within the shared 32 instruction program area and is used to refer back to the installed PIO program. It is returned from pio_add_program().
  • A PIO .program directive becomes a default C like directive on processing by pioasm. This results in two obscure bits of “magic” coding going on meaning in this case that “.program pwm” in the PIO file becomes “pwm_program” in C/C++:
    • pio_program_t pwm_program is a C structure which can then be referenced from the C code as shown in the line pio_add_program(pio, &pwm_program).
    • static inline pio_sm_config pwm_program_get_default_config(uint offset) is a C function based on pio_get_default_sm_config() that returns the PIO configuration for the specific PIO program in question – in this case of course the pwm program.
  • The use of .side_step opt means that not every PIO instruction has to have a side step instruction too.
  • The PIO refers to an abstract group of pins, but it is the configuration which is part of the C/C++ SDK that determines which pins are used.
  • The %c-sdk { … %} pairing signifies that this part of the PIO code will be passed straight onto the C/C++ SDK.
  • There are multiple ways of initialising GPIO pins and directions. In this example it doesn’t use pindirs in the PIO code but uses pio_sm_set_consecutive_pindirs() in the C code.
  • This example uses hardcoded references to PIO 0 and SM 0, but in many cases the PIO and SM would be chosen dynamically using API calls such as the following:
    • pio_claim_free_sm_and_add_program ()
    • pio_claim_free_sm_and_add_program_for_gpio_range()
    • pio_claim_unused_sm()
  • Each PIO program has a default configuration associated with it which can be updated. A typical pattern is shown here where the default configuration is grabbed using (in this case) pwm_program_get_default_config() and then updated by passing into following SDK calls.
  • The state machine is finally set running using pio_sm_init();

There is one additional mix of techniques that is worth pulling out here. In the C code the function pio_pwm_set_period() is used to update the PWM period which it has to do by passing it into the SM via the FIFO. It is using some SM manipulation routines and then some inline, run-time PIO code, to achieve this.

void pio_pwm_set_period(PIO pio, uint sm, uint32_t period) {
pio_sm_set_enabled(pio, sm, false);
pio_sm_put_blocking(pio, sm, period);
pio_sm_exec(pio, sm, pio_encode_pull(false, false));
pio_sm_exec(pio, sm, pio_encode_out(pio_isr, 32));
pio_sm_set_enabled(pio, sm, true);
}

Again some pretty confusing API calls, especially giving this is meant to be an example, but essentially what is going on (I think) is:

Disable the statemachine by using pio_sm_set_enabled(... false).
Push the period value into the TX FIFO, blocking if full to wait for it to be empty.

Execute two direct PIO instructions using pio_sm_exec():
This uses pio_encode_pull and pio_encode_out to run the following PIO code:
pull noblock ; non-blocking pull
out isr, 32 ; out 32 bits to the interrupt shift register

Re-enable he state machine using pio_sm_set_enabled(... true).

By default anything sent to the FIFO is written to the X register and used to set the duty cycle of the PWM. But this code creates some temporary PIO code to receive the contents of the FIFO and put it into ISR instead. Of course it has to temporarily suspend the execution of the stored PIO code in order to do this.

I really dislike the nomenclature of “set enabled (false)” as an API approach. I’d much prefer to see something like pio_sm_enable() and pio_sm_disable() myself. I suppose they haven’t done this due to the large increase in API functions it creates.

I guess this is personal preference, but I do find that it adds to the opaqueness of much of the example code when it doesn’t read naturally.

So To Recap…

Writing PIO code can be done at build time (from Python or C/C++ using pioasm or an online assembler) or run time (using pio_encode_ functions or maybe APIO).

pioasm bridges the gap between PIO code and C/C++ including creating two magic C/C++ constructs: pwm_program for the code and pwm_program_get_default_config() to return the created PIO configuration.

PIO and SMs can be allocated by the system using a range of “claim” functions. There are 2 PIOs on the RP2040 and 3 on the RP2350, each with its own 32 instruction program memory and each with four state machines.

It can be useful to include an initialisation routine, that configures and starts the PIO program, within the PIO code for use from the C/C++ code using % c-sdk { … %}.

The PIO program is added into the system and given an offset in instruction memory using pio_add_program.

PIO code is very dense and often the functionality cannot be seen from the PIO code itself as it is defined by the PIO configuration – e.g. pins to use, frequency of execution, direction of shifts and so on.

I’ve not touched on it here, but the use of PIO and DMA (direct memory access) often go hand in hand to create completely CPU-free means of getting data in and out of a RP2040/RP2350 system. A really good example of this is Piers Rocks’ OneROM (see this video for a brilliant summary of how this works: https://www.youtube.com/watch?v=Y8RODQZM2HY).

Finally I need to remember that ISR stands for Input Shift Register and not Interrupt Service Routine…

Kevin

#pio #raspberryPiPico #rp2040 #rp2350
Microcontroller chips - Raspberry Pi Documentation

The official documentation for Raspberry Pi computers and microcontrollers

Dear #lazyweb, does any anyone know how to get the #tasmota #pio build system to regenerate the .bec and .tapp files? There seem to be hints about a "solidify" step but nothing to trigger it from the build system.

今更だけど
ラズパイPico、PIOなんてあったの???

そう言えば RP2040 のデータシート、読んだ事なかったかも…  

やる事やったら読んでみよう!

#RaspberryPiPico #PIO

🌘 利用 RP2040 驅動 TFEL 顯示器:逐步卸載 CPU 負載
➤ 解構 RP2040 PIO 驅動 TFEL 顯示器的技術細節
https://www.zephray.me/post/rpi_pico_driving_el/
本文詳細介紹如何利用 Raspberry Pi RP2040 微控制器及其 PIO (可程式化 I/O) 功能,逐步實現驅動 640x480 像素的雙掃描單色 TFEL 顯示器,並有效將影像輸出任務從 CPU 核心卸載。作者首先說明瞭傳統透過 GPIO Bit-Bang 的方法會佔用大量 CPU 資源且影響時序精確度,隨後引入 PIO 的概念,並分階段展示如何利用 PIO 的自動推拉和側邊設定功能,建立兩個同步的狀態機來處理畫面資料的輸出,最終成功實現了流暢且無閃爍的畫面顯示。
+ 這篇文章對於如何善用 RP2040 的 PIO 進行低階硬體控制非常有啟發性。我之前一直煩惱著如何高效驅動高解析度顯示器,這提供了很好的思路。
+ 實作細節很紮實,尤其是關於兩個 PIO 狀態機
#嵌入式系統 #RP2040 #PIO #TFEL 顯示器 #嵌入式開發
Driving TFEL with RP2040: Offloading the CPU step by step — Wenting's Web Page

Разбираемся с композитным видеосигналом NTSC, и стоит ли изучать его в 2025 году. Часть 2

В предыдущей статье я рассказал об основах композитного видеосигнала NTSC. Эта статья должна быть интереснее, так как она посвящена программной генерации такого видеосигнала. Тема интересна тем, что помимо самого видеосигнала вы ещё получаете множество практических навыков применения современных микроконтроллеров. Сигнал CVBS можно получить, используя и FPGA-решения, но стоимость их выше, чем у микроконтроллеров, таких как Raspberry Pi Pico или ESP32. Я использовал платы разработчика на базе микроконтроллера RP2040. На рынке существует несколько таких плат. Классика — это Raspberry Pi Pico, но есть несколько китайских аналогов, например, YD-2040. Отдельно хочется выделить RP2040 Zero от Waveshare — очень компактное решение, правда у него отсутствует порт для отладки, но можно обойтись и без порта. Важный момент — СVBS-сигнал является аналоговый, поэтому стабильность напряжение на выходе играет важную роль и для приемлемого качества сигнала китайские клоны Raspberry Pi Pico могут не подойти, так как они страдают нестабильным напряжением на выходах. Мой совет — используйте или оригинальный Raspberry Pi Pico или RP2040 Zero от Waveshare. Желающих продолжить чтение приглашаю под кат.

https://habr.com/ru/companies/ruvds/articles/961086/?utm_source=habrahabr&utm_medium=rss&utm_campaign=961086

#ntsc #raspberrypi #raspberry_pi_pico #cvbs #композитный_видеосигнал #r2r_dac #DMA #PIO #прерывания #ruvds_статьи

Разбираемся с композитным видеосигналом NTSC, и стоит ли изучать его в 2025 году. Часть 2

В предыдущей статье я рассказал об основах композитного видеосигнала NTSC. Эта статья должна быть интереснее, так как она посвящена программной генерации такого видеосигнала. Тема интересна тем, что...

Хабр

Разбираемся с композитным видеосигналом NTSC, и стоит ли изучать его в 2025 году. Часть 2

В предыдущей статье я рассказал об основах композитного видеосигнала NTSC. Эта статья должна быть интереснее, так как она посвящена программной генерации такого видеосигнала. Тема интересна тем, что помимо самого видеосигнала вы ещё получаете множество практических навыков применения современных микроконтроллеров. Сигнал CVBS можно получить, используя и FPGA-решения, но стоимость их выше, чем у микроконтроллеров, таких как Raspberry Pi Pico или ESP32. Я использовал платы разработчика на базе микроконтроллера RP2040. На рынке существует несколько таких плат. Классика — это Raspberry Pi Pico, но есть несколько китайских аналогов, например, YD-2040. Отдельно хочется выделить RP2040 Zero от Waveshare — очень компактное решение, правда у него отсутствует порт для отладки, но можно обойтись и без порта. Важный момент — СVBS-сигнал является аналоговый, поэтому стабильность напряжение на выходе играет важную роль и для приемлемого качества сигнала китайские клоны Raspberry Pi Pico могут не подойти, так как они страдают нестабильным напряжением на выходах. Мой совет — используйте или оригинальный Raspberry Pi Pico или RP2040 Zero от Waveshare. Желающих продолжить чтение приглашаю под кат.

https://habr.com/ru/companies/ruvds/articles/961086/

#ntsc #raspberrypi #raspberry_pi_pico #cvbs #композитный_видеосигнал #r2r_dac #DMA #PIO #прерывания #ruvds_статьи

Разбираемся с композитным видеосигналом NTSC, и стоит ли изучать его в 2025 году. Часть 2

В предыдущей статье я рассказал об основах композитного видеосигнала NTSC. Эта статья должна быть интереснее, так как она посвящена программной генерации такого видеосигнала. Тема интересна тем, что...

Хабр
🌘 Raspberry Pi RP2040 或 RP2350 軟體模擬實現 100 Mbit/s 乙太網路
➤ 微控制器效能極限的突破:用軟體模擬實現高速乙太網路
https://www.elektormagazine.com/news/rp2350-bit-bangs-100-mbit-ethernet
開發者 Steve Markgraf 運用 Raspberry Pi Pico 上的 RP2040 (或更新的 RP2350) 微控制器,僅透過軟體和可程式化 I/O (PIO) 成功實現了 100 Mbit/s 的高速乙太網路傳輸。此專案繼先前軟體模擬 USB 之後,展現了 PIO 的強大潛力,能夠處理 MLT-3 編碼、4B5B 線路編碼及擾碼等複雜任務,並能達到每秒約 11 MB 的 UDP 串流傳輸量,可應用於低成本的高速資料擷取與串流情境。
+ 太令人驚訝了!竟然能用 RP2040 跑出 100M 的乙太網路,這對小型專案來說開啟了許多可能性。
+ 這真是個了不起的成
#嵌入式程式設計 #Raspberry Pi #RP2040 #RP2350 #乙太網路 #PIO
Raspberry Pi RP2040 or RP2350 Bit-Bangs 100 Mbit/s Ethernet

Engineer Steve Markgraf Raspberry Pi RP2040 or RP2350 Bit-Bangs 100 Mbit/s Ethernet after kingyoPiyo pulled 10 Mbit off three years ago.

Elektor

Arduino and SP0256A-AL2 – Part 3

Following on from using an Arduino as a variable clock in Arduino and SP0256A-AL2 – Part 2, I have some ideas for a few options, but this post looks in detail at using a Raspberry Pi Pico as the clock source.

Spoilers: it kind of works, but isn’t quite the answer I need yet…

  • Part 1 – Basic introduction and getting started
  • Part 2 – Arduino programmable clock
  • Part 3 – Using a Raspberry Pi Pico as a programmable clock
  • Part 4 – Using a HC4046 PLL as the clock
  • Part 5 – Using an I2C SI5351 programmable clock
  • Part 6 – Adding MIDI

https://makertube.net/w/bxBYCqHrZvQLwLuwYa5Z9r

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

If you are new to microcontrollers, see the Getting Started pages.

Using a RPi Pico

The RP2040 can be overclocked quite a bit, so generating a variable square wave up in the few MHz range should presumably be relatively straight forward. Using the built-in PIO state machines for a square wave is fairly simple and it can be done from Circuitpython or Micropython too.

This is a complete square wave generator for GP2 that steps down from 4MHz to 2MHz in steps of 100kHz. It can optionally overclock the RPi to 250 MHz too if required.

import time
import microcontroller
import board
import rp2pio
import adafruit_pioasm

square = adafruit_pioasm.assemble ("""
.program square
set pins, 1
set pins, 0
""")

RP2040Freq = 125_000_000
#RP2040Freq = 250_000_000

print ("RP2040 Frequency = ", microcontroller.cpu.frequency)
microcontroller.cpu.frequency = RP2040Freq
time.sleep(1)
print ("New RP2040 Frequency = ", microcontroller.cpu.frequency)

while True:
for freq in range (4000000, 2000000, -100000):
print("\nReqd frequency = ", freq*2)
print("Sq frequency = ", freq)

sm = rp2pio.StateMachine(
square,
frequency=freq*2,
first_set_pin=board.GP2,
)
print("Actual freq = {:d}".format(sm.frequency))
print("Actual sq freq = {:d}".format(int(sm.frequency/2)))

time.sleep(5)
sm.deinit()

The PIO program itself has two instruction steps, so takes two cycles to complete, so the running frequency has to be twice the desired frequency of the square wave. It automatically keeps looping, so no additional instructions are required there.

The state machine will run at the system speed with a 16.8 fixed point fractional clock divider. Full details can be found in section 3.5.5 “Clock Dividers” in the RP2040 datasheet.

For certain values there might be some jitter:

If the system clock is faster though, the amount of jitter will be less I suspect, so it is advantageous to overclock the Pico for more accurate frequencies.

The problem with this approach is that whilst I get a nice accurate clock source with quite a good resolution across its range, every time the state machine is recreated to change the frequency, there is a “blip” in the audio from the SP0256A-AL2 whilst its clock temporarily disappears!

An alternative approach is to use a fixed state machine frequency but include a counter in the PIO program to allow for a configurable number of steps per scan of the PIO without having to stop and restart the clock.

The problem with this is that I am limited to a unit of the instruction time for the PIO state machine which gives a fixed overhead, in terms of the instructions required for a minimal loop, and a flexible overhead, in terms of the counter I can pass in.

The upshot of this is that I’m tied to a certain resolution of frequency change.

I have the following PIO code:

.program blink
.side_set 1
.wrap_target
pull noblock
mov x, osr
mov y, x
set pins, 1
lp1:
jmp y-- lp1
nop
nop
mov y, x
set pins, 0
lp2:
jmp y-- lp2
.wrap

The “pull” will update the output shift register (OSR) either with any new value written to the state machine or the last value of the X register. This value gets copied to Y to use as a counter. This happens twice, once for when the pin is set at 1 and once for when the pin is set at 0.

There are two nops whilst the pin is set at 1 to balance for the original pull and mov instructions at the end of the pin set to 0 cycle.

As the Y counter value is used twice, the flexible overhead of the timing is essentially proportional to count * 2. It counts for the pin being HIGH and then for the pin being LOW.

The fixed overhead is the cost of the original pull, two moves, the pin sets, and a single jmp per pin state – so by using the two nops to ensure the HIGH and LOW times are the same, that is 10 instruction cycles.

I was hoping to use the “side” instruction to eliminate the two set instructions, but so far I’ve not managed to get that to work. I still don’t understand PIO…

So for now the timing of the PIO routine is = 10 + 2 * count and the unit is the time for a single instruction, which is 1 / frequency of the PIO execution, up to a maximum frequency of the Pico’s system clock frequency.

Using an overclocked Pico at 250MHz, the frequency range would start at the following:

  • Execution freq = Pico Sys Clock / (10 + 2 * count)
  • So when count = 0; execution freq = 250MHZ / 10 = 25 MHz

That is far too fast for the SP0256A-AL5. In fact, I’ve found that anything over around 5MHz causes the chip problems.

For this reason, I’m using a minimum count of 20:

  • Max execution freq = 250MHz / (10 + 2 * 20) = 5 MHz

Plotting execution frequency per “count” value (starting from 20) gives the following:

We can see the limits of the resolution at the top-end, and in fact, the first few equivalent frequencies in that range are as follows:

CountEquivalent Frequency205,000,000214,807,692224,629,629234,464,285244,310,344

That is giving me something like a 150-200kHz jump each time, which isn’t great, but is probably the best I can do. I would be larger if I wasn’t overclocking the Pico. It does get smaller as the count increases, but it is only really worth going down to a count value of around 120, which is around 1MHz for the resulting clock. Anything lower than that and the SP0256A-AL2 isn’t particularly useful.

Here is the full Circuitpython code which attaches a pot to GP26 to control the frequency in the range of around 900kHz up to 5MHz. Note the scaling of the pot value (0 to 65535) by 600 prior to its use to add to the count.

import array
import time
import board
import rp2pio
import microcontroller
import adafruit_pioasm

from analogio import AnalogIn
algin = AnalogIn(board.GP26) # ADC0

blink = adafruit_pioasm.assemble(
"""
.program blink
.side_set 1
.wrap_target
pull noblock
mov x, osr
mov y, x
set pins, 1
lp1:
jmp y-- lp1
nop
nop
mov y, x
set pins, 0
lp2:
jmp y-- lp2
.wrap

"""
)

RP2040Freq = 250_000_000

microcontroller.cpu.frequency = RP2040Freq
time.sleep(1)

oldalgval = 0

sm = rp2pio.StateMachine(
blink,
frequency=RP2040Freq,
first_set_pin=board.GP2
)
sm.write(bytes(16))

while True:
algval = algin.value
if (algval != oldalgval):
oldalgval = algval
count = 20 + int(algval / 600)
freq = int (RP2040Freq / (10 + count*2))
data = array.array("I", [count])
sm.write(data)

time.sleep(0.2)

One problem will be the 3V3 operating levels of the Pico. The SP0256A-AL2 datasheet states the following:

So whilst a “high logic” value for the oscillator has a minimum level of 2.5V, it also states that a minimum of 3.9V is required if driven from an external source.

If required, something like a 74HCT14, powered by 5V, can be used to level shift the 3V3 output of the Pico to a 5V signal for use with the SP0256A-AL2.

But in practice, I was finding the Pico worked fine as is. It is important to ensure both the Pico, Arduino and SP0256A-AL2 all have their grounds connected.

A this point I’m just using the Pico as a programmable clock, but if I was to go this route, then it would make sense to have the Pico drive the SP0256A-AL2 too and forgo the Arduino.

Closing Thoughts

So I have two choices if I want to use a Raspberry Pi Pico:

  • Go for smooth changes of frequency, but with less resolution, especially at the higher frequencies.
  • Go for more accurate resolution across the range but accept there will be blips when the clock changes which will be heard in the audio.

Neither is a perfect solution, but it shows the principles are valid. Also, using two microcontrollers is a bit over the top, so if I was to move to using a Pico, I’d probably want to find a way to drive the SP0256A from the Pico directly too and skip using an Arduino.

One benefit of that would be that I can time the frequency changes to coincide with silence in the speaking should I wish to, avoiding the possibility of major audio blips.

But I also have a few other options to try, which I’ll come back to in a future post.

Kevin

#arduinoUno #pio #raspberryPiPico #sp0256aAl2