Bb_black_ Study Notes-(7) ADC experiment

Source: Internet
Author: User

On the basis of the previous note, complete a simple ADC sampling experiment.

The first step: preparation of knowledge

1, first look at the Bb_black ADC pin position. Is the distribution of the analog input ports of the bb_black.

There are three important messages to note on this chart:

(1) Number of analog input ports: ARM chip A total of 8 ADC channels, the Bb_black is led out of 7 pins, ain0~6;

(2) voltage range of analog input port: 0~1.8v;

(3) Number of bits converted by ADC: 12 bits;

2, with the Eclipse development environment, you can easily view the directory structure of the Development Board. As shown in the directory structure of the Development Board:

The BBB Board ADC requires two directories:

(1)/sys/devices/bone_capemgr.8/ loading the directory of the ADC device tree, some versions may be bone_capemgr.9 or other numbers, depending on their own board;

(2)/sys/bus/iio/devices/ This directory is the device data directory after the ADC device is loaded, reading the ADC data is this in the main directory;

3, in order to perform ADC sampling, it is necessary to use a device to simulate a simulated amount, the author uses the common Sliding rheostat, as shown in:

Note:

(1) There are three pins in the sliding rheostat, where the middle pin is the sliding end, that is, the intermediate pins need to be connected to the analog input pins of the Development Board. Then the other two pins are connected with an analog reference voltage pin and a simulated ground pin;

(2) in the experimental process, the author chooses a type 3296 sliding rheostat with 100K;

Step two: Connect the hardware

1, the hardware connection of this experiment is very simple, only need to use three wires to connect the sliding rheostat with the Bb_black three pins.

2. The attached hardware is as follows:

Note: The AIN0 port is used by the author in the experiment.

Step three: Manually view ADC conversion data

1. Open Character terminal

2. Load ADC Device command: Echo BB-ADC >/sys/devices/bone_capemgr.8/slots

3. Enter the directory/sys/bus/iio/devices, and then view the file list

4. Enter the directory:

Note: In_voltage0_raw, In_voltage1_raw to In_voltage7_raw a total of 8 files is the BBB Board 8 ADC PIN values, you can use the Cat command to see the values below.

5. View ADC values:

Note:

(1) The value of each reading should be small deviation;

(2) 3446 is the value of the ADC conversion;

Fourth step: Read the ADC data by programming

1, create a new file, as shown in the My home file to build a own folder, and then right-click to create a new file.

2, the new Remote file prompt box as follows, enter the name of the new file adc.c

3, click OK after you can see the file in the directory structure of the author, and then double-click Open can be edited under Eclipse

4. Enter the following code

1#include <stdlib.h>2#include <stdio.h>3#include <string.h>4#include <fcntl.h>5#include <unistd.h>6 #defineSysfs_adc_dir "/sys/bus/iio/devices/iio:device0/in_voltage0_raw"7 #defineSysfs_adc_dev "/sys/devices/bone_capemgr.8/slots"8 #defineMAX_BUF 649 intMain ()Ten {  OneFILE *fd=NULL; A     Chara[Ten];  -     intx; -     floatADC; the  -Fd=fopen (Sysfs_adc_dir,"W");  -     if(Fd==null)/*load ADC If no files are executed*/  -     {  +Fd=fopen (Sysfs_adc_dev,"W");  -Fwrite"BB-ADC",sizeof(int),6, FD);/*BB-ADC has 6 characters*/  + fclose (FD); A     }  at      for(;;)  -     {  -Fd=fopen (Sysfs_adc_dir,"r+");  -FSCANF (FD,"%s", a);  -printf"%s", a);  -         if(Strlen (a) = =4)  in         {  -X= ((int) a[0]- -)* ++((int) a[1]- -)* -+((int) a[2]- -)*Ten+((int) a[3]- -);  to         }  +         Else if(Strlen (a) = =3)  -         {  theX= ((int) a[0]- -)* -+((int) a[1]- -)*Ten+((int) a[2]- -);  *         }  $         Else if(Strlen (a) = =2) Panax Notoginseng         {  -X= ((int) a[0]- -)*Ten+((int) a[1]- -);  the         }  +         Else  A         {  theX= ((int) a[0]- -);  +         }  -Adc= ((float) x/4095.0)*1.8;  $printf"adc=%4f\n", ADC);  $ fclose (FD); -Sleep1);  -     }  the     return 0;  -}

Note:

(1) Linux under the operation of the device to change the operation of the file, so the ADC experiment is also the corresponding files to operate;

(2) strlen (a) Get a number

5, editing must remember to save the file, otherwise the compilation will be the last file, as shown in saving the file

6, find the new file in the character terminal and compile the file, the Compile command is: Arm-angstrom-linux-gnueabi-gcc–o ADC ADC.C

7, after the completion of the compilation can run the results of the compilation:./ADC

8. Observe the ADC's numerical changes by rotating the sliding rheostat.

Bb_black_ Study Notes-(7) ADC experiment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.