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 | |
---|
25 | unsigned short values[16]; |
---|
26 | |
---|
27 | int main(void) |
---|
28 | { |
---|
29 | int channel; |
---|
30 | unsigned short result; |
---|
31 | float 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 | } |
---|