Difference between revisions of "EBC Exercise 10a Analog In"
m |
m (→Analog in - Continuous: Initial) |
||
Line 43: | Line 43: | ||
== Analog in - Continuous == | == Analog in - Continuous == | ||
+ | (This is based on information at: http://software-dl.ti.com/processor-sdk-linux/esd/docs/latest/linux/Foundational_Components/Kernel/Kernel_Drivers/ADC.html#Continuous%20Mode) | ||
+ | Reading a continuous analog signal requires some set up. First go to the iio devices directory. | ||
+ | bone$ '''cd /sys/bus/iio/devices/iio:device0''' | ||
+ | bone$ '''ls -F''' | ||
+ | buffer/ in_voltage0_raw in_voltage2_raw in_voltage4_raw in_voltage6_raw name power/ subsystem@ | ||
+ | dev in_voltage1_raw in_voltage3_raw in_voltage5_raw in_voltage7_raw of_node@ scan_elements/ uevent | ||
+ | |||
+ | Here you see the files used to read the one shot values. Look in '''scan_elements''' to see how to enable continuous input. | ||
+ | bone$ '''ls scan_elements''' | ||
+ | in_voltage0_en in_voltage1_index in_voltage2_type in_voltage4_en in_voltage5_index in_voltage6_type | ||
+ | in_voltage0_index in_voltage1_type in_voltage3_en in_voltage4_index in_voltage5_type in_voltage7_en | ||
+ | in_voltage0_type in_voltage2_en in_voltage3_index in_voltage4_type in_voltage6_en in_voltage7_index | ||
+ | in_voltage1_en in_voltage2_index in_voltage3_type in_voltage5_en in_voltage6_index in_voltage7_type | ||
+ | Here you see three values for each analog input, _en (enable), _index (index of this channel in the buffer’s chunks) | ||
+ | and _type (How the ADC stores its data). | ||
+ | (See the link above for details.) | ||
+ | |||
+ | Let's use the input at '''P9.40''' which is '''AIN1'''. To enable this input: | ||
+ | bone$ '''cd scan_elements''' | ||
+ | bone$ '''echo 1 > in_voltage1_en''' | ||
+ | Next set the buffer size. | ||
+ | bone$ '''cd ../buffer''' | ||
+ | bone$ '''ls''' | ||
+ | data_available enable length watermark | ||
+ | Let's use a 512 sample buffer. You might need to experiment with this. | ||
+ | bone$ '''echo 512 > length''' | ||
+ | Then start it running. | ||
+ | bone$ '''echo 1 > enable''' | ||
+ | Now, just read from '''/dev/iio:device0'''. | ||
{{YoderFoot}} | {{YoderFoot}} |
Revision as of 13:34, 28 July 2020
Embedded Linux Class by Mark A. Yoder
The Beagle has seven exposed analog inputs, numbered AIN0 to AIN6, on the P9 header. They are accessed through the Linux Industrial IO (iio) system (https://wiki.analog.com/software/linux/docs/iio/iio). They can be read either a sample at a time (One Shot) or in blocks of samples (Continous). One shot can be used to read the setting of a potentiometer, or an analog temperature sensor. The continuous mode is for reading a microphone or some other analog signal. With the proper configuration, the continuous input can read 12 bit samples at 200k samples/second.
Here's is how to use each.
Analog in - One Shot
(This is based on BeagleBone Black Analog Input.)
The bone has eight Analog Inputs; seven are exposed on P9, labeled AIN in table 11 below.
The AIN pins are sampled at 12 bits and 8k samples per second by default. The input voltage is between 0 and 1.8V. Fortunately, both analog ground (0V) and 1.8V are available on P9.
The photo below shows a small potentiometer wired to the bone. One end goes to the analog ground (pin 34), the other analog 1.8V (pin 32). The wiper is attached to AIN5 which is pin 36.
You interact with the analog in much like the gpio, but it appears in a different place.
bone$ cd /sys/bus/iio/devices/iio:device0 bone$ ls -F buffer/ in_voltage2_raw in_voltage6_raw power/ dev in_voltage3_raw in_voltage7_raw scan_elements/ in_voltage0_raw in_voltage4_raw name subsystem@ in_voltage1_raw in_voltage5_raw of_node@ uevent
There are the various analog inputs, in_voltage6_raw corresponds with AIN6
bone$ cat in_voltage6_raw 1185
Change the pot and rerun cat. What's the min and max value you get? Is it 12 bits?
Analog in - Continuous
(This is based on information at: http://software-dl.ti.com/processor-sdk-linux/esd/docs/latest/linux/Foundational_Components/Kernel/Kernel_Drivers/ADC.html#Continuous%20Mode)
Reading a continuous analog signal requires some set up. First go to the iio devices directory.
bone$ cd /sys/bus/iio/devices/iio:device0 bone$ ls -F buffer/ in_voltage0_raw in_voltage2_raw in_voltage4_raw in_voltage6_raw name power/ subsystem@ dev in_voltage1_raw in_voltage3_raw in_voltage5_raw in_voltage7_raw of_node@ scan_elements/ uevent
Here you see the files used to read the one shot values. Look in scan_elements to see how to enable continuous input.
bone$ ls scan_elements in_voltage0_en in_voltage1_index in_voltage2_type in_voltage4_en in_voltage5_index in_voltage6_type in_voltage0_index in_voltage1_type in_voltage3_en in_voltage4_index in_voltage5_type in_voltage7_en in_voltage0_type in_voltage2_en in_voltage3_index in_voltage4_type in_voltage6_en in_voltage7_index in_voltage1_en in_voltage2_index in_voltage3_type in_voltage5_en in_voltage6_index in_voltage7_type
Here you see three values for each analog input, _en (enable), _index (index of this channel in the buffer’s chunks) and _type (How the ADC stores its data). (See the link above for details.)
Let's use the input at P9.40 which is AIN1. To enable this input:
bone$ cd scan_elements bone$ echo 1 > in_voltage1_en
Next set the buffer size.
bone$ cd ../buffer bone$ ls data_available enable length watermark
Let's use a 512 sample buffer. You might need to experiment with this.
bone$ echo 512 > length
Then start it running.
bone$ echo 1 > enable
Now, just read from /dev/iio:device0.
Embedded Linux Class by Mark A. Yoder