source: multiio/pcmmio/original/getall.c @ 1cbabbe

Last change on this file since 1cbabbe was 1cbabbe, checked in by Joel Sherrill <joel.sherrill@…>, on 06/17/09 at 20:34:51

2009-06-17 Joel Sherrill <joel.sherrill@…>

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