ADC max1027
Contents
Introduction
The MAX1027 is an 8 channels 10 bits analog-to-digital converter (ADC) with an internal reference and an internal temperature sensor. It is mounted (in option) on the APF9328 boards. To know if you have one on your board, take a look at the connectors side:
If you don't have one and are a good electronician, you can order a sample at Maxim's website and solder it directly on your board (footprint is available).
Hardware interface
The 8 inputs voltage range is [0 - 3,3V]. Don't try to put higher voltage on ADC inputs !!
By default internal reference voltage is used (2,5V), so if you apply analog values > 2,5V, they will be truncated.
The i.MXL SPI_1 interface is used to communicate with the device.
If you want to use the MAX1027 then you will have to connect #EOC pin (End Of Conversion) and #CNVST pin (conversion start) to two i.MXL GPIOs. By default the driver is using PA13 (CSI_HSYNC) for #EOC and PA14 (CSI_PIXCLK) for #CNVST, so on the APF9328DevFull board you will have to connect pin 11 of ADC connector (right of Ethernet one) to pin 12 of CSI connector (below RS232 one) and pin 10 of the ADC connector to pin 14 of the CSI connector
Driver
Depending on your needs (ie sampling slow or fast signals) there are 2 ways to use the max1027 Linux driver:
- for slow signals (temperature or battery level monitoring), the driver can be strictly controlled from its /sys interface: /sys/bus/spi/devices/spiN.0/ (N depending on the number of SPI devices declared for your target). Moreover, if needed (lm-sensors & Co), you can add it a Linux Hardware Monitoring API (hwmon) compatible/standardized interface: /sys/class/hwmon/hwmonN/device/ (N depending on the ID given by hwmon). This interface mimics the /sys/bus/spi/devices/ one.
- for "fast" signals, the driver has a /dev interface which can be configured through /sys/bus/spi/devices/spiX.0/.
Installation
- From the armadeus/ top directory:
$ make linux26-menuconfig
- Then select in Device Drivers->SPI support->Freescale iMX SPI controler driver (builtin not module !!)
- If you want to have the hwmon compatible interface, select in Device Drivers->Hardware Monitoring Support->MAX1027 sensor chip (Module)
- and then choose MAX1027 driver in Device Drivers->Armadeus Specific Drivers->ARMadeus Max1027 ADC Drivers
- Once the new configuration saved, rebuild your system:
$ make
and copy hwmon.ko and max1027.ko driver to your target or reflash your rootfs.
- On the target, the driver can be started like this:
# insmod /lib/modules/drivers/hwmon/hwmon.ko (if you configurer hwmon interface) # insmod /lib/modules/drivers/hwmon/max1027.ko
- or like this if you reflashed your rootfs:
# modprobe max1027
Usage
"Slow" & configuration interface
Several interfaces in /sys/bus/spi/devices/spi... are created in order to:
- read the 8 analog inputs values: inx_input (in mV)
- read the temperature: temp1_input (in m°C)
- modify the max1027 registers: conversion, setup & averaging
# ls /sys/bus/spi/devices/spi1.0/ averaging driver in2_input in5_input modalias temp1_input bus in0_input in3_input in6_input setup uevent conversion in1_input in4_input in7_input subsystem
An input can be read like that:
# cat /sys/bus/spi/devices/spi1.0/in0_input
The temperature can be read like that:
# cat /sys/bus/spi/devices/spi1.0/temp1_input
These values are only updated each time you launch a conversion, to read the value updated you have to re-read the value. These values are only dedicated to measure slow evolving greats.
"Fast" interface (frequencies > 10Hz)
In that case you can use /dev interface (using blocking read to wait end of conversion). To create /dev nodes you can use the loadmax.sh script. As driver MAJOR number is dynamically allocated, you may need to update /dev depending on the drivers loaded on you system.
- repeatedly read value of analog input 0 (variable sampling rate = depends on system load):
# cat /dev/max1027/AIN0
- read analog input 0 once:
# time dd if=/dev/max1027/AIN0 bs=2 count=1 > tmp.bin # hexdump tmp.bin
Chip registers configuration
Independent of the mode, /sys interfaces allow direct access to the corresponding register in the MAX1027:
# let conv=0xb9; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
You can also get current (hexadecimal) values of conversion, averaging and setup registers with (for example):
# cat /sys/bus/spi/devices/spi1.0/setup 0x62
For more details on how to use these registers, take a look at the datasheet.
Shell examples
- Get channel 0 and temperature values:
# let conv=0x87; echo $conv > /sys/bus/spi/devices/spi1.0/conversion # cat /sys/class/hwmon/hwmon0/device/temp1_input # cat /sys/class/hwmon/hwmon0/device/in0_input
- Get channels [0-7] and temperature values:
# let conv=0xb9; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
- Get 4 average values (of 32 conversions) for channel 0:
# let avg=0x3c; echo $avg > /sys/bus/spi/devices/spi1.0/averaging # let conv=0x84; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
Links
Other languages: | |
---|---|
English • Français |