1 | /* dacbuff.c Demonstration program for WinSystems PCM-MIO Driver */ |
---|
2 | |
---|
3 | /* |
---|
4 | * |
---|
5 | * $Id$ |
---|
6 | * |
---|
7 | * |
---|
8 | * Compile for GNU/Linux with: |
---|
9 | * |
---|
10 | * gcc dacbuff.c kbhit.c mio_io.o -o dacbuff |
---|
11 | * |
---|
12 | * |
---|
13 | * This program demonstrates the adc_buffered_channel_conversions function |
---|
14 | * which allows for a programmed sequence of conversions to be accomplished |
---|
15 | * with a single call. |
---|
16 | */ |
---|
17 | |
---|
18 | #include "mio_io.h" |
---|
19 | #include <stdio.h> |
---|
20 | #include <stdlib.h> |
---|
21 | |
---|
22 | // This array will store the results of 2000 conversions |
---|
23 | |
---|
24 | unsigned char commands[16385]; |
---|
25 | unsigned short values[16384]; |
---|
26 | |
---|
27 | void init_keyboard(void); |
---|
28 | void close_keyboard(void); |
---|
29 | int kbhit(void); |
---|
30 | int readch(void); |
---|
31 | |
---|
32 | |
---|
33 | int main(int argc, char* argv[]) |
---|
34 | { |
---|
35 | unsigned x; |
---|
36 | |
---|
37 | |
---|
38 | // Set all 8 DAC outputs to a known span +/- 10V |
---|
39 | |
---|
40 | for(x=0; x<8; x++) |
---|
41 | { |
---|
42 | set_dac_span(x, DAC_SPAN_BI10); |
---|
43 | if(mio_error_code) |
---|
44 | { |
---|
45 | printf("\n%s\n",mio_error_string); |
---|
46 | exit(1); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | // For this program we are going to use only channel 0 |
---|
52 | // with 16384 updates. |
---|
53 | |
---|
54 | |
---|
55 | // The data will step up from -10V to +10V in 4/65536 increments |
---|
56 | |
---|
57 | for(x = 0; x < 16384; x++) |
---|
58 | { |
---|
59 | commands[x] = 0; |
---|
60 | values[x] = x * 4; |
---|
61 | } |
---|
62 | |
---|
63 | /* We need to terminate the command so that it knows when its done */ |
---|
64 | |
---|
65 | commands[16384] = 0xff; |
---|
66 | |
---|
67 | |
---|
68 | /* This program runs until a key is pressed. It prints nothing |
---|
69 | on the screen to keep from slowing it down. To see the results |
---|
70 | it would be necessary to attach an oscilloscope to DAC channel |
---|
71 | 0. |
---|
72 | */ |
---|
73 | |
---|
74 | init_keyboard(); |
---|
75 | |
---|
76 | printf("DACBUFF running - press any key to exit\n"); |
---|
77 | |
---|
78 | while(!kbhit()) |
---|
79 | { |
---|
80 | |
---|
81 | /* This command returns when all 16,384 samples have been |
---|
82 | sent to the DAC as fast as possible |
---|
83 | */ |
---|
84 | |
---|
85 | buffered_dac_output(commands,values); |
---|
86 | if(mio_error_code) |
---|
87 | { |
---|
88 | printf("\n%s\n",mio_error_string); |
---|
89 | exit(2); |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | readch(); |
---|
96 | close_keyboard(); |
---|
97 | return 0; |
---|
98 | } |
---|
99 | |
---|