Today I am going to continue with the DIY signal generator based on the AD9833 IC where I have left in the second part. Earlier, I have talked about how I had built second analog signal generator’s stage – offset adding circuit. Because the generator is going to be digital, potentiometers should be replaced by electronically controllable circuits. So, today I will walk you through a filter circuit which changes PWM signal from an MCU output to an analog DC voltage.
Let’s again remember full test PCB’s initial circuit:
Links to project’s all posts
- VCA822 Gain Amplifier Circuit
- LM7171 Offset Circuit
- Gain and Offset Control Filter Circuit (this post)
- Dual 5V Power Supply
- Dual 12V TPS65131 Power Supply
- Battery Charging Circuit with BQ24295
- Basic WEB Interface
- IPS Capacitive LCD on an ESP32
- IPS LCD, ESP32 with eSPI library and Touch screen
- Final PCB Design for the DIY Waveform Generator
- Custom Design PCBs and How To Get Them Manufactured
- Soldering the PCB
- AD9833 Library and Further Output Noise Reduction
- Arduino BQ24295 Battery Charger Library
- LCD GUI with LVGL on ESP-32
- 3D Printed Enclosure
- Finished DIY generator
As I have mentioned, in this post we will look into filtering circuit:
There will be two almost identical filtering circuits – one for gain and one for offset control. OPA2196 for this circuit was chosen. The op-amp has low offset and its drift values, it has wide power supply voltage range, which is good for testing purposes, it is also unity gain stable which makes it suitable for filter application where gain is set to 1.
The shown circuit is second order Sallen-Key filter with a gain of 2. With R10 = R11 = 22k and C6 = C7 = 470n values, the filter’s corner frequency is around 16 Hz. During testing with these values, it was noticed, that using PWM frequency of 10kHz made output perfect DC value, while using 1kHz PWM frequency – a triangle wave was seen with several mVpp ripple. Also, corner frequency is high enough to let output value change quickly enough to be usable in setting the generator’s output offset value.
Additional offset on the filter’s input
The shown filtering circuit would output only positive voltages because PWM signal from an MCU is also only positive. The gain amplifier and offset stages also needs negative voltages. So, to set additional offset on each filters input, a voltage divider circuit was used:
When PWM is set to 50 percent, average voltage will be around 1.65 V (3.3V*0.5). So, let’s say we need to get 0V at divider’s output when PWM average voltage is 1.6 and the divider is connected to -5V instead of ground, then a ratio Rx : Ry is going to be 1 : 3.125. In reality I have chosen ratio of 1:3 as then it was easier to find needed resistor values (which were 1.3k and 3.9k).
With divider circuit on the filter’s input and gain set to 2 the generator (at its offset amplifiers stage) outputs dc voltages in the range of -7.3 to + 8.3 V. This voltage range is higher that I initially have wanted (+- 5V). So, the gain might be reduced in the final design.
The second filter, as I have mentioned earlier, is used for controlling generators gain. The only difference is that this filter’s gain is set to 1 (R13 = 0, R14 not soldered in). Such filter outputs voltages in the range of -1.2 to +1.2 V. By the way, filter op-amp can be powered either from +- 12V or +-5V. It might be better to power it from +-5V in a battery powered device. Boosting voltage to 12V from a battery might be inefficient, so it is best not to load this rail.
Note, that up until now, ESP8266 was used to set AD9833 output waveform and frequency. These values were constants and would be always set up after powering up the ESP. The PWM signals supplied into filters inputs are also taken from the same ESP8266. As I needed to have ability to change PWM values, a simple web interface was written.
The interface is actuality slightly modified interface from Temperature-Humidity sensor. The difference is that in this case two sliders were added to change gain and offset PWMs. Also, I should mention that this interface will definitely change in the future as now it can be used for testing purposes only.
To sum up, two additional filter circuits were added to the design. These filters replaced two potentiometers used to control the generator’s output amplitude and offset values. Now, with this additional circuity, there is an ability to control aforementioned generator’s parameters fully electronically with any available MCU and its PWM output.