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