px-lib  0.8.3 dev
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers
ADC Data Logger Application

1. Introduction

This is an ADC data logger app for the Piconomix ATmega328P Scorpion Board.

Here is an example where the logger was used to measure the voltage of 2 x AA cells and the output of the +8V boost converter to determine maximum battery life:

scorpion_board_log_adc_graph.png
ADC graph

Observe that the minimum value (not the average value) reveals when the +8V boost converter starts to fail.

The board has 4 ADC channels. The input voltage range on ADC0 and ADC1 is +0 mV to +3300 mV (1:1 divider). The input voltage range on ADC2 and ADC3 is +0 mV to +36300 mV (11:1 divider). The scale can be changed by replacing or removing the resistor dividers.

2. Command examples

Basic use of the Command Line Interpreter is documented here

Type 'help' to list commands with parameters and descriptions:

>help

log s                                    : Start logging
log dump                                 : Dump log
log del                                  : Delete log
log info                                 : Report ADC settings
log fit     <ch> <scale> <offset>        : Configure linear fit of ADC channel (y = scale x ADC + offset)
log samples <nr of samples>              : Set number of samples accumulated for each ADC channel

rtc r                                    : Read RTC time
rtc w       <yy-mm-dd> <hh:mm:ss>        : Write RTC time

fs info                                  : Report file system info

sf info                                  : Report Serial Flash info
sf e        [start page] [end page]      : Erase Serial Flash page(s)
sf r        <adr> <nr of bytes>          : Read Serial Flash data
sf rp       <page>                       : Read Serial Flash page
sf rx       [start page] [end page]      : Read Serial Flash data and send using XMODEM
sf wp       <page> <offset> <d0> .. [d7] : Write up to 8 bytes of data to Serial Flash
sf wx       [start page]                 : Receive data using XMODEM and write to Serial Flash

help        [cmd(s) starts with...]      : Display list of commands with help. Optionally the list can be reduced.

Type 'rtc w <yy-mm-dd hh:mm:ss>' to set the date and time:

>rtc w 19-09-12 15:28:58

The raw 10-bit ADC values (0 to 1023) is scaled and an offset added. The default scale and offset value for each channel converts the raw ADC value into millivolt (mV).

Formula: ScaledValue = scale x ADC + offset

Type 'log info' to get the ADC settings:

>log info
Sampling rate = 1000 Hz
Number of samples = 1000
ADC0 : Scale = 3.225806, Offset = 0.000000
ADC1 : Scale = 3.225806, Offset = 0.000000
ADC2 : Scale = 35.483871, Offset = 0.000000
ADC3 : Scale = 35.483871, Offset = 0.000000

To change the scale of channel 0 to +10.1 and the offset to -4.5:

>log fit 0 10.1 -4.5

All the channels are sampled at 1000 Hz (1 ms). The values are accumulated and by default the average is logged every 1000 samples, i.e. once every 1000 ms (1 s). The number of samples can be changed to make the logging rate quicker or slower. For example, to make the logging rate 500 ms (0.5 s):

>log samples 500

Type 'log s' to start logging (MIN, MAX and AVERAGE value for ADC0, ADC1, ADC2 and ADC3):

>log s
Timestamp       ADC0_MIN        ADC0_MAX        ADC0_AVE        ADC1_MIN        ADC1_MAX        ADC1_AVE        ADC2_MIN        ADC2_MAX        ADC2_AVE        ADC3_MIN        ADC3_MAX        ADC3_AVE
19-09-12 10:41:09       0.000000        3.225806        1907996.800000  54306.453000    131864.520000   71500.586000    73522.578000    8374.193400     76201048.000000 81754.844000    588996.810000   39149624.000000
19-09-12 10:41:10       0.000000        3.225806        1907996.800000  54306.453000    131864.520000   71500.586000    73522.578000    8374.193400     76201048.000000 81754.844000    588996.810000   39149624.000000
19-09-12 10:41:11       0.000000        9.677420        1907996.800000  54306.453000    131864.520000   71500.586000    73522.578000    8374.193400     76201048.000000 81754.844000    588996.810000   39149624.000000
19-09-12 10:41:12       0.000000        12.903226       1907996.800000  54306.453000    131864.520000   71500.586000    73522.578000    8374.193400     76201048.000000 81754.844000    588996.810000   39149624.000000

Press SPACE or press the button on the board to stop.