Portable Function Generator on Arduino

25,189

229

37

Hi, I have a hobby to build some DIY Audio stuff, simple gadgets, etc. Hope you will find my inst...

Function generator is a very useful tool, especially when we are considering testing our circuit's response to a certain signal. In this instructable I'll describe the building sequence of small, easy to use, portable function generator.

Features of the project:

  • Fully digital control: No need for passive analog components.
  • Modular design: Every sub-circuit is a pre-defined easy to use module.
  • Output frequency: Available range from 0Hz to 10MHz.
  • Simple control: Single rotary encoder with built-in push button.
  • Li-ion battery for portable use, with external charging ability.
  • AC and DC coupling for output waveform.
  • LCD Brightness control for energy consumption reduction.
  • Battery charge indicator.
  • Digital amplitude control.
  • Three available waveforms: Sine, triangle and square.

Step 1: The Idea

There are a lot of circuits that require some testing equipment in order to get information about circuit's response to a certain waveform. This project in based on Arduino (Arduino Nano in this case), with 3.7V a Lithium-Ion battery as a power source thus making the device portable. It is known that Arduino Nano board requires 5V as a power supply, so electronic design contains DC-DC boost converter that converts 3.7V battery voltage to 5V required for powering up the Arduino. Thus, this project is easy to build, completely modular, with relatively simple schematic diagram.

Powering the board: Device has a single mini-USB connector that receives 5V from the external power supply, that may be either PC or external USB charger. the circuited designed in a way that when the 5V DC source is connected, Li-ion battery is being charged by TP4056 charger module that is attached to the power supply circuitry (Topic will be expanded further in the following steps).

AD9833: integrated function generator circuit is a central part of the design, controlled via SPI interface with ability to generate square/sine/triangle wave with frequency modulation option. Since AD9833 has no capability to change output signal amplitude, I've used a digital 8-bit potentiometer as a voltage divider at the device output endpoint (Will be described in further steps).

Display: is the basic 16x2 LCD, which is probably the most popular liquid-crystal display among Arduino users. In order to reduce energy consumption, there is an option to adjust LCD backlight via PWM signal from the Arduino pre-defined "analog" pin.

After this brief introduction, we can proceed to the building process.

Step 2: Parts and Instruments

1: Electronic Parts:

1.1: Integrated Modules:

  • Arduino Nano board
  • 1602A - Generic liquid crystal display
  • CJMCU - AD9833 Function generator module
  • TP4056 - Li-ion battery charger module
  • DC-DC Step-Up coverter module: 1.5V-3V to 5V converter

1.2: Integrated Circuits:

  • SRD=05VDC - 5V SPDT relay
  • X9C104P - 8-bit 100KOhm digital potentiometer
  • EC11 - Rotary Encoder with SPST switch
  • 2 x 2N2222A - NPN general purpose BJT

1.3: Passive and unclassified parts:

  • 2 x 0.1uF -Ceramic capacitors
  • 2 x 100uF - Electrolytic capacitors
  • 2 x 10uF - Electrolytic capacitors
  • 3 x 10KOhm Resistors
  • 2 x 1.3KOhm Resistors
  • 1 x 1N4007 Rectifier diode
  • 1 x SPDT Toggle switch

1.4: Connectors:

  • 3 x 4-pin JST 2.54mm pitch connectors
  • 3 x 2-pin JST 2.54mm pitch connectors
  • 1 x RCA Receptacle connector

2: Mechanical Parts:

  • 1 x 12.5cm x 8cm x 3.2cm Plastic enclosure
  • 6 x KA-2mm pulling screws
  • 4 x KA-8mm drilling screws
  • 1 x Encoder knob (Cap)
  • 1 x 8cm x 5cm Prototype board

3. Instruments and Software:

  • Soldering station/iron
  • Electrical screwdriver
  • Grinding files of numerous sizes
  • Sharp knife
  • Drill bits
  • Screwdriver bits
  • Hot glue gun
  • Mini-USB cable
  • Arduino IDE
  • Caliper/ruler

Step 3: Schematics Explanation

In order to make it easier to understand the schematic diagram, description is divided in sub-circuits while every sub-circuit has responsibility for each design block:

1. Arduino Nano Circuit:

Arduino Nano module acts as a "Main Brain" for our device. It controls all the peripheral modules on device, in both digital and analog operating modes. Since this module has its own mini-USB input connector, it will be used both as a power supply input and programming interface input. Because of that, J1 - the mini-USB connector is detached from schematic symbol of Arduino Nano (U4).

There is an option for using dedicated analog pins (A0..A5) as general purpose I/O, so some of the pins are used as digital output, communicating with LCD and AC/DC coupling select of the device's output. Analog pins A6 and A7 are dedicated analog input pins and only can be used as an ADC inputs, because of Arduino Nano microcontroller ATMEGA328P TQFP package, as it was defined in the datasheet. Notice that battery voltage line VBAT is attached to the analog input pin A7, because we need to get its value in order to determine low battery state of Li-ion battery voltage.

2. Power Supply:

Power supply circuit is based upon powering the whole device via Li-ion battery 3.7V converted to a 5V. SW1 is a SPST toggle switch that controls power flow on the whole circuit. As it can be seen from the schematics, when external power supply is connected via micro-USB connector of the Arduino Nano module, battery is being charged through TP4056 module. Make sure that bypass capacitors of several values are present on the circuit, since there is a DC-DC boost converter switching noise on ground and 5V potentials of the whole circuit.

3. AD9833 and Output:

This sub-circuit provides appropriate output waveform, defined by AD9833 module (U1). Since there is only single power supply on device (5V), there is need to attach coupling select circuit to the output cascade. C1 capacitor is connected in series to the amplitude selection stage, and can be silenced via driving current on the relay inductor, thus making output signal traced straight to the output stage. C1 has value of 10uF, it is sufficient for the waveform even of low frequencies to pass through capacitor without being distorted, only affected by DC removal. Q1 is used as simple BJT switch used to drive current through relay's inductor. Make sure that diode is connected in a reverse allocation to the relay inductor, in order to avoid voltage spikes that can damage the device circuits.

Last but not least stage is an amplitude select. U6 is 8-bit digital potentiometer IC, that acts as voltage divider for a given output waveform. X9C104P is a 100KOhm digital potentiometer with very simple wiper position adjustment: 3-pin digital inputs for adjusting increment/decrement wiper position.

4. LCD:

16x2 Liquid crystal display is graphical interface between user and the device' circuitry. In order to reduce energy consumption, LCD backlight cathode pin is connected to Q2 BJT connected as switch, controlled by PWM signal driven by Arduino analogWrite ability (Will be described in Arduino code step).

5. Encoder:

Encoder circuit is a control interface, defining whole device operation. U9 consists of encoder and a SPST switch, so there is no need to add additional buttons to the project. Encoder and switch pins should be pulled up by an external 10KOhm resistors, but it can also be defined via code. It is recommended to add 0.1uF capacitors in parallel to the encoder A and B pins in order to avoid bouncing on these input lines.

6. JST Connectors:

All the external parts of the device are connected via JST connectors, thus making it much more convenient to assemble the device, with an additional feature of reducing place for mistakes during the building process. Mapping the connectors is done this way:

  • J3, J4: LCD
  • J5: Encoder
  • J6: Battery
  • J7: SPST toggle switch
  • J8: RCA output connector

Step 4: Soldering

Because of this project' modular design, soldering step becomes simple:

A. Main board soldering:

1. First of all, there is need to crop the prototype board to the size of desired enclosure dimensions.

2. Soldering The Arduino Nano module and testing its initial operation.

3. Soldering power supply circuit and checking all the voltage values conform the device requirements.

4. Soldering AD9833 module with all the peripheral circuits.

5. Soldering all the JST connectors.

B. External components:

1. Soldering JST male connector' wires to the LCD pins in EXACT order as there were planned on the main board.

2. Soldering JST Male connector' wires to the encoder similarly to the previous step

3. Soldering toggle switch to the JST wires.

4. Soldering JST wires to the battery (If it is needed at all. Some of the Li-ion batteries available on eBay are pre-soldered with their own JST connector).

Step 5: Enclosure and Assembly

After all the soldering is done, we can proceed to device assembly sequence:

1. Think over device external parts placement: In my case, I preferred to place encoder below LCD, when toggle switch and RCA connector are placed on separate sides of the enclosure box.

2. Preparing LCD frame: Decide where LCD will be located on the device, make sure that it will be placed in right direction, it happened to me several times that after I finished all the cutting process, LCD was inverted vertically, speaking of which is sad, because there is need to re-arrange the LCD frame.

After frame is selected, drill several holes on the perimeter of the whole frame. Remove all the unwanted plastic cuts with grinding file.

Insert the LCD from the inside and locate the screw points on the enclosure. Drill holes with an appropriate diameter drill bits. Insert pulled screws and fasten nuts on the inner side of front panel.

3. Encoder: has only single rotary part on the package. Drill the area according to the encoder rotary attachment diameter. Insert it from the inside, fasten it with a hot glue gun. Place a cap on the rotary attachment.

4. Toggle switch: decide on dimensions of the toggle switch swing, so it can may be pulled down or up freely. If you have screw points on the toggle switch, drill the appropriate areas on the enclosure, Otherwise you can fasten it with a hot glue gun.

5. RCA output connector: Drill appropriate diameter hole for the RCA output connector on the side-bottom side of the enclosure. Fasten it with the hot glue gun.

6. Main board and battery: Place Li-ion battery on the bottom side of the enclosure. Battery can be fastened with a hot glue gun. Main board should be drilled in four places for 4 screws on each main board corner. Make sure that Arduino mini-USB input is as closer as possible to the boundary of enclosure (We will have to use it for charging and programming purposes).

7. Mini-USB: cut off the desired area for Arduino Nano micro-USB with a grinding file, thus making it possible to connect external power supply/PC to the device when it is assembled completely.

8. Final: Connect all the JST connectors, attach both parts of the enclosure with a four 8mm screws on each corner of the enclosure.

Step 6: The Arduino Code

Attached code is the complete device code that is needed for complete device operation. All the needed explanation is attached at the comment sections inside the code.

Step 7: Final Testing

We have our device ready to be used. mini-USB connector acts both as programmer input and external charger input, so device is capable of being programmed when is completely assembled.

Hope, you'll find this instructable useful,

Thanks for reading! ;)

Share

Recommendations

  • Big and Small Contest

    Big and Small Contest
  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • PCB Contest

    PCB Contest

37 Discussions

0
None
LeonardoD33

1 day ago on Step 7

Can I use an arduino LEONARDO in replacement of the arduino nano?

0
None
tcjeep

8 weeks ago

I have built this on a breadboard and am currently making a pcboard for the final project. The following comments might be useful for the beginner attempting this project. Two 10uF electrolytic capacitors are specified in the components list. Non are actually used, except to the AC coupling across the relay contacts. This signal has a very small DC component, 0.2V. So a non polarised capacitor should actually be used here. In any case the polarity of this capacitor is not shown. The second point is that LCD-V0, does not go anywhere, this is a contrast control and left floating will mean a black display. Taking it to ground seems to work.
Finally I found the schematic hard to follow, I understand that this is supposed to be the modern way to draw a schematic but its really confusing. One complete circuit would have explained everything and eliminated all the anomalies. Thanks for a useful design.

2 replies
0
None
tcjeepGönn_dir_hart

Reply 5 days ago

Yes PCB is came out okay, but I have a problem with Vbat, it doesn't display battery voltage.

20181023_124229.jpg20181027_151841.jpg
0
None
Gönn_dir_hart

5 days ago

Is there a plan for pcb sortware

0
None
ajoyraman

3 months ago

Good project and well explained! Thanks for sharing.

1 reply
0
None
tcjeepajoyraman

Reply 8 weeks ago

I thought of using some sort of bi-directional solid state device in place of the realy, but a FET is not the answer, in its "on" state it will not pass an AC signal. I chose a 14pin DIP reed relay, current draw is negligable.

0
None
FilibertoC2

2 months ago

Hello! nice project...but, do you have a Fritzing scheme sowe could replicate your PCB layout?

2 replies
0
None
FaranskyFilibertoC2

Reply 2 months ago

Hi, thanks. I didn't make any simplifying schemes to this project, since it's all modular and relatively easy to understand. There is digipot IC, but the rest are PCB modules with pin description labels printed on.

0
None
FilibertoC2Faransky

Reply 2 months ago

I understand, but the photo of weldings on the connection plate isn't so clear for me. Thanks the same

0
None
MichaelO11

2 months ago

Very nice project well documentated, well done...

0
None
NickB74

2 months ago

What battery would be appropriate? I can't find it in the parts list :(

1 reply
0
None
FaranskyNickB74

Reply 2 months ago

You can have a couple of options:

1. Attach a AA/AAA battery pack, of a sum voltage greater than 3.5V.

2. As it was mentioned in the project, rechargeable Li-ion battery is the best power source for the portable device. You can look up these on the eBay : https://www.ebay.com/itm/3-7V-2800-mAh-Polymer-rechargeable-Li-ion-battery-For-GPS-iPAQ-Tablet-PC-3570100/111764481577?epid=1160345563&hash=item1a05aea629:g:~ZwAAOSwyHRavaDZ or something similar. But do not forget about the battery charging circuit - for example TP4056 integrated PCB module.

0
None
bgroene

Question 3 months ago on Step 7

Instead of going to a digital oscilloscope, could this function generator be used with the Digilent analog discovery 2 USB to PC oscilloscope and logic analyzer?

1 answer
0
None
Faranskybgroene

Answer 3 months ago

Sure, it can be used with any testing equipment you want.

0
None
mikej191

Question 3 months ago

I am interested in building a project that will flash a 120 volt incandescent bulb at a variously range of from maybe 1khz to 1 mhz. It has to have an output of 120 volts to power the filament of the bulb.If it is possible to do, thank you.

2 answers
1
None
MikeD11mikej191

Answer 3 months ago

Incandescent lights work by heating up the filament. Right now it's being driven by a 60 cycle power and is going off 120 times a second. You can't measure or see any flicker because the filament needs time to cool off before you'd see a change. I'd estimate that the fastest you could turn on/off an incandescent light is around 5 times a second. So at 1KHZ, you wouldn't see anything different than the 60HZ your using now.

0
None
mikej191MikeD11

Reply 3 months ago

Thank you for your answer, I should of realized that myself.

0
None
AgilePhil

Question 3 months ago on Step 3

Where did you get the AD9833 module. I have seen several different ones and I don't want to buy the wrong one.

1 answer
0
None
FaranskyAgilePhil

Answer 3 months ago

If you are using eBay, you can search find the module here: https://www.ebay.com/itm/DDS-AD9833-Signal-Generat...

Just look for the "AD9833 DDS Signal Generator Module" key in your search.

Regarding the frequency, device' code defines maximum frequency of 10.990MHz. Where Hz step resolution is 10Hz, KHz step is 1Khz, and MHz step is 1MHz.

You can adjust step resolution in the frequency acquire block in the code.