Raspberry Pi Pico PIO - Ep. 14 - Arbitrary Waveform Generator

Ғылым және технология

Join David as he uses the Raspberry Pi Pico (RP2040) as an Arbitrary Waveform Generator. This episode includes Direct Memory Access, Programmable Input Output, and the theory and building of a Digital to Analog converter.
Link to program files for this Episode:
github.com/LifeWithDavid/Rasp...
00:00 Introduction
00:35 Function Generator History
01:20 Using a Raspberry Pi Pico as an AWG
02:28 Digital to Analog Convertor Theory
04:04 Building the DAC
04:48 The Amplifier
05:17 Proof of Concept MicroPython Program
05:37 DMA Theory
06:25 AWG C program details
11:10 AWG PIO program details
12:33 Testing the AWG
13:38 AWG Frequency Accuracy
13:55 Closing
Music:
(Pinnacle 25 royalty-free music):
Pulsing Dance
House Fever
Reaction Time
City Night Groove

Пікірлер: 72

  • @zhitailiu3876
    @zhitailiu3876 Жыл бұрын

    This channel is really "out-of-the-ordinary", thank you for sharing all these with the world!

  • @LifewithDavid1

    @LifewithDavid1

    Жыл бұрын

    Glad you enjoy it! Thanks for watching!

  • @Ololoshize
    @Ololoshize Жыл бұрын

    Cool, thanks for this video.

  • @LifewithDavid1

    @LifewithDavid1

    Жыл бұрын

    No problem! Thanks for watching!

  • @TheDarkelvenangel
    @TheDarkelvenangel2 жыл бұрын

    Thank you for showing this project I would be interested in seeing an improved version. It's great seeing how all the pieces come together.

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    You're welcome. Thanks for the input. I'll see if I can put together something that will be useful. It all depends on getting high speed amplification (+25mHz). That will take a little bit of research. Until recently, I've been a low speed digital/audio guy, the world of high speed analog (i.e. radio) is new to me too.

  • @boriskotov717
    @boriskotov717 Жыл бұрын

    Such a good and well documented work! Even for a microcontroller & c beginner its understandable (of course with pausing, repeating and looking into the repo). Thank you for making it public, sir!

  • @LifewithDavid1

    @LifewithDavid1

    Жыл бұрын

    Glad you enjoyed it! Thanks for watching!

  • @boriskotov717

    @boriskotov717

    Жыл бұрын

    @@LifewithDavid1 I did web development for over 10y now. And I was a bit scared of C/C++. Now I am writing pure C with the power of this little beast :D Keep doing, I bet it helps a lot of other people as well 👍

  • @sebastianhabiger8379
    @sebastianhabiger83792 жыл бұрын

    You are awesome! Thank you. Breaking down the informations to the minimum needed to understand the basics is above reach of other KZread Videos. This reminds me of the 80/90s computer area and the sharing of informations that time. Thanks!!!

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Glad it was helpful! As you may have guessed; I loved the homebrew computer community support during the 70's and 80's.

  • @ciiriin
    @ciiriin2 жыл бұрын

    Thank you. I really liked the video, because the way I treat the subject was very clear and novel for me.

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Glad you enjoyed it! Thanks for watching!

  • @miguelestrada2011
    @miguelestrada20112 жыл бұрын

    It is impressive how diverse the community is, i was just laying around in KZread and your video popped out. It is interesting that I just recently had this project in mind and starting to build up my own PCB design for a waveform generator by using rp2040, MDACs and High speed amplifiers, this video is super helpful due to the theory and the awesome explanation of the different peripheral functionality integrated with PIO. Definitively subscribed.

  • @LifewithDavid1

    @LifewithDavid1

    Жыл бұрын

    Thank you very much. I’m working toward a high speed version; but progress has been slowed because of my cataract surgery and all the other things going on because of summer. Maybe in a few months. Thanks for watching!

  • @dolandump
    @dolandump2 жыл бұрын

    Hello, your video series is fascinating.

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Glad you think so!

  • @PATRIK67KALLBACK
    @PATRIK67KALLBACK4 ай бұрын

    Nice tutorial!

  • @LifewithDavid1

    @LifewithDavid1

    4 ай бұрын

    Glad you think so! Thanks for watching!

  • @cthoadmin7458
    @cthoadmin7458 Жыл бұрын

    Ideas for you David: 1). Do the reverse, input waveforms, then display them via your method, basis of an oscilloscope. 2) Modulate the waveform with a baseband signal for an AM transmitter. Probably reaching the limits of what the Pico could do unassisted, but I'm blown away by the capability of DMA/PIO.

  • @LifewithDavid1

    @LifewithDavid1

    Жыл бұрын

    Those are great ideas. I'm working on a higher frequency AWG now. Thanks for watching!

  • @attilathehun5904
    @attilathehun5904 Жыл бұрын

    HI David. Thanks again for a wonderful video! The Pico project I'm sorta looking at is to make a simple software-defined radio out of an Si5351A board and a Pico. I'm thinking of using the Si5351A to generate generate quadrature LO signals and a couple of SA612 mixers to give me I & Q signals. I want to read I & Q into A/D converters on the Pico using DMA. I'm intrigued with the potential to make a very cheap SDR receiver that's somewhat out of the normal. In particular, I'm fascinated with having the crunching power of two cores that don't have to work significantly on data grabbing. And doing it in Micropython :-) although I can do it in C if necessary.

  • @LifewithDavid1

    @LifewithDavid1

    Жыл бұрын

    That's a neat project. MicroPython is not quite as capable as C when it comes to PIO interrupts or DMA. I had to go to C for my video and AWG projects because of that. Good luck and keep us informed of your progress!

  • @dazzer_
    @dazzer_2 жыл бұрын

    Great video. A video using the PIO with Sigma Delta, and a simple RC filter to play an audio file would be pretty interesting.

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    That would be interesting. I'll have to add that to my list of potential video ideas. Thanks!

  • @richardmarsden6541

    @richardmarsden6541

    2 жыл бұрын

    I was thinking about a small MIDI synthesizer project, so this would definitely interest me!

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    @@richardmarsden6541 Wow, that would be really cool!

  • @christianlennertz5780
    @christianlennertz57802 жыл бұрын

    Great tutorial, and, I have to admit, I would love to see how you would improve the signal generator. 👍

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Thank you! I'm going to take a look into it. It all depends on amplifier frequency response.

  • @manjitkumar6510
    @manjitkumar65102 жыл бұрын

    Thanks for nice and unparalleled coverage of rp2040 pio. Would appreciate if you could consider SPWM waveform generation using pio in some of your next episode. Thanks for your efforts and excellent coverage. PIO peripheral is already available on many other brand mcu but such a beautiful coverage on pio is unique on KZread. Thanks.

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Thanks for the suggestion. I plan to follow up my Arbitrary Waveform video with one with a higher frequency op amp with a slightly better user interface. This sounds like it would be well suited for SPWM.

  • @HighfireX
    @HighfireX2 жыл бұрын

    Thank you for continuing the exploration of the capabilities of the Raspberry Pico. Have you covered hardware interpolators for the raspberry pico?

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Thanks for watching! No, I haven't looked at hardware interpolation. I'm not sure what I could do to demonstrate it on a Pico. If you have any ideas; let me know!

  • @HighfireX

    @HighfireX

    2 жыл бұрын

    @@LifewithDavid1 I haven't seen examples yet but the datasheet says it can be used for audio dithering and textures. I do like the idea that it can do simple repetitive operations like right shift, masking and saving processor cycles.

  • @AdiGitalEU
    @AdiGitalEU2 жыл бұрын

    Fantastic project and the whole series you're making David! Helped me a lot. Until now all my projects were C++ based (Arduino, Teensy, ESP etc.). I picked the Pico for its rapid and easy prototyping with Python, which I was looking to finally get started with. Having to go through C++ chain and the separate io file and steps to achieve the coolness of PIO is a little off-putting. Definitely not "prototyping-friendly". I wish there was Python path for the same. While I'm fine with C++, for now I'll need to focus on the basics and mastering the Python. Nonetheless, I'll be coming back and keep my eye on your fantastic work. There are two important factors I really like about your videos. One, is going through the code and explaining what particular statements are responsible for. And the second is explaining the background of the topic, which like in this episode, not everyone might know what is and how an arbitrary generator works.

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Thank you for the kind comments. I like making videos, and my tendency to "over-explain" (my kids' term) helps with the background. As you may know, many of my early PIO videos used MicroPython. There is a lot you can do with MicroPython; although some things might be a little clunky. Thanks for watching!

  • @trumpeteerTralala
    @trumpeteerTralala2 жыл бұрын

    Thanks again David. Your videos and code examples are outstanding for anyone interested in learning RP2040 programming. Very appreciated! I followed your examples using parallel 5k SMD 1206 1/4W resistors in my DAC and the results are near perfect!

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Fantastic! Have fun and thanks for watching.

  • @dansam1395
    @dansam13952 жыл бұрын

    Super interesting video David. It would be great to know how far you can push this up. BTW, I read it is possible to overclock the 2040 up to 300Mhz without issues. Thanks for sharing, I am learning how to do PIO programming.

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Thanks. I've got the high speed op amps but I haven't put it together yet. Right now I'm thinking a pseudo sine wave of about 15 MHz ( 8 samples per wave cycle)

  • @bennguyen1313
    @bennguyen13132 жыл бұрын

    I'm always impressed with how much can be done with the PIO blocks! Do you know if the block exists in other Pi devices, like the Pi Zero (BCM2835)? For example, there's a Pi project using a GPIO to implement an RF transmitter! Another great Pico PIO example is the can2040, which achieves full 2.0b Can Bus Specs using only one of the PIO hardware blocks! BTW, I've been thinking of implementing the PIO functionality inside an FPGA/CPLD.. any suggestions?

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    I don't believe any other RasPi device has PIO. They do have specialized I/O for handling several different standardized protocols. I'm not sure, but the higher clock speeds for the Pi 2, 3, 4, and 0 should allow them to do bit banging and give the illusion that they have PIO. Looking at the history of the Pico, it was first implemented on FPGAs during development. I've not worked with FPGAs (I'm too cheap and the Pico gets me the FPGA functionality I want at a VERY reasonable price) but I don't see why you couldn't make it happen. Good luck!

  • @itzhakadir1730
    @itzhakadir17302 жыл бұрын

    Thank you for this very good demo. Do you think the pico can give output frequencies up to 10 Mhz, or we will need stronger hrdware?

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Thank for inspiring this video! I think I could get 10 MHz; but I need a high speed amplifier. I'll be investigating that in the future.

  • @Rudie_
    @Rudie_2 жыл бұрын

    Fantastic project. Thank you. May I suggest you use something like a BUF634 as an output buffer-amp.. And, would you make the code available?

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    That's a great idea. I didn't know about the BUF634, which looks like it would be easy to implement. However, I already bought some LM6171's and LM7171's to improve the frequency response; which I hope to do soon. Follow the link in the description for the code. Thanks for watching!

  • @juanpablojaramillo5390
    @juanpablojaramillo53902 жыл бұрын

    is it possible to read single colors from a hdmi signal with pico?

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    HDMI is just too fast for the Pico. Even the slowest HDMI (cat 1) operates at 75 MHz. The Pico operates at 125 MHz, which only allows 2 clock cycles to process each chunk of HDMI data. This is just not fast enough. Sorry.

  • @arunrajmbbs
    @arunrajmbbs2 жыл бұрын

    Sir, Can you make a video to interface ADC08100 to pio of raspberry pi pico and display the analog waveform on a pc ?

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    That's a really ambitious project! I'm not sure the Pico could handle that much data. It only has 256K of memory, which would only be enough for a few milliseconds of a signal at 20Msps. And that doesn't include any space for the program. The Pico does have a built in ADC which can (I think) sample one pin at 500Ksps. That might be a good place to start. Thanks for watching!

  • @slimhazard
    @slimhazard2 жыл бұрын

    Because of my electronics noobitude, I wouldn‘t have thought of using the op-amp, believing that the output of the DAC by itself would be enough. What is the output range of the DAC when it‘s powered by VUSB? How is it improved by the op-amp?

  • @slimhazard

    @slimhazard

    2 жыл бұрын

    Oh sorry, the inputs to the DAC are GPIOs, so they‘re high or low in the 3.3v range. It‘s the op-amp that‘s powered by VUSB. #noob So is the op-amp used in order to get output in the 5v range? If so, then you could do without the op-amp if you‘re okay with DAC output in the 3.3v range? #noob #questions

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    These are all good and important questions. If you go slow enough, and the downstream circuitry doesn't draw any load, then you can get by with no op-amp. However, to get any speed, or to provide any current, you need an amplifier to keep the current draw and capacitance on the resistor network as low as possible. This will also maintain the accuracy of the DAC because a higher downstream current draw on the resistor network will load the most significant bit (MSB) GPIO more than the LSB. This will cause a little voltage sag on the MSB GPIO, causing non-linearity. Because the op-amp is set up for unity gain, the output will be 0 to 3.3 volts (same as the input). Note that while the LM358 is capable of single supply operation, there will still be some non-linearity near 0 volts. If you were to set up the op-amp as an inverting amplifier with a split power supply, you could make an output that would be useful for all types of downstream circuits. Op-amps are awesome little devices, and there is a ton of information on how to use them "hidden" in their datasheets. Look through one, don't be discouraged if you don't understand all of it at first. The idea is to just familiarize you with where and what kind of information you can find. Good luck and have fun!

  • @slimhazard

    @slimhazard

    2 жыл бұрын

    @@LifewithDavid1 thanks! My mental model of an op-amp was that it‘s just for amplification, but obviously there‘s a lot more to it than that. I might have some LM358s in the “box of stuff to try out someday”, looks like it‘s time to do just that.

  • @AdiGitalEU

    @AdiGitalEU

    2 жыл бұрын

    @@slimhazard I definitely encourage you to do! For very long time op-amps were a mystery to me. Especially, when very early in my electronic journey I saw an analogue computer full of them. They can do all sorts of mathematical operations! I was thinking "how on earth?". Lately I finally got to use them and even do some designs. So awesome and relatively easy to work with. Just like Lego bricks.

  • @tinglin6121
    @tinglin61216 ай бұрын

    Wow, 100kHz just from the basic setup.

  • @LifewithDavid1

    @LifewithDavid1

    6 ай бұрын

    The RP2040 is really neat. As you may have seen from my later videos; I got much faster. Thanks for watching!

  • @aerispalm6523
    @aerispalm6523 Жыл бұрын

    thank you, this is exactly the information i was looking for! now i know what i wanna do is feasable! but please stop with the music fading in and out for like a second between lines, it's super irritating.

  • @LifewithDavid1

    @LifewithDavid1

    Жыл бұрын

    Glad it was helpful. Sorry the music was irritating; I'm not using the music as much. However, I still don't like dead air. Thanks for watching!

  • @jonathanstein6056
    @jonathanstein60562 жыл бұрын

    David, now that you are close to mastering the PIO on Pico, why not try your hand at the FlexIO on the Teensy 4 or 4.1? Nobody else has tackled this, so you’d probably attract a ton of new subscribers from the Teensy community.

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Thanks for the suggestion! As I learn more about the RP2040, I realize how much more there is to learn. I've not worked on the Teensy before; so I scanned the web for info. Version 4.1 looks like a very powerful controller. I'll look into it more; but I'm afraid it could be quite some time before I can put out content that would be worth people's time to watch.

  • @jonathanstein6056

    @jonathanstein6056

    2 жыл бұрын

    @@LifewithDavid1 You bet! Your PIO series is really a general master class on hardware concepts in modern systems - and in programming them. Way beyond merely the Pico. As for the Teensy, you're right. It's the most powerful microcontroller out there. And FlexIO is its PIO. Keep up the great work! PS I too work with 65xx ICs, so I really appreciate what you're doing.

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    @@jonathanstein6056 Thank you. I appreciate your kind words.

  • @ichemnutcracker
    @ichemnutcracker2 жыл бұрын

    Why did you define Pi as 3.142859264 instead of 3.141592653?

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    That's an "aw s#!+" I borrowed some code from another Raspberry Pi program and it had Pi defined improperly. My bad!

  • @shailu3003
    @shailu30032 жыл бұрын

    sir , for video you are using same shirt for last 3 years ?

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    You're right. That's my video making shirt! By always using the same shirt, I can maintain continuity if I have to re-record an opening or closing.

  • @simonbaxter8001

    @simonbaxter8001

    2 жыл бұрын

    You want to watch the KZread legend that is 'Colin Furze' ... I think he's had the same shirt since leaving school! 🤣 P.S. Great video's David 😎

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    @@simonbaxter8001 Thank you. It does get washed; so everything smells nice and fresh! LOL

  • @PaulGrayUK
    @PaulGrayUK2 жыл бұрын

    Pi is 3.1415926535 from memory, you have 3.1428592654. Is there a reason that I missed? So I tried the difference between 39Hz and what the pico gives from the clocks and got 3.1466272572013. I'll puzzle it out in the end before I call typo :).

  • @LifewithDavid1

    @LifewithDavid1

    2 жыл бұрын

    Go ahead and call typo. I remember that Pi is 3.14159. This came from a little chunk of code I got from another program. In fact I was going to change it; but it slipped my mind. Good catch! The difference in Pi will lead to a mis-shapened curve but not a difference in frequency. However a better value of pi will lead to a better curve. In reality; it probably doesn't make any difference at all since the resolution is only 1 in 256.

  • @PaulGrayUK

    @PaulGrayUK

    2 жыл бұрын

    @@LifewithDavid1 Given most uses of PI end up being multiplied by 2, there is merit in using Tau(2xPI) instead of PI. Looking at the code: awg_buff[i] = 128+(sin((factor)*2*PI)*127); //Loads the AWG Buffer table with values of the wave Though maybe the compiler is clever enough to optimise that out, though might need bracing the (2*PI) to nudge that, safer with Tau as any literal when the first thing you do is multiply it by two always bemused me.

Келесі