Difference between revisions of "ADC max1027"

From ArmadeusWiki
Jump to: navigation, search
Line 1: Line 1:
 
=Introduction=
 
=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:<br><br>
+
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:'''
[[image:APF9328_with_MAX1027.jpg|center|frame|'''figure 1''' - ''MAX1027 schematic'']]
+
[[image:APF9328_with_MAX1027.jpg|center|frame|'''figure 1''' - ''MAX1027 localisation'']]
  
If you don't have one and are a good electronician, you can order a sample at [http://www.maxim-ic.com Maxim's website] and solder it directly on your board (footprint is available).
+
If you don't have one and are a good electrician, you can order a sample at [http://www.maxim-ic.com Maxim's website] and solder it directly on your board (footprint is available).
  
 
=Hardware interface=
 
=Hardware interface=
'''The 8 inputs voltage range is [0 - 3,3V]. Don't try to put higher voltage on ADC inputs !!'''<br>
+
'''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.<br>
+
By default internal reference voltage is used ('''2,5V'''), so if you apply analog values > 2,5V, they will be truncated.
<br>
+
The i.MXL SPI_1 interface is used to communicate with the device.  
The i.MXL SPI_1 interface is used to communicate with the device. <br>
+
  
[[Image:MAX1027_connections.png]]
+
[[image:MAX1027_connections.png|center|frame|'''figure 1''' - ''MAX1027 connections'']]
<br><br>
+
  
 
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:
 
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:
Line 32: Line 30:
  
 
*From the ''armadeus/'' top directory:
 
*From the ''armadeus/'' top directory:
 +
<pre class="host">
 
  $ make linux26-menuconfig
 
  $ make linux26-menuconfig
 +
</pre>
  
*Then select in Device Drivers  ---> [*] SPI support  ---> <M>  Freescale iMX SPI controller
+
*Then select in  
[[Image:SPI_Linux_Config.png]]
+
<pre class="config">
 +
Device Drivers  --->  
 +
    [*] SPI support  --->  
 +
        <M>  Freescale iMX SPI controller
 +
</pre>
  
*<u>If you want to have the hwmon compatible interface</u>, select in Device Drivers  ---> <M> Hardware Monitoring support (Module)
+
* '''If you want to have the hwmon compatible interface''', select in  
[[Image:HWMonitor_Linux_Config.png]]
+
<pre class="config">
* and then choose MAX1027 driver in Device Drivers  ---> Armadeus specific drivers  ---> <M>  Armadeus Max1027 ADC driver (fast version)
+
Device Drivers  --->  
[[Image:MAX1027_Linux_Config.png]]<br>
+
    <M> Hardware Monitoring support (Module)
 +
</pre>
 +
* and then choose MAX1027 driver in  
 +
<pre class="config">
 +
Device Drivers   
 +
    ---> Armadeus specific drivers   
 +
        <M>  Armadeus Max1027 ADC driver (fast version)
 +
</pre>
  
 
*Once the new configuration saved, rebuild your system:
 
*Once the new configuration saved, rebuild your system:
 +
<pre class="host">
 
  $ make
 
  $ make
 +
</pre>
 
and [[Linux_drivers_generalities | copy ''hwmon.ko'' and ''max1027.ko'' driver to your target or reflash your rootfs.]]
 
and [[Linux_drivers_generalities | copy ''hwmon.ko'' and ''max1027.ko'' driver to your target or reflash your rootfs.]]
  
 
==Usage==
 
==Usage==
 
On the target, the driver can be started like this:
 
On the target, the driver can be started like this:
 +
<pre class="apf">
 
  # modprobe spi_imx
 
  # modprobe spi_imx
 
  # modprobe max1027
 
  # modprobe max1027
 
  max1027 v0.3 successfully probed !
 
  max1027 v0.3 successfully probed !
 +
</pre>
  
 
==="Slow" & configuration interface===
 
==="Slow" & configuration interface===
 +
 
Several interfaces in ''/sys/bus/spi/devices/spi...'' are created in order to:
 
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 8 analog inputs values: ''inx_input'' (in mV)
 
* read the temperature: ''temp1_input'' (in m°C)
 
* read the temperature: ''temp1_input'' (in m°C)
 
* modify the max1027 registers: ''conversion, setup & averaging''
 
* modify the max1027 registers: ''conversion, setup & averaging''
 
+
<pre class="apf">
 
  # ls /sys/bus/spi/devices/spi1.0/
 
  # ls /sys/bus/spi/devices/spi1.0/
 
  averaging    driver      in2_input    in5_input    modalias    temp1_input
 
  averaging    driver      in2_input    in5_input    modalias    temp1_input
 
  bus          in0_input    in3_input    in6_input    setup        uevent
 
  bus          in0_input    in3_input    in6_input    setup        uevent
 
  conversion  in1_input    in4_input    in7_input    subsystem
 
  conversion  in1_input    in4_input    in7_input    subsystem
 +
</pre>
  
 
An input can be read like that:
 
An input can be read like that:
 +
<pre class="apf">
 
  # cat /sys/bus/spi/devices/spi1.0/in0_input
 
  # cat /sys/bus/spi/devices/spi1.0/in0_input
 +
</pre>
  
 
The temperature can be read like that:
 
The temperature can be read like that:
 +
<pre class="apf">
 
  # cat /sys/bus/spi/devices/spi1.0/temp1_input
 
  # cat /sys/bus/spi/devices/spi1.0/temp1_input
 +
</pre>
  
'''These values are only updated each time you launch a conversion, ie accessing the Max1027 conversion register, after having configured setup register accordingly. So this interface is only suitable to measure slow evolving greats.'''<br>
+
'''These values are only updated each time you launch a conversion, ie accessing the Max1027 conversion register, after having configured setup register accordingly. So this interface is only suitable to measure slow evolving greats.'''
 
Example:
 
Example:
 +
<pre class="apf">
 
  # let set=0x62; echo $set > /sys/bus/spi/devices/spi1.0/setup
 
  # let set=0x62; echo $set > /sys/bus/spi/devices/spi1.0/setup
 
  # let conv=0x87; echo $conv > /sys/bus/spi/devices/spi1.0/conversion    (launch 1 conversion of temp & AN0)  
 
  # let conv=0x87; echo $conv > /sys/bus/spi/devices/spi1.0/conversion    (launch 1 conversion of temp & AN0)  
Line 77: Line 99:
 
  # cat /sys/bus/spi/devices/spi1.0/in0_input
 
  # cat /sys/bus/spi/devices/spi1.0/in0_input
 
  1135    (mV)
 
  1135    (mV)
 +
</pre>
  
 
==="Fast" interface (frequencies > 10Hz)===
 
==="Fast" interface (frequencies > 10Hz)===
CNVST pin is used to start the conversion, so you "only" have 7 analog inputs.<br>
+
 
 +
CNVST pin is used to start the conversion, so you "only" have 7 analog inputs.
 
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 located in armadeus/target/linux/modules/max1027. As driver MAJOR number is dynamically allocated, you may need to update ''/dev'' depending on the drivers loaded on you system.
 
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 located in armadeus/target/linux/modules/max1027. As driver MAJOR number is dynamically allocated, you may need to update ''/dev'' depending on the drivers loaded on you system.
  
 
* first, the conversion mode has to be chosen (channel 0->6 and temp):
 
* first, the conversion mode has to be chosen (channel 0->6 and temp):
 +
<pre class="apf">
 
  # let set=0xb1; echo $set > /sys/bus/spi/devices/spi1.0/conversion
 
  # let set=0xb1; echo $set > /sys/bus/spi/devices/spi1.0/conversion
 +
</pre>
 
* and eventually the averaging and setup registers as well (refer to the max1027 documentation for more details):
 
* and eventually the averaging and setup registers as well (refer to the max1027 documentation for more details):
 +
<pre class="apf">
 
  # let set=0x48; echo $set > /sys/bus/spi/devices/spi1.0/setup
 
  # let set=0x48; echo $set > /sys/bus/spi/devices/spi1.0/setup
 
  # let set=0x20; echo $set > /sys/bus/spi/devices/spi1.0/averaging
 
  # let set=0x20; echo $set > /sys/bus/spi/devices/spi1.0/averaging
 +
</pre>
 
* repeatedly read value of analog input 0 (variable sampling rate = depends on system load):
 
* repeatedly read value of analog input 0 (variable sampling rate = depends on system load):
 +
<pre class="apf">
 
  # cat /dev/max1027/AIN0
 
  # cat /dev/max1027/AIN0
 +
</pre>
 
* read analog input 0 once:
 
* read analog input 0 once:
 +
<pre class="apf">
 
  # time dd if=/dev/max1027/AIN0 bs=2 count=1 > tmp.bin
 
  # time dd if=/dev/max1027/AIN0 bs=2 count=1 > tmp.bin
 
  # hexdump tmp.bin
 
  # hexdump tmp.bin
 +
</pre>
  
 
This mode is activated by default in the Max1027 driver. If you switched to "slow" mode you can activate "fast" mode again with:
 
This mode is activated by default in the Max1027 driver. If you switched to "slow" mode you can activate "fast" mode again with:
 +
<pre class="apf">
 
  # let set=0x48; echo $set > /sys/bus/spi/devices/spi1.0/setup
 
  # let set=0x48; echo $set > /sys/bus/spi/devices/spi1.0/setup
 +
</pre>
  
 
===Chip registers configuration===
 
===Chip registers configuration===
 
Independent of the mode, ''/sys'' interfaces allow direct access to the corresponding register in the MAX1027:
 
Independent of the mode, ''/sys'' interfaces allow direct access to the corresponding register in the MAX1027:
 +
<pre class="apf">
 
  # let conv=0xb1; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
 
  # let conv=0xb1; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
 +
</pre>
  
 
You can also get current (hexadecimal) values of conversion, averaging and setup registers with (for example):
 
You can also get current (hexadecimal) values of conversion, averaging and setup registers with (for example):
 +
<pre class="apf">
 
  # cat /sys/bus/spi/devices/spi1.0/setup
 
  # cat /sys/bus/spi/devices/spi1.0/setup
 
  0x62
 
  0x62
 +
</pre>
  
 
For more details on how to use these registers, take a look at [[ADC_max1027#Links | the datasheet]].
 
For more details on how to use these registers, take a look at [[ADC_max1027#Links | the datasheet]].
Line 108: Line 146:
 
===Shell examples===
 
===Shell examples===
 
* Get channel 0 and temperature values:
 
* Get channel 0 and temperature values:
 +
<pre class="apf">
 
  # let conv=0x87; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
 
  # 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/temp1_input
 
  # cat /sys/class/hwmon/hwmon0/device/in0_input
 
  # cat /sys/class/hwmon/hwmon0/device/in0_input
 +
</pre>
  
 
* Get channels [0-6] and temperature values:
 
* Get channels [0-6] and temperature values:
 +
<pre class="apf">
 
  # let conv=0xb1; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
 
  # let conv=0xb1; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
 +
</pre>
  
 
* Get 4 average values (of 32 conversions) for channel 0:
 
* Get 4 average values (of 32 conversions) for channel 0:
 +
<pre class="apf">
 
  # let avg=0x3c; echo $avg > /sys/bus/spi/devices/spi1.0/averaging
 
  # let avg=0x3c; echo $avg > /sys/bus/spi/devices/spi1.0/averaging
 
  # let conv=0x84; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
 
  # let conv=0x84; echo $conv > /sys/bus/spi/devices/spi1.0/conversion
 +
</pre>
  
 
=Links=
 
=Links=

Revision as of 13:04, 3 February 2009

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:

figure 1 - MAX1027 localisation

If you don't have one and are a good electrician, 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.

figure 1 - MAX1027 connections

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 for example on the APF9328DevFull board you will have to connect:

  • pin 11 of ADC connector (right of the 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

Max1027 driver is now by default installed on standard rootfs so following instructions are only given as reference.

  • From the armadeus/ top directory:
 $ make linux26-menuconfig
  • Then select in
 Device Drivers  ---> 
    [*] SPI support  ---> 
        <M>   Freescale iMX SPI controller
  • If you want to have the hwmon compatible interface, select in
 Device Drivers  ---> 
    <M> Hardware Monitoring support (Module)
  • and then choose MAX1027 driver in
 Device Drivers  
    ---> Armadeus specific drivers  
        <M>   Armadeus Max1027 ADC driver (fast version)
  • Once the new configuration saved, rebuild your system:
 $ make

and copy hwmon.ko and max1027.ko driver to your target or reflash your rootfs.

Usage

On the target, the driver can be started like this:

 # modprobe spi_imx
 # modprobe max1027
 max1027 v0.3 successfully probed !

"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, ie accessing the Max1027 conversion register, after having configured setup register accordingly. So this interface is only suitable to measure slow evolving greats. Example:

 # let set=0x62; echo $set > /sys/bus/spi/devices/spi1.0/setup
 # let conv=0x87; echo $conv > /sys/bus/spi/devices/spi1.0/conversion    (launch 1 conversion of temp & AN0) 
 # cat /sys/bus/spi/devices/spi1.0/temp1_input
 32750   (m°C)
 # cat /sys/bus/spi/devices/spi1.0/in0_input
 1135    (mV)

"Fast" interface (frequencies > 10Hz)

CNVST pin is used to start the conversion, so you "only" have 7 analog inputs. 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 located in armadeus/target/linux/modules/max1027. As driver MAJOR number is dynamically allocated, you may need to update /dev depending on the drivers loaded on you system.

  • first, the conversion mode has to be chosen (channel 0->6 and temp):
 # let set=0xb1; echo $set > /sys/bus/spi/devices/spi1.0/conversion
  • and eventually the averaging and setup registers as well (refer to the max1027 documentation for more details):
 # let set=0x48; echo $set > /sys/bus/spi/devices/spi1.0/setup
 # let set=0x20; echo $set > /sys/bus/spi/devices/spi1.0/averaging
  • 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

This mode is activated by default in the Max1027 driver. If you switched to "slow" mode you can activate "fast" mode again with:

 # let set=0x48; echo $set > /sys/bus/spi/devices/spi1.0/setup

Chip registers configuration

Independent of the mode, /sys interfaces allow direct access to the corresponding register in the MAX1027:

 # let conv=0xb1; 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-6] and temperature values:
 # let conv=0xb1; 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 Flag.svg English  •  French Flag.svg Français