SEARCH
TOOLBOX
LANGUAGES
modified on 14 November 2011 at 13:47 ••• 11,276 views

Electrum Kernel SPI ADC Driver

From Manuals

Jump to: navigation, search

Kernel SPI ADC driver

Contributed by: Christian Saether

This driver is an spi protocol driver for the adc128s052 a/d chip option on the Micromint Electrum 100 SBC. It is meant to be built as a loadable driver. It allocates a megabyte internal buffer (about a second's worth of samples) when loaded. It is controlled by writing to its file system device.

The commands are:

"r" - run
"s" - stop
"cddd..." - one or more "d" specifying channel rotation

It will send a message to sample each of the specified channels 16 times in rotation. Channel zero is always included. The numbers of channels must be 1, 2, 4, or 8.

For example, if the device is "/dev/adc0" then the following shell command

echo c0123 > /dev/adc0

will enable sampling for channels 0, 1, 2, and 3. The device must be stopped when this is issued. To start sampling, do

echo r > /dev/adc0

At this point, the data samples will be returned by doing a read on /dev/adc0. They are returned as a series of 16 bit values in the channel rotation specified.

Using od to display them, for example:

od -sAn -w8 /dev/adc0
8172   8174      1    268
8174   8181      1    270
8172   8181      2    266
8176   8173      0    263
8172   8172      2    268
8172   8179      2    265
8169   8177      2    269
8175   8180      1    264

Reading from minor device numbers other than zero will average samples by 2 raised to the minor number, so reading minor device number 1 returns the average of every 2 samples, minor 2 every 4 samples, up to minor 4 (avg every 16). Values from the a/d are shifted left 2 (multiplied by 4) as the lower bits will have some value when multiple samples are averaged.