A Raspberry Pi Pico as a function generator for arbitrary waveforms - Page 1
Forum section: electronics / general

author: Batucada
author_rank: Contributor
timestamp: August 08, 2024, 10:03:27 pm
content: HelloI just wanted to hear another opinion. If you turn to special forums, you often get "special" opinions. Recently, it was about the possibility of building a function generator using a Raspberry Pi Pico. The person who came up with the idea was very proud to be able to connect an R2R network with a resolution of 22 bits to a Raspberry Pi Pico. This is already an immensely high resolution, which is technically not feasible with the clock rate of the Raspberry Pi Pico, as I found out later.The initial discussion was about how to deal with changes to the binary code when a particularly large number of bits have to be switched at the same time. In other words, in the case of a switchover where it is not ensured that all bits are operated at the same time, which is actually in the nature of things and you can no longer cope with the glitches. Another question was the influence of the supply voltage of the Raspberry Pi Pico on the noise immunity in the R2R network. The voltage of the Raspberry Pi Pico is processed in an internal buck-boost switching regulator RT6150B-33GQW. However, the specification of the switching regulator is politely silent. But I assume that a digital part like the Raspberry Pi Pico is not intended to implement high-quality analog technology with its GPIO, if the GPIO are configured as outputs, they only have to meet the specification for the levels of the binary signals. Maybe I'm wrong, but that would surprise me.I therefore suggested connecting the GPIOs to the inverting inputs of operational amplifiers. I would want to use the LT1356 type from Analog Devices as the operational amplifier, all of which are fine components with excellent properties. All this just to be able to separate the R2R network from the influences of the Raspberry Pi Pico. The operational amplifiers would then work as comparators, the non-inverting input is connected to ground, the outputs of the operational amplifiers would then drive the R2R network with a real dual power supply (±12V). Up to the evaluation of the R2R network output, there would be a good signal-to-noise ratio due to the high levels. This is at least 9 times better than connecting the R2R network directly to the Raspberry Pi Pico.This suggestion was countered by the suggestion that the operational amplifiers would significantly disturb the symmetry. In an LTspice simulation, no evidence of interference could be observed. I am now interested in whether similar projects have been realized in the large community of the EEV blog.

author: Sensorcat
author_rank: Regular Contributor
timestamp: August 08, 2024, 11:26:28 pm
content: It may be clear to you, but not to the reader what your actual design goal is. Without that, it is at least difficult to give advice.There are function generators you can buy, ICs which integrate much of the internals of such a generator, integrated DACs, and much more.So what are you trying to achieve? Building something because it's fun? Making a generator that meets certain needs? Save money compared to buying a generator?In any case, what you describe so far will not lead to a 22bit DAC.Regarding the simulation: Many important effects are not included in many SPICE models of semiconductors (ICs and discrete). For OpAmps, one of the most important omissions usually found is offset. So you can only find in a simulation what actually was put in the model, either by the manufacturer or by yourself.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: August 09, 2024, 06:05:46 am
content: Quote from: Batucada on August 08, 2024, 10:03:27 pmThat's a lot of words to say the pins are noisy in the analog domain !Quote from: Batucada on August 08, 2024, 10:03:27 pmThere is no brick wall preventing you using opamps as level shifters, but that's a lot of Opamps !If you cannot afford a proper external DAC, you can use an external CMOS buffer / level translator with clean supplies. (low noise, low drift regulators)You probably need to decide what matters more, speed or precision.A useful sanity check, is to look at what the big players can manage.eg you will find Analog Devices can offer 87-93dB of SFDR on their top-end High speed ( > 30MSPS) DACs or 18-20 bits max, in their slower DACs

author: Batucada
author_rank: Contributor
timestamp: August 09, 2024, 09:58:24 am
content: Quote from: PCB.Wiz on August 09, 2024, 06:05:46 amI would have to go into great detail to explain all aspects of my intention, so I'll keep it short. At the beginning there was a demand for a pulse generator. In the end, my discussion partner presented me with the beginnings of a design using a Bing-Bang machine (Raspberry Pi Pico) and an R2R network as a DAC. I haven't worked in electronics for many years, but I didn't lose my intuition enough to realize that an extremely stupid design had just been launched. I couldn't accept digital and analog technology on the same branch and argued that it would be better to use opamps than comparators to operate the R2R network. 22 bits is a huge number, I finally reduced it to 20 because 20 can be divided by 4. I suggested the LT1356 as an opamp because the chip has 4 opamps on board. With the excellent data of the chip, the Raspberry Pi Pico could not compete with the LT1356.And so I think my consideration was not the worst, but certainly the most expensive. Ok, up to this point it was just brainstorming, always bearing in mind that even a private hobby project costs a lot of money and it's not worth saving money at the wrong end right from the start. Personally, I would be prepared to pay the price for the LT1356 if the end result was a functioning concept.This is the preliminary idea of my concept:-- a dedicated isolated power supply for the Bing-Bang machine.-- Another isolated dual power supply for the opamps.-- The power supply of the Bing-Bang machine is set lower than the ground of the dual power supply by an adjustable value in the range of -1.65V. The intention behind this is to drive the opamps with a balanced signal so that the DAC signal can later be used to test tube amplifiers.-- The resolution will certainly not be 22 bits. That was merely the opinion of my discussion partner. The number 20 also seems too high to me; 16 or even 12 bits should be the target, because at 20 kHz the Raspberry Pi Pico is not able to deliver enough samples to the output to display a sine wave in acceptable quality. You do not need a micro-controller to display a square or triangular signal.

author: iMo
author_rank: Super Contributor
timestamp: August 09, 2024, 10:06:50 am
content: Quote from: Batucada on August 09, 2024, 09:58:24 amWhat is the Bing-Bang machine? Is that a typo? Do you mean Big-Bang machine or Bingo-Bang machine or Bit-Bang machine?

author: Batucada
author_rank: Contributor
timestamp: August 09, 2024, 10:38:36 am
content: Quote from: iMo on August 09, 2024, 10:06:50 amOh dear, that's one of humanity's biggest problems: understanding each other.Ok, I may have adopted a buzzword without understanding it. The issue is: What is the influence in a digital environment when an R2R network is connected to digital outputs that are intended for analog processing. This is not about the digital levels, which can only be binary in type (i.e. bing or bang), but about the influence of the supply voltage with which the digital machine is operated. In other words, how can noise, which is undoubtedly present, be prevented from seeping into the analog signal?The direct coupling of the GPIO with the resistors of the R2R network will undoubtedly lead to painful experiences. There is a suggestion to use CMOS components for coupling. Not bad either. My suggestion would be to use the LT1356. This is expensive, but would have a lot of advantages. If the only disadvantage is the cost, I would still want to use the LT1356. However, I don't see the typical disadvantage of an incalculable offset for opamps specifically with the LT1356. Are there other opinions that are justified? If so, then I would abandon my plan. And lokk for another.

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: August 09, 2024, 12:53:25 pm
content: Quote from: BatucadaWhy? What is the value of R? If you choose R=100ohm the behaviour of the R2R ladder will be quite different than if you choose 10kOhm or 100kOhm.You can also buiild a mixed DAC using oversamping and a resistor ladder configured with a non-binary base. A higher base than 2 leads to higher value resistors connected to the GPIOs, and fewer steps in the ladder. (7x oversamping, octal base for resistor DAC and just 8 GPIOs for 24 bits of resolution).

author: Batucada
author_rank: Contributor
timestamp: August 09, 2024, 01:30:26 pm
content: Quote from: Sacodepatatas on August 09, 2024, 12:53:25 pmThat should actually be clear, because I believe that Kirchhoff's rules have not changed since the many years of his researchBut the question is not what resistor values do I use in the R2R network? The question is rather, how do I avoid the influence of a noisy supply voltage, such as that certainly caused by the buck-boost switching regulator of the Raspberry Pi Pico? You will have no chance of counteracting this. You need to find a way to avoid introducing this noise into the analog signal processing branches. Do you have any idea?

author: peter-h
author_rank: Super Contributor
timestamp: August 09, 2024, 01:35:50 pm
content: I built a function generator (sinewave actually - posted various threads about it) on a 32F417, using a timer triggering a DAC which triggered a DMA to feed it, from a circular list in RAM.Doing arbitrary functions is easy.A DIY R/2R ladder will give you huge resolution but will be rubbish when the code switches on some of the larger bits. If say you want 12 bits you really need a proper 12 bit DAC. Otherwise you would need high grade analog switches and 0.01% resistors.

author: oPossum
author_rank: Super Contributor
timestamp: August 09, 2024, 02:04:03 pm
content: 74LVC574 fed from a lower noise power rail could be of some use. There will still be the problem of R2R having a practical limit of about 8 bits.For more than 8 bits a monolithic DAC will provide a much easier path to good performance.You haven't specified the desired frequency range or ENOB/THD so it is difficult to make a specific recommendation.Some parallel DACs:https://www.ti.com/data-converters/dac-circuit/precision/products.html#1918=Parallel&sort=1130;asc&

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: August 10, 2024, 03:20:36 am
content: Quote from: BatucadaI find this joke quite disrespectful. You have stated that you know little thing about digital GPIOs from an analogic point of view. Selecting the right values for R is mandatory. Too low and you will be overloading the outputs or even increasing the switching noise of the internal output drivers. Too high and the thermal noise of the resistors will ruin the DAC accuracy. But you say that the question isn't about resistor values. This statement is regarding to your question, not mine.Quote from: BatucadaWhy not? did you set the regulator into PWM mode? Did you make the inductor work in continuous operation? These things improve the output ripple but also increase current consumption, if Kirchhoff agrees with me, of course.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 10, 2024, 05:49:05 am
content: Resistors are quite affordable up to an accuracy of 0.1% these days, beyond that they become expensive very quickly, and I guess that puts the maximum practical resolution of an R2R network around 10 bits. 20 bits is probably never useful because of drift, temperature coefficient, aging, whatever.I bought a cheap chinese function generator some time ago, an JDS6600, (15MHz version). It has an R2R network for each of it's outputs and they are connected to an FPGA. But it's not just R2R. I guess that an (almost?) fixed number of bits are used for the signal generator, and the rest are used for an attenuator. I guess the attenuator switches some of the FPGA pins between "output" or "input" (open). In practice it is probably more complicated. The reason for opening it in the first place was to see if I could replace the resistors, because waveforms at lower amplitude setting are quite atrocious. The resistors are very small.0402, maybe 0201, and I'd first have to buy a bunch of them before attempting to do some soldering (and hand sorting) of those things. But this does mean that a part of the R2R network is also used for the attenuation.Using LT1356 as a driver for the R3R network sounds like a terrible idea. It has a few volts of headroom from it's power supplies and that makes the output unpredictable. It may for example drift like crazy with temperature. But you can of course always try. My first bet would be on some 8-bit TTL buffer / line driver. CMOS versions of TTL have a much more predicable resistive output, although they are not symmetrical between switching to power and GND. Dip versions can be stacked to put a bunch of the switches (outputs) in parallel and reduce output resistance further. The TTL Chip can also be powered from a separate / stable voltage reference. HCT works pretty good from upping the 3V3 uC voltage to 5V, maybe even upto 6V (some HC / HCT chips can go up to 6V5 or even 8V I think, but it would be manufacturer specific).Another option would be analog cmos switches. I guess the channel resistance is more predictable / symmetric then with TTL IC's, but channel resistance is probably also higher, unless you go tho the expensive ADG range of switches, which defeats the purpose of R2R in the first place.SOT-23 based FET's are cheap and can have a low Rdson (10mOhm or so), and you can hand match Rdson. Using them for R2R drivers could also be an option, but you would have to think carefully about dead time. The amount of hardware required probably also defeats the purpose of a cheap R2R.

author: Batucada
author_rank: Contributor
timestamp: August 10, 2024, 11:20:59 am
content: Quote from: Sacodepatatas on August 10, 2024, 03:20:36 amUnfortunately, this discussion is now branching off in a direction that was not intended. But well, as a reminder, my original question: "What is the influence in a digital environment when an R2R network is connected to digital outputs that are intended for analog processing." So the question was not focused on the performance of a digital output, but rather on the digital environment that is inevitable when connecting the R2R network directly to the digital outputs of the Raspberry Pi Pico.In addition to the fact that you are not happy about my satirical interjection, but continue to pursue your train of thought, you prove it with the following statement:Quote from: Sacodepatatas on August 10, 2024, 03:20:36 amI would never consider setting the individual resistors of the R2R network too low, if only to counteract the temperature response due to self-heating.Quote from: Sacodepatatas on August 10, 2024, 03:20:36 amIf you are sure that the GPIO of the Raspberry Pi Pico can produce switching noise and you do not want this noise to interfere with the analog signal, then the principle should now be to never connect a Raspberry Pi Pico to a R2R network. From this point of view, I am certainly right when I say: The direct coupling of the GPIO with the resistors of the R2R network will undoubtedly lead to painful experiences.Quote from: Sacodepatatas on August 10, 2024, 03:20:36 amAre you sure you are not confusing something? A sufficiently large resistor can never be subjected to thermal stress. Or did you mean if the current through the resistor and the GPIO becomes too large? But I don't think so, you have already described the consequences of too little resistance above.Quote from: Sacodepatatas on August 10, 2024, 03:20:36 amI will never agree to do analog signal processing near a PWM generator, especially if the resolution of the R2R network is to go to extremes and thus the ripple or noise of the PWM generator exceeds the step size of the R2R network.You could have raised your objections in your previous post, in which case I would certainly not have mentioned Kirchhoff.

author: Neganur
author_rank: Unknown
timestamp: August 10, 2024, 11:43:04 am
content: even though the name is thermal noise, it does actually also depend on resistance.Person was not talking about the resistor getting stressed by heat.https://en.m.wikipedia.org/wiki/Johnson%E2%80%93Nyquist_noise

author: Batucada
author_rank: Contributor
timestamp: August 10, 2024, 02:11:04 pm
content: Quote from: Doctorandus_P on August 10, 2024, 05:49:05 amThe original idea of my counterpart was even to push the resolution to 22 bits. He proudly presented his idea to me, saying that he had thus extracted the maximum technically possible resolution from the Raspberry Pi Pico. I tried to find out what the commercial competition is trying to achieve. Rigol advertises a resolution of 14 bits. However, the resolution is not so important to me at the moment. I'm much more interested in how to get there. The 20 bits I mentioned are just a house number, which I arbitrarily changed from 22 to 20 bits when I was still following the path of using these quad opamps from Analog Devices.With a simple estimation of the delivery possibilities, I would still be prepared to pay the price that would have to be paid for a tolerance of 0.01% at 10 ppm/K, if in the end, in conjunction with all other influences, this could be expected. The cost of a stable R2R network is probably the least of it.Quote from: Doctorandus_P on August 10, 2024, 05:49:05 amIf the Chinese are already using FPGA, then this could mean that recurring tasks have been outsourced from the processor in order to relieve it. I have tried to carefully estimate what a Raspberry Pi Pico could achieve if it could load a bit pattern into the output register with every 9th processor clock, then the samples could be supplied with a phase angle increment of 0.5°. However, this is only necessary if the amplitude is in the upper third of the maximum. In this range, a higher R2R resolution might also be desirable because the amplitude changes only minimally with the phase angle.Since the Chinese have focused their main attention on making good money, one should not expect the reproduction of a sine curve to give a good picture over the entire frequency range. And at 0402 or even 0201, that's where the fun stops for me.Quote from: Doctorandus_P on August 10, 2024, 05:49:05 amThat's exactly what I want to hear. That's finally an idea worth pursuing. I'm not a specialist in opamps. My knowledge goes back too far for me to remember everything. I chose the LT1356 because it has good values in terms of Input Voltage Noise Density. It should also outshine the Raspberry Pi Pico in terms of output slew rate. As far as the input offset of the LT1356 is concerned, I wouldn't have any concerns there either. However, I had not yet considered the temperature response of the output. The idea of using a CMOS line driver also has no disadvantages in terms of symmetry, which can be solved technically with little effort.As a first approximation, I have now set my sights on the 74HCT244 from Texas Instruments. The tip to use the PDIP package makes the proposal a lot more elegant. I would not want to evaluate whether something could be improved by using FETs, as it would easily drift into overestimation. A possible change in the output resistance of the 74HCT244 would be seen as a series resistance to a connection resistance (100 kOhm) of the R2R network, an assumed change of 30 Ohm would then be 300 ppm.Thank you very much for taking the trouble to share your thoughts with me.

author: Batucada
author_rank: Contributor
timestamp: August 10, 2024, 02:36:01 pm
content: Quote from: Neganur on August 10, 2024, 11:43:04 amI was not aware of this effect. The Johnson-Nyquist noise is directly proportional to the absolute temperature of the conductor. However, this also means that the noise that is present at 20°C does not double when the device temperature rises to 40°C. And according to the work of these honorable gentlemen who have researched this topic, when considering an R2R network, it is not necessary to select special resistors that do not exist anyway. The impression given by Sacodepatatas that this noise can be minimized or even eliminated by selecting an appropriate resistor value does not correspond to the physical conditions - so his argument is completely misleading in relation to this discussion.

author: iMo
author_rank: Super Contributor
timestamp: August 10, 2024, 02:41:09 pm
content: Quote from: Batucada on August 10, 2024, 11:20:59 am"What is the influence in a digital environment when an R2R network is connected to digital outputs that are intended for analog processing."When you want to use R2R network for a DAC wired to the Pico you will get noise and EMI based on the Pico's power source, Pico's timings jitter, and based on the wiring (grounding loops, decoupling, shielding, etc.).Moreover, as the digital outputs of all the MCUs are generators of almost a continual frequency spectra from 0Hz to xGHz (even when output pins are kept at log0 or log1), you might see those spurious at the DAC's output as well.There are professional products using that R2R wired to MCUs or FPGAs (ie the ICOM radios for generating VFO and BFO frequencies, with up to 10 bits, they did decades ago with good results). It requires to introduce the counter measures, such all the above mess will be mitigated.Messing with something higher than 10bit sounds to me as an unrealistic assumption, however.. Anyhow, the Pico shall get a linear supply, and the main clock has to be taken off an external oscillator (with low noise/jitter). And of course, you have to take into account all written above..PS: you should show us the schematics or a prototype with some measurements - otherwise people here cannot help you much..

author: Batucada
author_rank: Contributor
timestamp: August 10, 2024, 02:42:56 pm
content: Quote from: oPossum on August 09, 2024, 02:04:03 pmI would be very interested if you could tell me more about why there should be this "practical" limit of 8 bits for an R2R network

author: oPossum
author_rank: Super Contributor
timestamp: August 10, 2024, 03:02:24 pm
content: A monolithic DAC will be less expensive than a discrete R2R DAC somewhere in the range of 8 to 10 bits. The price of precision resistors, precision switches, and possible trimming goes up significantly above 8 bits.It is certainly possible to build 12+ bit discrete R2R, but as a practical matter it just isn't worth the effort. There are some audio discrete R2R DACs with 16+ bits. They are expensive and typically do not measure well. A monolithic audio DAC can achieve 21 ENOB in a finished product.74LVC and 74AC have somewhat better output characteristics than 74HC for DAC use.74x541 octal buffer74x574 octal latchTable with output drive (higher current is generally better):https://en.wikipedia.org/wiki/7400-series_integrated_circuits#Families

author: Batucada
author_rank: Contributor
timestamp: August 10, 2024, 03:03:33 pm
content: Quote from: iMo on August 10, 2024, 02:41:09 pmI can see that you have fully understood the meaning of my question. Your answer touches on exactly the issues I wanted to highlight.The Pico has a buck-boost switching regulator on board, which is already giving me a stomach ache. Bypassing this voltage supply with an external linear regulator would be feasible, but involves some risks. This is also the reason for using the Pico exclusively for indirect control of the R2R network.I would like to thank you and this forum in particular, which has often helped me to get the right perspective in the past.The discussion is still very theoretical at the moment and my approach is deterministic. I think when the matter has developed a little further, there will also be circuit diagrams.

author: iMo
author_rank: Super Contributor
timestamp: August 10, 2024, 03:38:03 pm
content: It depends on the construction as well. With a solderless breadboard and through hole resistors you get different results than with properly designed 4 layer pcb and 0402 resistors (ie the capacitancies and inductancies may play a role with higher frequencies). Also the outputs of the Pico may not have all the same voltage swing or the same output characteristics. Then you would need a low pass at the DAC's output to get rid of spurious frequency components, you would need a power broadband amplifier to drive a, say, 50ohm load, etc., etc.So it depends on many factors.You have to define your requirements like this, for example:1. I want Pico, output via PIO state machine (it can toggle at PIO's clock/2 afaik, not sure how it works with an arbitrary data stream via its FIFOs)2. Minimal output signal period 40ns (that means max 25MHz with 50% duty square signal)3. Resolution 12bit, max INL 3LSB, signal to noise min 60dB4. DAC output: bipolar 10Vpp, unipolar 0..5Vp, into 50ohm5. PCB 4 layers, 10x10cm max6. price $10..Or something like that

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 10, 2024, 04:20:16 pm
content: If you want to get 20 bits out of an R2R, then you need a resistor accuracy of around (1/2^20), which is 1ppm. Such resistors are prohibitively expensive. With 0.01% resistors, you get 1 part out of 10.000, which is roughly equivalent to 13.4 bits.And it is also not just the resistors, you need to consider the whole system. That includes the output drivers for the R2R network (output resistance of FET's in TTL IC's is certainly not matched, and thwarts benefits for more accurate resistors.What good is a 10k 0.1% resistor if you put it in series with a FET with an RdsOn which can vary between 20 and 80 Ohms? FET channel resistance also changes a lot with temperature and other factors. And on top of all that comes the cost of a voltage reference with suitable specifications.

author: radiolistener
author_rank: Super Contributor
timestamp: August 11, 2024, 10:32:33 am
content: Quote from: Batucada on August 08, 2024, 10:03:27 pmI think the noise due to the DAC clock jitter (since you're using microcontroller to clock the DAC) will be much more serious issue than noise from power supply...Quote from: Doctorandus_P on August 10, 2024, 04:20:16 pmI think this is useless, because practical limit for discrete R2R DAC is about 6-8 bit ENOB, if you want better, you're need to use DAC chip

author: Batucada
author_rank: Contributor
timestamp: August 11, 2024, 11:02:12 am
content: Quote from: radiolistener on August 11, 2024, 10:32:33 amMany thanks for the comment. The impression that it seems useless to try to build an R2R network above 6 to 8 bits is also starting to grow on me, everyone seems to recognize this as a limit of feasibility. Doctorandus_P was finally able to give a plausible explanation that I can understand. But can you also explain to me why this is the case from your point of view? Do you perhaps have another explanation?

author: radiolistener
author_rank: Super Contributor
timestamp: August 11, 2024, 10:48:24 pm
content: Quote from: Batucada on August 11, 2024, 11:02:12 amThe main limitation for discrete R2R DAC is phase error between bits and resistors tolerance. If you build discrete R2R, the PCB design and available resistor tolerances limits practical performance of that DAC. Even if you use very precise resistors and laser trimming for precise tuning, you still don't have good control on phase error, because even a small solder volume variation and limit of PCB wires precision affects electrical length of wires. You can't improve it for a usual PCB, this is why using DAC chip allows to get much better results. The internal chip traces have much better precision and it can be precisely trimmed with laser on the factory, so you don't need to take care about it.At higher sample rate phase error become much more critical.Here is example of a typical discrete 8-bit R2R DAC ENOB vs sample rate:With precise smd component and good PCB you can get better, but still much limited in comparison with factory manufactured DAC chip.

author: iMo
author_rank: Super Contributor
timestamp: August 12, 2024, 09:52:06 am
content: The limitation with an R2R DAC (provided you have got ideal switches and Vref) is mostly with the parameters of the resistors (their precision, TC, noise) and the overall design (the parasitic L and C) when talking high speeds.In addition you get the differences with the switches (ie. the output characteristics of each Pico output - like their load char, voltage at log1/log0, leakages, switching transients and the noise at the pins coming off the mcu) and the stability of the Vref (its TC, its load characteristics as the Vref's output current may change with set outputs combination).The monolithic DACs might be much better as the manufacturers usually understand all those nuances well and they strive to make it as best as they can..