source: multiio/pcmmio/buffered.c @ 13bdbee

base
Last change on this file since 13bdbee was 13bdbee, checked in by Joel Sherrill <joel.sherrill@…>, on 03/17/11 at 15:04:30

Initial import.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/* buffered.c Demonstration program for WinSystems PCM-MIO Driver */
2
3/*
4*
5* $Id$
6*
7* Compile for GNU/Linux with:
8*
9*   gcc buffered.c kbhit.c mio_io.o -o buffered -lpthread
10*
11*
12*  This program demonstrates the adc_buffered_channel_conversions function
13*  which allows for a programmed sequence of conversions to be accomplished
14*  with a single call.
15*/
16
17/* Our IOCTL definitions and all function prototypes */
18
19#include "mio_io.h"   
20
21#include <stdio.h>
22#include <stdlib.h>
23
24/* This array will hold 2000 channel numbers plus a terminating 0xff charcter */
25
26unsigned char to_do_channels[2001];
27
28/* This array will store the results of 2000 conversions */
29
30unsigned short values[2000];
31
32/* Keyboard support function prototypes */
33
34void init_keyboard(void);
35void close_keyboard(void);
36int kbhit(void);
37int readch(void);
38
39
40int main(int argc, char* argv[])
41{
42int channel = 0;
43unsigned short result;
44float current;
45unsigned long count = 0;
46int x;
47
48        /* Set up all 16 channels for the +/- 10 Volt range */
49
50        for(channel =0; channel < 16; channel ++)
51        {
52                adc_set_channel_mode(channel,ADC_SINGLE_ENDED,ADC_BIPOLAR,ADC_TOP_10V);
53                if(mio_error_code)
54                {
55                        printf("\nError occured - %s\n",mio_error_string);
56                        exit(1);
57                }
58        }
59
60        /* We'll fill the to_do list with the four different channels 500
61          each successively.
62    */
63
64        for(x=0; x < 500; x++)
65        {
66                to_do_channels[x] = 0;
67                to_do_channels[x+500] = 1;
68                to_do_channels[x+1000] = 2;
69                to_do_channels[x+1500] = 3;
70
71        }
72
73        /* Load the "terminator" into the last position */
74
75        to_do_channels[2000] = 0xff;
76
77        /*  We'll keep going until a key is pressed */
78
79        init_keyboard();
80
81        while(!kbhit())
82        {
83                /* Start up the conversions. This function returns when all 2000 of
84             our conversions are complete.
85            */
86
87                adc_buffered_channel_conversions(to_do_channels,values);
88               
89                count += 2000;
90
91                if(mio_error_code)
92                {
93                        printf("\nError occured - %s\n",mio_error_string);
94                        exit(1);
95                }
96
97                /* We'll extract our data from the "values" array. In order to make the
98                 display more readable, we'll take a value from each channel display them,
99                 and move to the next result.
100                */
101
102                for(x=0; x < 500; x++)
103                {
104                        printf("%08ld  ",count);
105
106                        /* Get the raw data */
107
108                        result = values[x];
109
110                        /* Convert to voltage */
111
112                        current = adc_convert_to_volts(0, result);
113
114                        /* Display the value */
115
116                        printf("CH0 %9.5f ",current);
117
118                        /* Repeat for channels 1 - 3  */
119
120                        result = values[x+500];
121                        current = adc_convert_to_volts(1, result);
122                        printf("CH1 %9.5f ",current);
123
124                        result = values[x+1000];
125                        current = adc_convert_to_volts(2, result);
126                        printf("CH2 %9.5f ",current);
127                       
128                        result = values[x+1500];
129                        current = adc_convert_to_volts(3, result);
130                        printf("CH3 %9.5f ",current);
131                        printf("\r");
132                }
133        }
134        readch();
135        printf("\n\n");
136        close_keyboard();
137        return 0;
138}
Note: See TracBrowser for help on using the repository browser.