eCircuit  Center 
EE Design Series - DVM 1

About SPICE | SPICE Basics | Running SPICE | CIRCUIT COLLECTION
SPICE Commands | SPICE Downloads | About | Contact | Home

Software - Basic Voltmeter

pic

INTRO

This code builds on our Initial Test Software by adding a pushbutton press to change the Vrange. Again, even though we have NO analog prototype built yet, we can still write code and run a basic PRE-TEST with the Arduino UNO Board by itself.

Check out the Software Design overview.

Back to Design Series
 

ARDUINO BASICS

Here's the fast track version of running a C program (sketch) on your Arduino Board.

 

ARDUINO + ANALOG SCHEMATIC

The schematic shows the physical world that the code can control to implement our meter.

sch

 

FLOW CHART

Here's a shortened Flow Chart that skips the Pushbutton reading so we can focus on the ADC Read and Display.

pic

 

CODE STRATEGY / THEORY

A pushbutton as digital input requires only one additional component, a pullup resistor.
   pic

The two states can be described as

 SW      Vdin  Digital
 Open    5V    logic 1
 Closed  0V    logic 0

You read the button state every trip through the loop() function (or 0.25s) using digitalRead(Dx). The current and last reading are stored in variables

Although Normally Open, a press of the button causes a logic transition from 1 to 0. You can easily detect this change with the conditional statement

Arduino Pin usage

 

THE CODE

Caution Ahead - hardware person writing code! Granted, the program is so straighforward it's easy to create some reasonable code. However, I'm open to any suggestions from those with more Software experience.

Declarations

The variable declararions occur before the setup() function.

pic

 

Setup()

This code excecutes once in the Arduino Sketch. Note how the Vrange is set and then the digital bits D12,13 are set for resistor divider switches SW1,2. See comments in gray for code description.

pic

 

Loop()

This code runs continuously. The main voltmeter tasks happen here. To write this function, simply follow the flow chart and write the C code for each block. See comments in gray for program description.

pic

 

PRE-TEST

What can we test even though the analog circuitry has NOT been prototyped? Good news! We can jumper the Arduino's 3.3V supply directly into the A0 analog input.

 

NEXT UP

Congratulations for travelling this far, the basic voltmeter code is complete! However, in order to fully test it, we'll need to start constructing the actual prototype..

Back to Design Series