The Sine Lab: Part 2

This video is the second part to a series about building a function generator. If you haven’t seen the first part, I recommend that you do that first so that you know why the design we have currently is the way that it is. It is linked in the description. The first part covers using a microcontroller and a DAC to generate an output waveform. In this video, we will make the waveform centered around zero volts and allow the user to alter the amplitude. Anyways, let’s get the video started.

Let’s start with generating a negative voltage to make our bipolar supply. There are several ways to do so, but to keep things simple I will divide the supply voltage in half. Let’s say that the input voltage is this 24 volt DC adapter. If we want to turn our 24 volts into +- 12 volts, then we need to find a way to get a voltage that is in the middle. If you don’t know what I mean, let me explain it. Voltage is simply a difference in potential in two points, meaning that it is relative. Take, for example, if you use your multimeter to measure a 9v source, but switch the leads, you will get a negative voltage. The same concept applies to our case, if we have three different voltage points, 0v, 12v, and 24v, you can rearranage the point of reference. Instead of saying that the bottom here is 0 volts, we can say that the middle is 0 volts. That means that the bottom is -12 volts, the middle is ground, and the top is 12 volts. This new ground that we just created can be called a virtual ground. Just remember this, voltage is relative. Anyways, we just need a way to generate that 12 volts from 24 volts.

The simplest way, which some of you might have already come up with is a simple voltage divider. And yes, this technically works, but a problem arises when we place a load onto the circuit because ohm’s law is modified. So, to keep the voltage stable, we can use an output buffer. We can make such a buffer by using an op-amp and a transistor. Remember that op-amps will try to keep their inputs equal, so the op-amp will drive the transistor to match the voltage of the resistor divider. If you want to learn more about how this op-amp circuit works, feel free to check out my previous video on op-amps. So, I used a LM358 OP-AMP and a 2n3904 NPN transistor and put them on the breadboard according to our schematic. That means that we can generate a stable 12 volt output, thus completing our bipolar supply. One improvement that can be made is replacing the resistor divider with a TLE2426, which I will be doing. Don’t worry if you don’t have one, this IC is basically a precision voltage divider that makes it easier to get exactly half of the input voltage. If you don’t have it or don’t want it, just use the voltage divider that we just discussed.

One more power supply consideration to make, we need a five volt source for the microcontroller. Since it doesn’t use much current, I simply used an LM317 linear regulator. I have a million of them anyway. If you are confused and want to learn more about the LM317, you can check out my previous video which goes into depth on how it works and how you can use it yourself.

Now that we have our +- 12 volt supply, we can work on translating the 0 to 4 volt DC signal from the DAC to a -2 to 2 volt AC signal. For that, we can use a differential op-amp to subtract 2 volts from the DAC signal. We can simply use the second op-amp inside of the LM358 for this purpose. A quick rundown of differential op-amps is that they return the difference between the two inputs. So, if we constantly set the non-inverting input to 2 volts, the output will compare that to the inverting input. That means that if the inverting input is four volts, then the difference is two volts, which makes our peak. When the input is zero volts, the difference is -2 volts, which is our negative peak. So, in other words, we simply offset the waveform by -2 volts to center it around ground. We can create this 2 volt reference by just simply using a potentiometer as a voltage divider. Just adjust it to be centered around 0 volts. Anyways, by using this op-amp and making the differential configuration, we now have an AC signal. Again, if you want to learn more about the differential configuration or just op-amps in general, visit my previous video about op-amps.

Just one more thing involving analog for this project. We need to be able to alter the amplitude of the generated function, because 4 volts peak to peak isn’t always enough. For that we can use a PGA, otherwise known as a programmable gain amplifier. Since I don’t have any dedicated IC’s currently, we can make one ourselves. To understand how we can make one, let’s first consider a typical non-inverting amplifier. To increase the gain, we can change the bottom resistor. While this is great, how can we digitally control this. Well, that’s where we can add switches. Basically, we can select from a variety of switches to select the bottom resistor. There are a few ways to do this, but we will simply be using transistors as our switches. This means that the microcontroller can select 2v, 5v, and 11v peak outputs depending on what the user specifies. More advanced designs can use even more switches to get even more options, but this project already has a lot of parts to solder.

I also added a couple more inputs. A potentiometer will determine the frequency of the waveform. The potentiometer simply is read by the ADC in free-running mode and pressing the button will save the current ADC value into the current waveform frequency. I also added a button which will rotate through the three PGA options that we discussed earlier.

I then took a look at the LCD that I plan to use, and realized that the LCD is probably better in a smaller size, so I switched to this smaller LCD. I rewrote a bit of the code to fit the new LCD size and make it so that the user can select which value that they want to monitor. With that being said, the code is finally complete for this project and only the hardware remains.

For this project, I decided to make a PCB. I had already made a schematic while working on the breadboard version, so all I had to do was draw up the board. This project was a little more difficult than my other PCB projects, since it had multiple supply voltages. I also added a little bit of 3D, with the LCD hovering over some comonents. You’ll see what I mean once I solder it together. After putting everything together, I ordered it and started to wait.

It arrived a couple of weeks later and they looked great. Anyways, it’s time to solder it together. I started with the power supply portion since I didn’t want to accidentally fry anything. Once I verified that they were working properly, it was time to solder the rest of the board. Everything else was simple enough, but the LCD is what is different. To make sure that the LCD could fit above the other components, I put female headers to separate it. It really is quite satisfying. Anyways, with that being siad, the project is now complete! There are a few glitches and noise issues, but those could be solved with a second version. Maybe I’ll cover that in a future video.

Anyways, I hope you enjoyed this video and found it helpful. If you make a function generator of your own, you certainly won’t regret the convenience it brings to your workbench. If you enjoyed watching please consider subscribing so that you can see the other videos that I make. Have a good one.