source: multiio/pcmmio/original/getall.c @ da59d43

Last change on this file since da59d43 was 2bae2aa, checked in by Joel Sherrill <joel.sherrill@…>, on 06/08/09 at 14:52:43

Initial import.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/* getall.c Demonstration program for use with the WinSystems PCM-MIO Linux driver
2*
3*       $Header$
4*
5*       $Id$
6*
7*       $Log$
8*
9*       Compile with :
10*
11*                       gcc -static getall.c mio_io.o -o getall
12*/
13
14#include <stdio.h>
15#include <stdlib.h>
16#include "mio_io.h"
17
18/* This program demonstrates usage of the adc_convert_all_channels function call.
19   This allows for all 16 channels to be quickly converted and the results passed
20   back in an 16 element array. Note that this function does not return voltage values,
21   it returns raw 16-bit data directly from the converter.
22*/
23
24
25/* This array will receive the result values for all 16 channels */
26
27unsigned short values[16];
28
29int main(void)
30{
31int channel;
32unsigned short result;
33float current;
34
35                /* We set the mode on all 16 channels to single-ended bipolar +/- 10V scale.
36                   This allows for any device legal input voltages.
37                */
38               
39                for(channel=0; channel < 16; channel++)
40                {                       
41                        adc_set_channel_mode(channel,ADC_SINGLE_ENDED,ADC_BIPOLAR,ADC_TOP_10V);
42                       
43                        /* Check for an error by loooking at mio_error_code */
44                       
45                        if(mio_error_code)
46                        {
47                                /* If an error occurs, print out the string and exit */
48
49                                printf("%s - Aborting\n",mio_error_string);
50                                exit(1);
51                        }
52                }
53               
54                /* This is it! When this function returns the values from all 8 channels
55                           will be present in the values array.
56                */
57                       
58                adc_convert_all_channels(values);
59                       
60                /* Check for possible errors */
61                       
62                if(mio_error_code)
63                {
64                        printf("%s - Aborting\n",mio_error_string);
65                        exit(1);
66                }       
67                       
68                /* Now we'll extract the data, convert it to volts, and display the results */
69                       
70                for(channel =0; channel <16; channel++)
71                {
72                        /* This is for print formatting */
73
74                        if(channel == 4 || channel == 8 || channel == 12)
75                                printf("\n");
76                       
77                        /* Get a result from the array */
78                               
79                        result = values[channel];
80                       
81                        /* Convert the raw value to voltage */
82
83                        current = adc_convert_to_volts(channel,result);
84
85                        /* Display the result */
86                                               
87                        printf("CH%2d%8.4f | ",channel,current);
88                }
89               
90                printf("\n\n");
91}
Note: See TracBrowser for help on using the repository browser.