Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /***************************************************************************** |
2 | * Filename: test_dac.c * |
||
3 | * Author: Marco Ziglioli (Doctor Stein) * |
||
4 | * Date: 12/06/2001 * |
||
5 | * Description: Little test program for Analog Output section of PCI6025E * |
||
6 | *----------------------------------------------------------------------------* |
||
7 | * Notes: Connect a multimeter to DAC1 output (pin 21) and watch * |
||
8 | * tension value. Use '+' and '-' on numeric pad to increase * |
||
9 | * and decrise voltage * |
||
10 | * With this program it's possible to point out possible * |
||
11 | * offset errors. To correct them no software are written but * |
||
12 | * in National board package there's the program to calibrate * |
||
13 | * the board. Otherwise you can see how much is the offset * |
||
14 | * and you can compensate it through software value * |
||
15 | *****************************************************************************/ |
||
16 | |||
17 | /* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it |
||
18 | * |
||
19 | * Copyright (C) 2001 Marco Ziglioli |
||
20 | * |
||
21 | * This program is free software; you can redistribute it and/or modify |
||
22 | * it under the terms of the GNU General Public License as published by |
||
23 | * the Free Software Foundation; either version 2 of the License, or |
||
24 | * (at your option) any later version. |
||
25 | * |
||
26 | * This program is distributed in the hope that it will be useful, |
||
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
29 | * GNU General Public License for more details. |
||
30 | * |
||
31 | * You should have received a copy of the GNU General Public License |
||
32 | * along with this program; if not, write to the Free Software |
||
33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
34 | * |
||
35 | */ |
||
36 | |||
37 | #include <drivers/glib.h> |
||
38 | #include <drivers/keyb.h> |
||
39 | #include <drivers/pci6025e/dac.h> |
||
40 | |||
41 | #define TASK_VOLT_PERIOD 150E3 |
||
42 | #define TASK_VOLT_WCET 080E3 |
||
43 | #define TASK_DAC_PERIOD 050E3 |
||
44 | #define TASK_DAC_WCET 020E3 |
||
45 | |||
46 | #define CONV 10/2048 |
||
47 | |||
48 | #define TASK_GROUP 1 |
||
49 | |||
50 | WORD dac0_value = 0, |
||
51 | dac1_value = 0; |
||
52 | |||
53 | BYTE sys = 0; |
||
54 | BYTE dac = 0; |
||
55 | |||
56 | //some colors |
||
57 | int black = rgb16(0, 0, 0), |
||
58 | white = rgb16(255, 255, 255); |
||
59 | |||
60 | void drawInterface(void); |
||
61 | void endfun(KEY_EVT *); |
||
62 | void inc(KEY_EVT *); |
||
63 | void dec(KEY_EVT *); |
||
64 | void change_dac(KEY_EVT *); |
||
65 | void close_event(void *); |
||
66 | TASK Voltage_body(int); |
||
67 | TASK DAC_Check_body(int); |
||
68 | |||
69 | int main(int argc, char **argv) |
||
70 | { |
||
71 | int modenum; |
||
72 | KEY_EVT k; |
||
73 | HARD_TASK_MODEL m, d; |
||
74 | PID pid_m, pid_d; |
||
75 | |||
76 | sys_atrunlevel(close_event, NULL, RUNLEVEL_BEFORE_EXIT); |
||
77 | |||
78 | keyb_set_map(itaMap); |
||
79 | k.flag = CNTR_BIT; |
||
80 | k.scan = KEY_X; |
||
81 | k.ascii = 'x'; |
||
82 | keyb_hook(k, endfun); |
||
83 | |||
84 | k.flag = CNTL_BIT; |
||
85 | keyb_hook(k, endfun); |
||
86 | |||
87 | k.flag = 0; |
||
88 | k.scan = 78; |
||
89 | k.ascii = 43; |
||
90 | keyb_hook(k, inc); |
||
91 | |||
92 | k.flag = 0; |
||
93 | k.scan = 74; |
||
94 | k.ascii = 45; |
||
95 | keyb_hook(k, dec); |
||
96 | |||
97 | k.flag = 0; |
||
98 | k.scan = KEY_V; |
||
99 | k.ascii = 'v'; |
||
100 | keyb_hook(k, change_dac); |
||
101 | |||
102 | hard_task_default_model(m); |
||
103 | hard_task_def_wcet(m, TASK_VOLT_WCET); |
||
104 | hard_task_def_mit(m, TASK_VOLT_PERIOD); |
||
105 | hard_task_def_group(m, TASK_GROUP); |
||
106 | pid_m = task_create("Voltage", Voltage_body, &m, NULL); |
||
107 | if(pid_m == NIL){ |
||
108 | sys = 30; |
||
109 | sys_end(); |
||
110 | } |
||
111 | |||
112 | hard_task_default_model(d); |
||
113 | hard_task_def_wcet(d, TASK_DAC_WCET); |
||
114 | hard_task_def_mit(d, TASK_DAC_PERIOD); |
||
115 | hard_task_def_group(d, TASK_GROUP); |
||
116 | pid_d = task_create("DAC Check", DAC_Check_body, &d, NULL); |
||
117 | if(pid_d == NIL){ |
||
118 | sys = 31; |
||
119 | sys_end(); |
||
120 | } |
||
121 | |||
122 | //Check if PCI bus is present |
||
123 | if(pci_init()==-1){ |
||
124 | sys = 10; |
||
125 | sys_end(); |
||
126 | } |
||
127 | //Check if a NI board is on PCI bus |
||
128 | if(!reMap()){ |
||
129 | sys = 11; |
||
130 | sys_end(); |
||
131 | } |
||
132 | |||
133 | if(grx_init()==-1){ |
||
134 | sys = 20; |
||
135 | sys_end(); |
||
136 | } |
||
137 | |||
138 | modenum = grx_getmode(800, 600, 16); |
||
139 | if(modenum == -1){ |
||
140 | sys = 21; |
||
141 | sys_end(); |
||
142 | } |
||
143 | grx_setmode(modenum); |
||
144 | |||
145 | drawInterface(); |
||
146 | |||
147 | //Analog output section set up |
||
148 | DAC_Init(); |
||
149 | |||
150 | /* |
||
151 | *AI_TIMEBASE div by 2; OUT_TIMEBASE div by 2; single DAC mode |
||
152 | *TMRDACWR = 3 OUT_TIMEBASE period; FIFO flags polarity active low |
||
153 | *TMRDACWR disabled; DMA PIO control = FIFO DATA interface mode |
||
154 | *UPDATE signal timebase = AO_UPDATE pulse width |
||
155 | *UPDATE pulsewidth = 3-3.5 OUT_TIMEBASE period |
||
156 | *UPDATE signal polarity = HIGH Z |
||
157 | */ |
||
158 | DAC_boardInit(0x02, 0x4000); |
||
159 | /* |
||
160 | *LDAC0 source = UPDATE |
||
161 | *DAC0 update immediately |
||
162 | *LDAC1 source = UPDATE |
||
163 | *DAC1 update immediately |
||
164 | */ |
||
165 | DAC_LDACSourceUpdate(0x00); |
||
166 | //End of Analog output section setup |
||
167 | |||
168 | group_activate(TASK_GROUP); |
||
169 | |||
170 | return 0; |
||
171 | } |
||
172 | |||
173 | /* |
||
174 | * Every time operator select a new value to send to a DAc this TASK makes |
||
175 | * actions needed to perform the operation |
||
176 | */ |
||
177 | TASK Voltage_body(int dac_work) |
||
178 | { |
||
179 | WORD old0_value, old1_value; |
||
180 | char buf[6]; |
||
181 | float volt; |
||
182 | |||
183 | old0_value = dac0_value; |
||
184 | old1_value = dac1_value; |
||
185 | while(1){ |
||
186 | if(dac){ |
||
187 | if(dac1_value != old1_value){ |
||
188 | DAC_output(DAC1, dac1_value); |
||
189 | old1_value = dac1_value; |
||
190 | sprintf(buf, "%04d", dac1_value); |
||
191 | grx_text(buf, 70, 120, rgb16(180, 0, 0), rgb16(255,255,140)); |
||
192 | sprintf(buf, "%04x", dac1_value); |
||
193 | grx_text(buf, 300, 120, rgb16(180, 0, 0), rgb16(255,255,140)); |
||
194 | if( (dac1_value & 0x0800) == 0 ) |
||
195 | volt = (float)dac1_value * (float)CONV; |
||
196 | else |
||
197 | volt = (float)(dac1_value-0x0FFF) * (float)CONV; |
||
198 | sprintf(buf, "%05.2f", volt); |
||
199 | grx_text(buf, 70, 177, rgb16(180, 40, 180), black); |
||
200 | } |
||
201 | } else { |
||
202 | if(dac0_value != old0_value){ |
||
203 | DAC_output(DAC0, dac0_value); |
||
204 | old0_value = dac0_value; |
||
205 | sprintf(buf, "%04d", dac0_value); |
||
206 | grx_text(buf, 521, 120, rgb16(180, 0, 0), rgb16(255,255,140)); |
||
207 | sprintf(buf, "%04x", dac0_value); |
||
208 | grx_text(buf, 754, 120, rgb16(180, 0, 0), rgb16(255,255,140)); |
||
209 | if( (dac0_value & 0x0800) == 0 ) |
||
210 | volt = (float)dac0_value * (float)CONV; |
||
211 | else |
||
212 | volt = (float)(dac0_value-0x0FFF) * (float)CONV; |
||
213 | sprintf(buf, "%05.2f", volt); |
||
214 | grx_text(buf, 521, 177, rgb16(180, 40, 180), black); |
||
215 | } |
||
216 | } |
||
217 | task_endcycle(); |
||
218 | } |
||
219 | } |
||
220 | |||
221 | /* |
||
222 | * This TASK show which is the DAC active |
||
223 | */ |
||
224 | TASK DAC_Check_body(int dummy) |
||
225 | { |
||
226 | BYTE old = dac; |
||
227 | char buf[8]; |
||
228 | |||
229 | while(1){ |
||
230 | if(dac != old){ |
||
231 | old = dac; |
||
232 | sprintf(buf, "DAC %d", dac); |
||
233 | grx_text(buf, 385, 90, rgb16(255*dac, 255*(1-dac), 0), black); |
||
234 | } |
||
235 | task_endcycle(); |
||
236 | } |
||
237 | } |
||
238 | |||
239 | void drawInterface(void) |
||
240 | { |
||
241 | grx_rect(1, 1, 799, 69, rgb16(105, 0, 0)); |
||
242 | grx_rect(2, 2, 798, 68, rgb16(155, 0, 0)); |
||
243 | grx_rect(3, 3, 797, 67, rgb16(205, 0, 0)); |
||
244 | grx_rect(4, 4, 796, 66, rgb16(255, 0, 0)); |
||
245 | |||
246 | grx_text("Test program for Analog output section of PCI6025E", |
||
247 | 7, 10, rgb16(50, 255, 50), black); |
||
248 | grx_text("Use '+' and '-' on numeric pad to change tension", |
||
249 | 7, 25, rgb16(0, 255, 255), black); |
||
250 | grx_text("Connect a tester to DAC1 output (pin21) or to DAC0 output (pin20)", |
||
251 | 7, 33, rgb16(0, 255, 255), black); |
||
252 | grx_text("Use 'v' to alternate change active DAC", |
||
253 | 7, 40, rgb16(0, 255, 255), black); |
||
254 | |||
255 | grx_text("CTRL-X for Exit", 7, 55, rgb16(200, 200, 0), black); |
||
256 | |||
257 | grx_rect(1, 80, 355, 150, rgb16(0, 105, 0)); |
||
258 | grx_rect(2, 81, 354, 149, rgb16(0, 155, 0)); |
||
259 | grx_rect(3, 82, 353, 148, rgb16(0, 205, 0)); |
||
260 | grx_rect(4, 83, 352, 147, rgb16(0, 255, 0)); |
||
261 | |||
262 | grx_rect(1, 160, 355, 199, rgb16(0, 105, 0)); |
||
263 | grx_rect(2, 161, 354, 198, rgb16(0, 155, 0)); |
||
264 | grx_rect(3, 162, 353, 197, rgb16(0, 205, 0)); |
||
265 | grx_rect(4, 163, 352, 196, rgb16(0, 255, 0)); |
||
266 | |||
267 | grx_rect(455, 80, 799, 150, rgb16(105, 105, 0)); |
||
268 | grx_rect(456, 81, 798, 149, rgb16(155, 155, 0)); |
||
269 | grx_rect(457, 82, 797, 148, rgb16(205, 205, 0)); |
||
270 | grx_rect(458, 83, 796, 147, rgb16(255, 255, 0)); |
||
271 | |||
272 | grx_rect(455, 160, 799, 199, rgb16(105, 105, 0)); |
||
273 | grx_rect(456, 161, 798, 198, rgb16(155, 155, 0)); |
||
274 | grx_rect(457, 162, 797, 197, rgb16(205, 205, 0)); |
||
275 | grx_rect(458, 163, 796, 196, rgb16(255, 255, 0)); |
||
276 | |||
277 | grx_rect(360, 80, 450, 105, rgb16(85, 85, 255)); |
||
278 | grx_rect(361, 81, 449, 104, rgb16(125, 125, 255)); |
||
279 | grx_rect(362, 82, 448, 103, rgb16(175, 175, 255)); |
||
280 | grx_rect(363, 83, 447, 102, rgb16(225, 225, 255)); |
||
281 | |||
282 | grx_rect(153, 93, 195, 103, rgb16(255, 0, 0)); |
||
283 | grx_text("DAC 1", 155, 95, rgb16(255, 170, 170), black); |
||
284 | |||
285 | grx_rect(607, 93, 649, 103, rgb16(255, 0, 0)); |
||
286 | grx_text("DAC 0", 609, 95, rgb16(255, 255, 210), black); |
||
287 | |||
288 | grx_text("Decimal", 7, 120, rgb16(120, 120, 255), black); |
||
289 | grx_text("Hexadecimal", 200, 120, rgb16(120, 120, 255), black); |
||
290 | grx_text("Tension", 7, 177, rgb16(120, 120, 255), black); |
||
291 | |||
292 | grx_text("Decimal", 461, 120, rgb16(255, 120, 120), black); |
||
293 | grx_text("Hexadecimal", 654, 120, rgb16(255, 120, 120), black); |
||
294 | grx_text("Tension", 461, 177, rgb16(255, 120, 120), black); |
||
295 | } |
||
296 | |||
297 | void close_event(void *arg) |
||
298 | { |
||
299 | grx_close(); |
||
300 | switch(sys){ |
||
301 | case 0 : cprintf("Regular End\n"); break; |
||
302 | case 1 : cprintf("End fun invoked\n"); break; |
||
303 | case 10: cprintf("Pci bus not found\n"); break; |
||
304 | case 11: cprintf("No National board found\n"); break; |
||
305 | case 20: cprintf("Cannot initialize graphic envirorment\n"); break; |
||
306 | case 21: cprintf("Cannot start envirorment in 800x600x16\n"); break; |
||
307 | case 30: cprintf("Cannot create task <voltage>\n"); break; |
||
308 | case 31: cprintf("Canot create task <DAC Check>\n"); break; |
||
309 | case 40: cprintf("Break on clock end event\n"); break; |
||
310 | default: cprintf("Unkwon exit event\n"); break; |
||
311 | } |
||
312 | } |
||
313 | |||
314 | void endfun(KEY_EVT *k) |
||
315 | { |
||
316 | sys = 1; |
||
317 | sys_end(); |
||
318 | } |
||
319 | |||
320 | /* |
||
321 | * Capture correct key event and increase output tension of active DAC |
||
322 | */ |
||
323 | void inc(KEY_EVT *k) |
||
324 | { |
||
325 | if(dac){ |
||
326 | if( (dac1_value & 0x0800) == 0 && dac1_value > 0x07FF ) |
||
327 | dac1_value = 0; |
||
328 | else |
||
329 | dac1_value++; |
||
330 | } else { |
||
331 | if( (dac0_value & 0x0800) == 0 && dac0_value > 0x07FF ) |
||
332 | dac0_value = 0; |
||
333 | else |
||
334 | dac0_value++; |
||
335 | } |
||
336 | } |
||
337 | |||
338 | /* |
||
339 | * Same as above but decrease tension |
||
340 | */ |
||
341 | void dec(KEY_EVT *k) |
||
342 | { |
||
343 | if(dac){ |
||
344 | if(dac1_value < 1) |
||
345 | dac1_value = 0x0FFF; |
||
346 | else |
||
347 | dac1_value -= 1; |
||
348 | } else { |
||
349 | if(dac0_value < 1) |
||
350 | dac0_value = 0x0FFF; |
||
351 | else |
||
352 | dac0_value -= 1; |
||
353 | } |
||
354 | } |
||
355 | |||
356 | /* |
||
357 | * Capture correct key event and change active DAC |
||
358 | */ |
||
359 | void change_dac(KEY_EVT *k) |
||
360 | { |
||
361 | if(dac) dac = 0; |
||
362 | else dac = 1; |
||
363 | } |
||
364 |