Top Banner
instructables Portable Function Generator on Arduino by Faransky 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. https://youtu.be/Xt2-HlCfXGs Portable Function Generator on Arduino: Page 1
13

Portable Function Generator on Arduino

Nov 25, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Portable Function Generator on Arduino

instructables

Portable Function Generator on Arduino

by Faransky

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

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.

https://youtu.be/Xt2-HlCfXGs

Portable Function Generator on Arduino: Page 1

Page 2: Portable Function Generator on Arduino

Step 1: The Idea

There are a lot of circuits that require some testingequipment in order to get information about circuit'sresponse to a certain waveform. This project in basedon Arduino (Arduino Nano in this case), with 3.7V aLithium-Ion battery as a power source thus makingthe device portable. It is known that Arduino Nanoboard requires 5V as a power supply, so electronicdesign contains DC-DC boost converter that converts3.7V battery voltage to 5V required for powering upthe Arduino. Thus, this project is easy to build,completely modular, with relatively simple schematicdiagram.

Powering the board: Device has a single mini-USBconnector that receives 5V from the external powersupply, that may be either PC or external USBcharger. the circuited designed in a way that whenthe 5V DC source is connected, Li-ion battery isbeing charged by TP4056 charger module that isattached to the power supply circuitry (Topic will be

expanded further in the following steps).

AD9833: integrated function generator circuit is acentral part of the design, controlled via SPI interfacewith ability to generate square/sine/triangle wave withfrequency modulation option. Since AD9833 has nocapability to change output signal amplitude, I'veused a digital 8-bit potentiometer as a voltage dividerat the device output endpoint (Will be described infurther steps).

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

After this brief introduction, we can proceed to thebuilding process.

Portable Function Generator on Arduino: Page 2

Page 3: Portable Function Generator on Arduino

Portable Function Generator on Arduino: Page 3

Page 4: Portable Function Generator on Arduino

Step 2: Parts and Instruments

1: Electronic Parts:1.1: Integrated Modules:

Arduino Nano board1602A - Generic liquid crystal displayCJMCU - AD9833 Function generator moduleTP4056 - Li-ion battery charger moduleDC-DC Step-Up coverter module: 1.5V-3V to 5V converter

1.2: Integrated Circuits:

SRD=05VDC - 5V SPDT relayX9C104P - 8-bit 100KOhm digital potentiometerEC11 - Rotary Encoder with SPST switch2 x 2N2222A - NPN general purpose BJT

1.3: Passive and unclassified parts:

2 x 0.1uF -Ceramic capacitors2 x 100uF - Electrolytic capacitors2 x 10uF - Electrolytic capacitors3 x 10KOhm Resistors2 x 1.3KOhm Resistors1 x 1N4007 Rectifier diode1 x SPDT Toggle switch

1.4: Connectors:

3 x 4-pin JST 2.54mm pitch connectors3 x 2-pin JST 2.54mm pitch connectors1 x RCA Receptacle connector

2: Mechanical Parts:

1 x 12.5cm x 8cm x 3.2cm Plastic enclosure6 x KA-2mm pulling screws4 x KA-8mm drilling screws1 x Encoder knob (Cap)1 x 8cm x 5cm Prototype board

3. Instruments and Software:

Soldering station/ironElectrical screwdriverGrinding files of numerous sizesSharp knifeDrill bits

Portable Function Generator on Arduino: Page 4

Page 5: Portable Function Generator on Arduino

Screwdriver bitsHot glue gunMini-USB cableArduino IDECaliper/ruler

Step 3: Schematics Explanation

In order to make it easier to understand the schematic diagram, description is divided in sub-circuits while everysub-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, inboth digital and analog operating modes. Since this module has its own mini-USB input connector, it will be usedboth as a power supply input and programming interface input. Because of that, J1 - the mini-USB connector isdetached 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 usedas digital output, communicating with LCD and AC/DC coupling select of the device's output. Analog pins A6 andA7 are dedicated analog input pins and only can be used as an ADC inputs, because of Arduino Nanomicrocontroller ATMEGA328P TQFP package, as it was defined in the datasheet. Notice that battery voltage lineVBAT is attached to the analog input pin A7, because we need to get its value in order to determine low batterystate 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 aSPST toggle switch that controls power flow on the whole circuit. As it can be seen from the schematics, whenexternal power supply is connected via micro-USB connector of the Arduino Nano module, battery is beingcharged 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.

Portable Function Generator on Arduino: Page 5

Page 6: Portable Function Generator on Arduino

3. AD9833 and Output:

This sub-circuit provides appropriate output waveform, defined by AD9833 module (U1). Since there is only singlepower supply on device (5V), there is need to attach coupling select circuit to the output cascade. C1 capacitor isconnected 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 waveformeven of low frequencies to pass through capacitor without being distorted, only affected by DC removal. Q1 isused as simple BJT switch used to drive current through relay's inductor. Make sure that diode is connected in areverse 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 agiven 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 energyconsumption, LCD backlight cathode pin is connected to Q2 BJT connected as switch, controlled by PWM signaldriven 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 anexternal 10KOhm resistors, but it can also be defined via code. It is recommended to add 0.1uF capacitors inparallel 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 toassemble the device, with an additional feature of reducing place for mistakes during the building process.Mapping the connectors is done this way:

J3, J4: LCDJ5: EncoderJ6: BatteryJ7: SPST toggle switchJ8: RCA output connector

Portable Function Generator on Arduino: Page 6

Page 7: Portable Function Generator on Arduino

https://www.instructables.com/ORIG/FC4/3NTE/JLGUZFAV/FC43NTEJLGUZFAV.pdf…Download

Portable Function Generator on Arduino: Page 7

Page 8: Portable Function Generator on Arduino

Step 4: Soldering

Because of this project' modular design, solderingstep becomes simple:

A. Main board soldering:

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

2. Soldering The Arduino Nano module and testing itsinitial operation.

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

4. Soldering AD9833 module with all the peripheralcircuits.

5. Soldering all the JST connectors.

B. External components:

1. Soldering JST male connector' wires to the LCDpins in EXACT order as there were planned on themain board.

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

3. Soldering toggle switch to the JST wires.

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

Portable Function Generator on Arduino: Page 8

Page 9: Portable Function Generator on Arduino

Portable Function Generator on Arduino: Page 9

Page 10: Portable Function Generator on Arduino

Step 5: Enclosure and Assembly

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

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

2. Preparing LCD frame: Decide where LCD will belocated on the device, make sure that it will be placedin right direction, it happened to me several times thatafter I finished all the cutting process, LCD wasinverted vertically, speaking of which is sad, becausethere is need to re-arrange the LCD frame.

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

Insert the LCD from the inside and locate the screwpoints on the enclosure. Drill holes with anappropriate diameter drill bits. Insert pulled screwsand fasten nuts on the inner side of front panel.

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

4. Toggle switch: decide on dimensions of the toggleswitch swing, so it can may be pulled down or upfreely. 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 diameterhole for the RCA output connector on the side-bottomside of the enclosure. Fasten it with the hot glue gun.

6. Main board and battery: Place Li-ion battery onthe bottom side of the enclosure. Battery can befastened with a hot glue gun. Main board should bedrilled in four places for 4 screws on each main boardcorner. Make sure that Arduino mini-USB input is ascloser as possible to the boundary of enclosure (Wewill have to use it for charging and programmingpurposes).

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

8. Final: Connect all the JST connectors, attach bothparts of the enclosure with a four 8mm screws oneach corner of the enclosure.

Portable Function Generator on Arduino: Page 10

Page 11: Portable Function Generator on Arduino

Step 6: The Arduino Code

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

https://www.instructables.com/ORIG/F5T/SN9I/JLGV118U/F5TSN9IJLGV118U.ino…Download

https://www.instructables.com/ORIG/F93/DORM/JLGV210V/F93DORMJLGV210V.cpp…Download

Portable Function Generator on Arduino: Page 11

Page 12: Portable Function Generator on Arduino

Thank you. Because I will be using it on battery most of the time I replaced the relay with a AC/DCswitch, so the relay will not be on. I noticed you did not show a contrast pot, is that an oversight oris it realy not needed?

Contrast pot does not present in my particular case. I've tested the LCD contrast after all thecircuits were soldered, it was sufficient to tie it to the ground. But it depends on design you want tomake.

This is a very well written instructable. Thanks for taking the time & effort.

Very nice project! Been looking for something like this. Is the 10 MHz limit caused solely by theAD9833 module? Is there a way to get up to 30 MHz of clean sine wave from the device orperhaps another? I need to cover all frequencies between audio and 30 MHz for a Ham Radioproject. Thanks.

Frequency limit is based on digital potentiometer bandwdith. Because it is embedded resistor arrayinside the IC, its inductive behavior above ~10MHz becomes significant. But regardless digipot,AD9833 module is able to produce up to 25MHz output waveform.

Hi, nice project indeed!But why make it portable? This is a device used in your "lab", so just plug a 5 V USB charger andbe done. That simplifies the project considerably and makes it a lot cheaper. No need for battery,charger or DC-DC converter.

Another note, why use a relay and not a MOSFET for decoupling? A relay is quite power hungryand not really the best choice for a battery powered project IMHO. One of these two are examplesof suitable devices:

https://www.sparkfun.com/products/10213

https://www.sparkfun.com/products/10349

Of course, the schematics would change quite a bit if using these. They can be driven directy fromthe Arduino, without the transistor. The resistance in "open" state is in the milli-ohm range. Shouldwork nicely I think!

Step 7: Final Testing

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

Hope, you'll find this instructable useful,

Thanks for reading! ;)

Portable Function Generator on Arduino: Page 12

Page 13: Portable Function Generator on Arduino

Good project and well explained! Thanks for sharing.

Very nice job!

I could make it! thanks

Very nice! Do you have a PCB layout, or an enclosure on Thingiverse?

Initially I wanted to make complete PCB design, but Idea was discarded since the whole deviceconsists of very easy to use PCB modules that makes soldering + assmebly processes muchfaster :)

Nice project! I might try building this I've needed a function gen a couple times now and this wouldbe handy.

One suggestion on the steps....

"cut off the Arduino micro-USB area with a grinding file"

rephrase that as:

"cut a hole in the case for the Arduino micro-USB area with a grinding file"

I had to read it three times because I thought you wanted me to cut off the USB connector at first!LOL!

Thanks for notice. When I tried to re-read the assembly step, that's really what comes in mind first:)

Portable Function Generator on Arduino: Page 13