Lennard Electronics Ltd
Simple A to D
I have a number of ideas involving the use of A to D converters, including a simple thermometer, and a Data Logger.
Below is a sample circuit to show how easy it is to use a Serial AD chip.
The circuit simply reads the voltage at the chip's input (Provided by the 47k variable resistor), and displays the digital value (in Decimal and Hexadecimal) on my 5 digit LED display. A little bit of maths and you could easily display the actual voltage (eg: 255 = 5V, 127 = 2.5V, 000 = 0V), but this gives you the idea.
The code is a simple modification of one of the sample codes in the data sheet for my 5 digit LED display. The actual ADC part of the code is very simple. The pdf for the AD chip is available from Texas Instrument's web site.
In order to log data, you can do it two ways.
1. Store data in memory on your microcontroller board and download later, or
2. Send data, as it is collected, to a PC.
Then - display the results.
Here is how I set up my test circuit, for option 2, to log the voltage every second as I adjusted the Variable resistor, and display the data in Excel on my Mac and Windows PC.
a). Firstly, in order to present the data in a format that Excel can understand, you need to create a "Comma separated values" file. This is a text file where commas separate the field values.
b). Use Hyperterminal to receive data from the Stamp, and turn on Text Capture.
So, to display something like the following table in Excel:
Your text file will need to look like this:
This code will do the trick. This version displays the voltage on my 5 digit LED module, and the data is sent out the serial port, formatted as per the requirements above.
How to display in Excel:
Within Excel, start recording a Macro. Open your text file, and follow the wizard to get your data displayed correctly. You can create graphs of your data as in the screenshot below. Now, everytime you run the Macro, you can easily collect data from your A to D circuit.
A complete working datalogger.
- The circuit on this page is made up from circuit examples on other pages on this site.
- The circuit diagram is below, and I've included some sample screen shots of collected data.
- The circuit shows a Temperature sensor wired up. You can easily connect whatever you want as a transducer...
- For full details on each device, have a look at the datasheets for them, which are easy to find on the Internet.
- You will need to burn an EEPROM for EEPROM_1, that contains all the messages, etc. used for the LCD.
- TABLE 1 - Memory Map of the 24C02 at Device address 002 on the I2C BUS
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00 L e n n a r d E l e c t r o n 10 i c s w w w . l e n n a r d . n 20 e t . n z F i r m w a r e v 1 30 . 0 0 0 9 / 0 2 S a m p l e 40 M e m o r y A b o u t S a m 50 p l e R a t e i s A d j u s 60 t O K O n B 70 o a r d M e m o r y S t o r e 80 D o w n l o a d P 90 r e s s G o w h e n r e a A0 d y D o w n l o a d i n g . . . B0 o f s e c m i n h o u r 0E 11 C0 15 15 15 11 15 1F 0E 11 11 11 11 11 1F 1F 0E 1F D0 1F 1F 1F 1F 1F 1F 0E 11 1F 1F 1F 1F 1F 1F 0E 11 E0 11 1F 1F 1F 1F 1F 0E 11 11 11 1F 1F 1F 1F 0E 11 F0 11 11 11 1F 1F 1F 18 14 14 14 1C 01 0A 04 00 00 Display messages Custom LCD characters User settings
The code is here.
All the data for these examples was collected by downloading the data from my datalogger's memory to Hyperterminal (or a similar Mac terminal emulator) using text capture mode, then the captured text file was loaded in to Excel and the chart wizard used to create the graphs.
- Temperature in the lounge at home over a 21 hour period...
- Conditions: A nice warm, sunny day in Wellington, with a mild breeze.
- Start time 2pm Saturday
- Samples every 5 minutes (256 samples x 5 minutes = 21.3 hours)
- Finish time, approx 11:20am Sunday (This is where the RTC code would come in handy - getting exact times).
You can see that the temperature went up and down a bit during the day. It can get hot in the lounge, and opening a window, and the door to the balcony helped cool the room down (until the wind stopped...). The Time along the X axis was a simple calculation in Excel.
The next two examples use modified code (just displaying the actual voltage).
light level during the day from 4.30pm until 8.46pm...
- Trasducer: A Solar panel.
- Conditions: Very cloudy and windy
- Start time: 4.30pm
- Samples: 1 minute samples (256 x 1 min samples = 4 hours and 16 minutes
- Finish time: 8.46pm
You can see the light level going up and down as clouds passed by overhead. Around about 6.30pm, is when the sun started to disappear behind the hills of Crofton Downs, and from 7pm to 7.40pm more peaks and throughs as clouds cleared then gathered again, then from around 7.50pm, the sun started to set altogether.
Discharge of a capacitor over 4 minutes and 16 seconds (256 1 second samples)...
This is a chart created in Excel. A .csv file is imported to Excel with the data as read from the Datalogger's memory, then in Excel, a simple calculation is performed to get the actual voltage that the data represents.