Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1197 giacomo 1
/*****************************************************************************
2
* Filename:       osc.c                                                      *
3
* Author:         Ghiro Andrea,Franchino Gianluca                            *
4
* Date:           09/2003                                                    *
5
* Description:    Oscilloscope and function generator for PCI6025E           *
6
*----------------------------------------------------------------------------*
7
* Notes:          Connect DAC output pin (21) to ADC input pins (3-18) and   *
8
*                 watch the waveforms.                                       *
9
*****************************************************************************/
10
 
11
/* This file is part of the S.Ha.R.K. Project - http://shark.sssup.it
12
 *
13
 * Copyright (C) 2003 Ghiro Andrea,Franchino Gianluca
14
 *
15
 * This program is free software; you can redistribute it and/or modify
16
 * it under the terms of the GNU General Public License as published by
17
 * the Free Software Foundation; either version 2 of the License, or
18
 * (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU General Public License
26
 * along with this program; if not, write to the Free Software
27
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
 *
29
 */
30
 
31
 
32
#include <drivers/glib.h>
33
#include <drivers/keyb.h>
34
#include <math.h>
35
#include <drivers/pci6025e/dac.h>
36
#include <modules/hartport.h>
37
#include <modules/srp.h>
38
#include "adc.h"
39
 
40
#define  MAX_VAL         500
41
#define  NUM_POINT        20
42
#define  GRAPH_PERIOD  50000
43
#define  GRAPH_WCET     2000
44
#define  WAVE_WCET       200
45
#define  OSC_WCET        200
46
#define  TASK_GROUP        1
47
#define  CHFREQ_PERIOD  5000
48
#define  CHFREQ_WCET     200
49
 
50
void drawInterface(void);
51
void endfun(KEY_EVT *);
52
void close_event(void *);
53
void createWaves(void);
54
void change_disp(KEY_EVT *);
55
void change_mode(KEY_EVT *);
56
void change_wave(KEY_EVT *);
57
void change_passo(KEY_EVT *);
58
void change_channel(KEY_EVT *);
59
void inc(KEY_EVT *);
60
void dec(KEY_EVT *);
61
 
62
TASK video_body(int);
63
TASK wave_body(int);
64
TASK osc_body(int);
65
TASK chfreq_body(int);
66
 
67
HARD_TASK_MODEL    wave0;
68
HARD_TASK_MODEL    chfreq;
69
HARD_TASK_MODEL    osc;
70
SRP_RES_MODEL      r;
71
SRP_mutexattr_t    a;
72
 
73
PID wave0_pid;
74
PID chfreq_pid;
75
PID osc_pid;
76
 
77
mutex_t m1 ;
78
 
79
int black = rgb16(0,0,0),
80
    white = rgb16(255, 255, 255);
81
 
82
int wave    = 3,
83
    varfun  = 0,
84
    varosc  = 0,
85
    flagch  = 0,
86
    channel = 0;
87
 
88
float vfun = 0,
89
      vosc = 2.5,
90
      ffun = 1,
91
      tbase = 75,
92
      yr[MAX_VAL],
93
      yrdac[NUM_POINT],
94
      ys[MAX_VAL],
95
      ysdac[NUM_POINT],
96
      yq[MAX_VAL],
97
      yqdac[NUM_POINT];
98
 
99
BYTE disp   = 0,
100
     modefun= 0,
101
     modeosc= 0,
102
     lib    = 0,
103
     sys    = 0;
104
 
105
short yoscold[MAX_VAL];
106
 
107
unsigned int period= 1e6/NUM_POINT;
108
unsigned int oscperiod = 1500;
109
 
110
int main(int argc, char **argv)
111
{
112
   KEY_EVT  k;
113
 
114
   HARD_TASK_MODEL    video;
115
   PID video_pid;
116
 
117
   int modenum;
118
 
119
   k.flag  =  CNTR_BIT;
120
   k.scan  =  KEY_X;
121
   k.ascii =  'x';
122
   keyb_hook(k, endfun);
123
 
124
   k.flag  =  CNTL_BIT;
125
   keyb_hook(k, endfun);
126
 
127
   k.flag  =  0;
128
   k.scan  =  KEY_A;
129
   k.ascii =  'a';
130
   keyb_hook(k, change_disp);
131
 
132
   k.flag  =  0;
133
   k.scan  =  KEY_S;
134
   k.ascii =  's';
135
   keyb_hook(k, change_mode);
136
 
137
   k.flag  =  0;
138
   k.scan  =  KEY_F;
139
   k.ascii =  'f';
140
   keyb_hook(k, change_wave);
141
 
142
   k.flag  =  0;
143
   k.scan  =  KEY_G;
144
   k.ascii =  'g';
145
   keyb_hook(k, change_wave);
146
 
147
   k.flag  =  0;
148
   k.scan  =  KEY_H;
149
   k.ascii =  'H';
150
   keyb_hook(k, change_wave);
151
 
152
   k.flag  =  0;
153
   k.scan  =  KEY_D;
154
   k.ascii =  'd';
155
   keyb_hook(k, change_passo);
156
 
157
   k.flag  =  0;
158
   k.scan  =  KEY_J;
159
   k.ascii =  'j';
160
   keyb_hook(k, change_channel);
161
 
162
   k.flag  =  0;
163
   k.scan  =  78;
164
   k.ascii =  43;
165
   keyb_hook(k, inc);
166
 
167
   k.flag  =  0;
168
   k.scan  =  74;
169
   k.ascii =  45;
170
   keyb_hook(k, dec);
171
 
172
   sys_atrunlevel(close_event, NULL, RUNLEVEL_BEFORE_EXIT);
173
 
174
   /*initialize the srp mutex*/
175
   SRP_mutexattr_default(a);
176
   mutex_init(&m1,&a);
177
 
178
   hard_task_default_model(wave0);
179
   hard_task_def_wcet(wave0, WAVE_WCET);
180
   hard_task_def_mit(wave0, period);
181
   hard_task_def_group(wave0, TASK_GROUP);
182
   if( (wave0_pid = task_create("Wave 0", wave_body, &wave0, NULL)) == NIL )
183
      {
184
      sys = 10;
185
      sys_end();
186
      }
187
 
188
   hard_task_default_model(video);
189
   hard_task_def_wcet(video, GRAPH_WCET);
190
   hard_task_def_mit(video, GRAPH_PERIOD);
191
   hard_task_def_group(video, TASK_GROUP);
192
   SRP_res_default_model(r,2);
193
   if( (video_pid = task_createn("Video task", video_body, &video, &r,
194
      SRP_usemutex(&m1), NULL))== NIL )
195
      {
196
      sys = 12;
197
      sys_end();
198
      }
199
 
200
   hard_task_default_model(osc);
201
   hard_task_def_wcet(osc, OSC_WCET);
202
   hard_task_def_mit(osc, oscperiod);
203
   hard_task_def_group(osc, TASK_GROUP);
204
   SRP_res_default_model(r,1);
205
   if((osc_pid = task_createn("osc task", osc_body, &osc, &r,
206
      SRP_usemutex(&m1), NULL))== NIL )
207
      {
208
      sys = 11;
209
      sys_end();
210
      }
211
 
212
   hard_task_default_model(chfreq);
213
   hard_task_def_wcet(chfreq, CHFREQ_WCET);
214
   hard_task_def_mit(chfreq, CHFREQ_PERIOD);
215
   hard_task_def_group(chfreq, TASK_GROUP);
216
   if( (chfreq_pid = task_create("chfreq", chfreq_body, &chfreq, NULL)) == NIL )
217
      {
218
      sys = 13;
219
      sys_end();
220
      }
221
 
222
   if(grx_init() == -1)
223
      {
224
      sys = 30;
225
      sys_end();
226
      }
227
 
228
   if((modenum = grx_getmode(800, 600, 16)) == -1)
229
      {
230
      sys = 31;
231
      sys_end();
232
      }
233
 
234
   if(pci_init() == -1)
235
      {
236
      sys = 20;
237
      sys_end();
238
      }
239
 
240
   if(!reMap())
241
      {
242
      sys = 21;
243
      sys_end();
244
      }
245
 
246
   grx_setmode(modenum);
247
 
248
   createWaves();
249
   drawInterface();
250
 
251
   DAC_Init();                  //Program the DAQ-STC AOTM
252
   Configure_Board(channel);    //Configure the board with the channel settings.
253
   ADC_Init();                  //Program the DAQ-STC AITM
254
 
255
   group_activate(TASK_GROUP);
256
 
257
   return 0;
258
}
259
 
260
void endfun(KEY_EVT *k)
261
{
262
   sys_end();
263
}
264
 
265
void close_event(void *arg)
266
{
267
   grx_close();
268
   switch(sys)
269
     {
270
     case 0:  cprintf("Regular End!\n"); break;
271
     case 10: cprintf("Cannot create <wave 0> task!\n"); break;
272
     case 11: cprintf("Cannot create <osc> task!\n"); break;
273
     case 12: cprintf("Cannot create <video> task!\n"); break;
274
     case 13: cprintf("Cannot create <chfreq> task!\n"); break;
275
     case 14: cprintf("Cannot kill <wave 0> task!\n"); break;
276
     case 15: cprintf("Cannot kill <osc> task\n");break;
277
     case 20: cprintf("No PCI bus found!\n"); break;
278
     case 21: cprintf("No NATIONAL PCI E-Series board found on PCI bus!\n");break;
279
     case 30: cprintf("Cannot start graphic envirorment!\n"); break;
280
     case 31: cprintf("800x600x16 video mode not supported!\n");break;
281
     default: cprintf("Unknown exit event!\n"); break;
282
     }
283
}
284
 
285
/*
286
* kill wave0 or osc when frequency change
287
*/
288
 
289
TASK chfreq_body(int w)
290
{
291
   PORT p;
292
   char msg[1];
293
   p = port_create("activation",1,1,STREAM,WRITE);
294
 
295
   while(1)
296
     {
297
     if(flagch == 1)
298
       {
299
       if(task_kill(wave0_pid)!=0)
300
         {
301
         sys=14;
302
         sys_end();
303
         }
304
       hard_task_def_mit(wave0, period);
305
       if( (wave0_pid = task_create("wave 0", wave_body, &wave0, NULL))== NIL )
306
         {
307
         sys = 10;
308
         sys_end();
309
         }
310
       flagch = 0;
311
       task_activate(wave0_pid);
312
       }
313
 
314
     if(flagch == 2)
315
       {
316
       if(task_kill(osc_pid)!=0)
317
         {
318
         sys=15;
319
         sys_end();
320
         }
321
       hard_task_def_mit(osc, oscperiod);
322
       if( (osc_pid = task_createn("osc", osc_body, &osc, &r,
323
          SRP_usemutex(&m1), NULL))== NIL )
324
         {
325
         sys = 11;
326
         sys_end();
327
         }
328
       flagch = 0;
329
       msg[0]=1;
330
       port_send(p,msg,NON_BLOCK);
331
       }
332
    task_endcycle();
333
    }
334
}
335
 
336
/*
337
* acquisition of input samples
338
*/
339
 
340
TASK osc_body(int wv)
341
{
342
   int i = 0 ;
343
   short y = 0;
344
   WORD Status = 0;
345
 
346
   while(1)
347
     {
348
     mutex_lock(&m1);
349
     if(lib)
350
       {
351
       mutex_unlock(&m1);
352
       AI_Start_The_Acquisition();
353
       do {
354
          Status = DAQ_STC_Windowed_Mode_Read(AI_STATUS_1);
355
          if (!( (Status & 0x1000) == 0x1000 ) )
356
          y = Immediate_Readw(ADC_DATA_READ);
357
          } while(((Status & 0x1000) == 0x1000));
358
       y = (2.5/vosc)*(y-40)/20;
359
       if(abs(y)<=100)
360
         {
361
         grx_plot(19+i,483-y,rgb16(255,255,0));
362
         }
363
       yoscold[i]=y;
364
       i=(i+1)%500;
365
       if(i==0)
366
         {
367
          mutex_lock(&m1);
368
          lib=0;
369
          mutex_unlock(&m1);
370
          task_testcancel();
371
         }
372
      }
373
    else  mutex_unlock(&m1);
374
    task_endcycle();
375
    }
376
}
377
 
378
/*
379
* Sends out waves' samples
380
*/
381
 
382
TASK wave_body(int wv)
383
{
384
   int i = 0;
385
   int y = 0;
386
   while(1)
387
     {
388
     if(wave==0)
389
       {
390
       y=vfun*(yrdac[i]*20);
391
       y=(y & 0x0FFF);
392
       }
393
     if(wave==1)
394
       {
395
       y=vfun*(ysdac[i]*20);
396
       y=(y & 0x0FFF);
397
       }
398
     if(wave==2)
399
       {
400
       y=vfun*(yqdac[i]*20);
401
       y=(y & 0x0FFF);
402
       }
403
     DAC_output(DAC1,y);
404
     i = (i + 1) % NUM_POINT;
405
     task_testcancel();
406
     task_endcycle();
407
     }
408
}
409
 
410
/*
411
* Shows setting,wave,grid and clear display
412
*/
413
 
414
TASK video_body(int dummy)
415
{                                
416
   BYTE dispold    = 1,
417
        modefunold = 1,  
418
        modeoscold = 1,      
419
        new        = 0;
420
 
421
   int  waveold    = 3,
422
        varfunold  = 2,
423
        i          = 0,
424
        y          = 0,
425
        channelold = 16,
426
        yold[MAX_VAL];
427
 
428
 
429
   float vfunold = 1,
430
         voscold = 1,
431
         ffunold = 0,
432
         tbaseold = 1;
433
 
434
   char st[20];
435
 
436
   PORT p;
437
   char msg[1];
438
   p=port_connect("activation",1,STREAM,READ);
439
 
440
    while(1)
441
      {
442
      mutex_lock(&m1);
443
      if(!lib)
444
        {
445
        mutex_unlock(&m1);
446
        for(i=0;i<MAX_VAL;i++)
447
          {
448
          if(abs(yoscold[i])<=100)
449
            {
450
            grx_plot(19+i,483-yoscold[i],rgb16(0,0,0));
451
            }
452
          }
453
        //OSCILLOSCOPE GRID
454
        grx_line(19, 385, 519, 385, rgb16(150,150,150));
455
        grx_line(19, 410, 519, 410, rgb16(150,150,150));
456
        grx_line(19, 435, 519, 435, rgb16(150,150,150));
457
        grx_line(19, 460, 519, 460, rgb16(150,150,150));
458
        grx_line(19, 485, 519, 485, rgb16(150,150,150));
459
        grx_line(19, 510, 519, 510, rgb16(150,150,150));
460
        grx_line(19, 535, 519, 535, rgb16(150,150,150));
461
        grx_line(19, 560, 519, 560, rgb16(150,150,150));
462
        grx_line(19, 585, 519, 585, rgb16(150,150,150));
463
        grx_line(19, 385, 19, 585, rgb16(150,150,150));
464
        grx_line(69, 385, 69, 585, rgb16(150,150,150));
465
        grx_line(119, 385, 119, 585, rgb16(150,150,150));
466
        grx_line(169, 385, 169, 585, rgb16(150,150,150));
467
        grx_line(219, 385, 219, 585, rgb16(150,150,150));
468
        grx_line(269, 385, 269, 585, rgb16(150,150,150));
469
        grx_line(319, 385, 319, 585, rgb16(150,150,150));
470
        grx_line(369, 385, 369, 585, rgb16(150,150,150));
471
        grx_line(419, 385, 419, 585, rgb16(150,150,150));
472
        grx_line(469, 385, 469, 585, rgb16(150,150,150));
473
        grx_line(519, 385, 519, 585, rgb16(150,150,150));
474
        mutex_lock(&m1);
475
        lib=1;
476
        mutex_unlock(&m1);
477
        port_receive(p,msg,NON_BLOCK);
478
        if(msg[0]==1)
479
          {
480
          task_activate(osc_pid);
481
          }
482
        }
483
        else mutex_unlock(&m1);
484
      if(disp != dispold)
485
        {
486
        dispold = disp;
487
        grx_disc(780,120,10,rgb16(255*(1-disp),0,0));
488
        grx_disc(780,390,10,rgb16(0,255*disp,0));
489
        }        
490
 
491
      if(modefun != modefunold)
492
        {
493
        modefunold = modefun;
494
        grx_disc(780,237,5,rgb16(255*(1-modefun),0,0));
495
        grx_disc(780,267,5,rgb16(255*(modefun),0,0));
496
        }        
497
 
498
      if(modeosc != modeoscold)
499
        {
500
        modeoscold = modeosc;
501
        grx_disc(780,502,5,rgb16(0,255*(1-modeosc),0));
502
        grx_disc(780,532,5,rgb16(0,255*(modeosc),0));
503
        }        
504
 
505
      if(wave != waveold)
506
        {
507
        waveold = wave;
508
        grx_disc(730,127,3,rgb16(127*(1-wave)*(2-wave),0,0));  
509
        grx_disc(730,142,3,rgb16(254*wave*(2-wave),0,0));  
510
        grx_disc(730,157,3,rgb16(254*wave*(wave-1),0,0));  
511
        new=1;
512
        }        
513
 
514
      if(varfun != varfunold)
515
        {
516
        varfunold = varfun;
517
        grx_disc(675,292,3,rgb16(42*(1-varfun)*(2-varfun)*(3-varfun),0,0));  
518
        grx_disc(775,292,3,rgb16(126*varfun*(2-varfun)*(3-varfun),0,0));  
519
        grx_disc(675,307,3,rgb16(252*varfun*(varfun-1)*(3-varfun),0,0));  
520
        grx_disc(775,307,3,rgb16(42*varfun*(varfun-1)*(varfun-2),0,0));  
521
        }        
522
 
523
 
524
      if(channel != channelold)
525
        {
526
        sprintf(st,"%2d",channel);
527
        grx_text("  ",660,470,black,white);
528
        grx_text(st,660,470,black,white);
529
        }
530
 
531
      if(ffun != ffunold)
532
        {
533
        ffunold = ffun;
534
        sprintf(st,"%10f",ffun);
535
        grx_text("          ",660,265,black,white);
536
        grx_text(st,660,265,black,white);
537
        }        
538
 
539
      if(tbase != tbaseold)
540
        {
541
        tbaseold = tbase;
542
        sprintf(st,"%10f",tbase);
543
        grx_text("          ",660,530,black,white);
544
        grx_text(st,660,530,black,white);
545
        }        
546
 
547
      if(vfun != vfunold)
548
        {
549
        vfunold = vfun;
550
        sprintf(st,"%3.1f",vfun);
551
        grx_text("     ",660,235,black,white);
552
        grx_text(st,660,235,black,white);
553
        new=1;
554
        }        
555
 
556
      if(vosc != voscold)
557
        {
558
        voscold = vosc;
559
        sprintf(st,"%3.1f",vosc);
560
        grx_text("     ",660,500,black,white);
561
        grx_text(st,660,500,black,white);
562
        }        
563
 
564
      if(new)
565
        {
566
        for(i=0; i<MAX_VAL; i++)
567
          {
568
          grx_plot(19+i, 215-yold[i],rgb16(0, 0, 0));
569
          }
570
 
571
      //FUNCTION GENERATOR GRID
572
        grx_line(22, 115, 525, 115, rgb16(150,150,150));
573
        grx_line(22, 165, 525, 165, rgb16(150,150,150));
574
        grx_line(22, 265, 525, 265, rgb16(150,150,150));
575
        grx_line(22, 315, 525, 315, rgb16(150,150,150));
576
        grx_line(19, 110, 19, 320, rgb16(150,150,150));
577
        grx_line(14, 215, 525, 215, rgb16(150,150,150));
578
 
579
        if(wave==0)
580
          {
581
          for(i=0;i<MAX_VAL;i++)
582
            {
583
            y=(vfun)*yr[i];
584
            grx_plot(19+i,215-y,rgb16(255,255,0));
585
            yold[i]=y;
586
            }
587
          }
588
 
589
        if(wave==1)
590
          {
591
          for(i=0;i<MAX_VAL;i++)
592
            {
593
            y=(vfun)*ys[i];
594
            grx_plot(19+i,215-y,rgb16(255,255,0));
595
            yold[i]=y;
596
            }
597
          }
598
 
599
        if(wave==2)
600
          {
601
          for(i=0;i<MAX_VAL;i++)
602
            {
603
            y=(vfun)*yq[i];
604
            grx_plot(19+i,215-y,rgb16(255,255,0));
605
            yold[i]=y;
606
            }
607
          }
608
 
609
          new=0;  
610
      }
611
      task_endcycle();
612
      }
613
}                          
614
 
615
/*
616
* create wave triangular,sinusoidal and square
617
*/
618
 
619
void createWaves(void)
620
{
621
   float  u=0,
622
          qdac= 2*PI/NUM_POINT,
623
          q = 2*PI/(MAX_VAL/2);
624
 
625
   register int i;
626
 
627
   BYTE direction=0;    
628
/*create the vectors for the video task*/
629
   for(i=0;i<MAX_VAL/2;i++)
630
      {                
631
      yr[i]=yr[i+MAX_VAL/2]=u/10;
632
      if(!direction)   u += 1.613;
633
      else             u -= 1.613;
634
      if(u >= 100)    direction = 1;
635
      if(u <= -101)   direction = 0;
636
 
637
      ys[i]=ys[i+MAX_VAL/2] = (sin(i*q)*10);
638
 
639
      if((i>=(MAX_VAL/4) && i< (MAX_VAL/2))) yq[i]=yq[i+MAX_VAL/2]=0;
640
      else yq[i]=yq[i+MAX_VAL/2]=10;
641
      }
642
/*create the vectors for the wave_body task*/
643
   direction=0;
644
   u = 0;
645
   for(i=0;i<NUM_POINT;i++)
646
      {
647
      yrdac[i]=u/10;
648
      if(!direction)  u += (400/NUM_POINT);
649
      else            u -= (400/NUM_POINT);
650
      if(u >= 100)    direction = 1;
651
      if(u <= -100)   direction = 0;
652
 
653
      ysdac[i]=(sin(i*qdac)*10);
654
 
655
      if((i>=(NUM_POINT/2) && i<NUM_POINT)) yqdac[i]=0;
656
      else yqdac[i]=10;
657
      }
658
}  
659
 
660
/*
661
* select device (0 function generator,1 oscilloscope)
662
*/
663
 
664
void change_disp(KEY_EVT *k)
665
{
666
   if(disp)  disp = 0;
667
   else      disp = 1;
668
}
669
 
670
/*
671
* select volt or frequency
672
*/
673
 
674
void change_mode(KEY_EVT *k)
675
{
676
   if(disp && modeosc)  modeosc = 0;
677
   else      
678
   if(disp && !modeosc) modeosc = 1;
679
   else  
680
   if(!disp && modefun) modefun = 0;
681
   else
682
   if(!disp && !modefun) modefun =1;
683
}
684
 
685
/*
686
* select wave (0 triangular,1 sinusoindal,2 square
687
*/
688
 
689
void change_wave(KEY_EVT *k)
690
{
691
  if(!disp && k->ascii =='f')
692
    {
693
    wave=0;
694
    }
695
  else
696
  if(!disp && k->ascii =='g')
697
    {
698
    wave=1;
699
    }
700
  else
701
  if(!disp && k->ascii =='h')
702
    {
703
    wave=2;
704
    }
705
}
706
 
707
/*
708
* select increase or decrease step
709
*/
710
 
711
void change_passo(KEY_EVT *k)
712
{
713
   if(!disp && modefun)
714
     {
715
     varfun=(varfun+1)%2;
716
     }
717
}
718
 
719
/*
720
* select input channel
721
*/
722
 
723
void change_channel(KEY_EVT *k)
724
{
725
   if(disp)
726
     {
727
     channel=(channel+1)%16;
728
     Configure_Board(channel);
729
     }
730
}
731
 
732
/*
733
* increase selected variable
734
*/
735
 
736
void inc(KEY_EVT *k)
737
{
738
   if(disp && modeosc && tbase<300)
739
     {
740
     flagch=2;
741
     switch(varosc)
742
        {
743
        case(0): tbase = tbase*2;
744
        oscperiod=(tbase/50)*1000;
745
        break;
746
        }
747
     }
748
   else
749
   if(disp && !modeosc && vosc<10) vosc += 0.1;
750
   else
751
   if(!disp && modefun && ffun<(1e6/(1020*NUM_POINT))-1)
752
     {
753
     flagch=1;
754
     switch(varfun)
755
        {
756
        case(0):  ffun += 1;
757
                  period = 1e6/(NUM_POINT*ffun);
758
                  break;
759
        case(1): ffun += 10;
760
                 period = 1e6/(NUM_POINT*ffun);
761
                 break;
762
        }
763
     }
764
   else
765
   if(!disp && !modefun && vfun<10) vfun += 0.1;
766
}
767
 
768
/*
769
* decrease selected variable
770
*/
771
 
772
void dec(KEY_EVT *k)
773
{
774
   if(disp && modeosc && tbase> 75)
775
     {
776
     flagch=2;
777
     switch(varosc)
778
        {
779
        case(0): tbase = tbase/2;
780
        oscperiod=(tbase/50)*1000;
781
        break;
782
        }
783
     }
784
   else      
785
   if(disp && !modeosc && vosc> 0.2) vosc -= 0.1;
786
   else  
787
   if(!disp && modefun && ffun> 0)
788
     {
789
     flagch = 1;
790
     switch(varfun)
791
        {
792
        case(0): ffun -= 1;
793
                 if(ffun == 0) period =1e6;
794
                 else
795
                 period = 1e6/(NUM_POINT*ffun);
796
                 break;
797
        case(1): ffun -= 10;
798
                 if(ffun == 0) period =1e6;
799
                 else
800
                 period = 1e6/(NUM_POINT*ffun);
801
                 break;
802
        }
803
     }
804
   else
805
   if(!disp && !modefun && vfun> -10) vfun -= 0.1;
806
}
807
 
808
/*
809
* draw interface
810
*/
811
 
812
void drawInterface(void)
813
{
814
   //TITLE
815
   grx_rect(1, 1, 799, 69, rgb16(105, 0, 105));
816
   grx_rect(2, 2, 798, 68, rgb16(155, 0, 155));
817
   grx_rect(3, 3, 797, 67, rgb16(205, 0, 205));
818
   grx_rect(4, 4, 796, 66, rgb16(255, 0, 255));
819
   grx_text("Oscilloscope and function generator for PCI6025E",7, 10, rgb16(50, 255, 50), black);
820
   grx_text("Pin ADC 3-18, DAC 21",7, 25, rgb16(0, 255, 255), black);
821
   grx_text("A for select Oscilloscope or Function generator",7, 40, rgb16(0, 255, 255), black);
822
   grx_text("CTRL-X for Exit", 7, 55, rgb16(200, 200, 0), black);
823
 
824
   //FUNCTION GENERATOR
825
   grx_text("FUNCTION GENERATOR", 100, 92, rgb16(200, 200, 0), black);
826
   grx_rect(1, 100, 549, 325, rgb16(0, 105, 0));
827
   grx_rect(2, 101, 548, 324, rgb16(0, 155, 0));
828
   grx_rect(3, 102, 547, 323, rgb16(0, 205, 0));
829
   grx_rect(4, 103, 546, 322, rgb16(0, 255, 0));
830
   grx_rect(579, 100, 799, 325, rgb16(0, 105, 0));
831
   grx_rect(580, 101, 798, 324, rgb16(0, 155, 0));
832
   grx_rect(581, 102, 797, 323, rgb16(0, 205, 0));
833
   grx_rect(582, 103, 796, 322, rgb16(0, 255, 0));
834
   grx_text("Wave selection",589,110,rgb16(0, 255, 0), black);
835
   grx_text("f -->triangular",589,125,rgb16(200, 200, 0), black);
836
   grx_text("g -->sin",589,140,rgb16(200, 200, 0), black);
837
   grx_text("h -->square",589,155,rgb16(200, 200, 0), black);
838
   grx_text("s -->select volt/freq",589,180,rgb16(200, 200, 0), black);
839
   grx_text("+/- -->set volt/freq",589,195,rgb16(200, 200, 0), black);
840
   grx_text("d -->frequency increase",589,210,rgb16(200, 200, 0),black);
841
   grx_text("Vpicco               V",589,235,rgb16(0, 255, 0),black);
842
   grx_text("Freq                 Hz",589,265,rgb16(0, 255, 0),black);
843
   grx_text("+/- 1   Hz",589,290,rgb16(0, 255, 0),black);
844
   grx_text("+/- 10  HZ",689,290,rgb16(0, 255, 0),black);
845
 
846
   //OSCILLOSCOPE
847
   grx_text("OSCILLOSCOPE", 100, 362, rgb16(200, 200, 0), black);
848
   grx_rect(1, 370, 549, 595, rgb16(105, 0, 0));
849
   grx_rect(2, 371, 548, 594, rgb16(155, 0, 0));
850
   grx_rect(3, 372, 547, 593, rgb16(205, 0, 0));
851
   grx_rect(4, 373, 546, 592, rgb16(255, 0, 0));
852
   grx_rect(579, 370, 799, 595, rgb16(105, 0, 0));
853
   grx_rect(580, 371, 798, 594, rgb16(155, 0, 0));
854
   grx_rect(581, 372, 797, 593, rgb16(205, 0, 0));
855
   grx_rect(582, 373, 796, 592, rgb16(255, 0, 0));
856
   grx_text("Scale selection",589,380,rgb16(255, 0, 0), black);
857
   grx_text("s -->select volt/freq",589,400,rgb16(200, 200, 0), black);
858
   grx_text("+/- -->set volt/freq",589,415,rgb16(200, 200, 0), black);
859
   grx_text("j -->change channel",589,430,rgb16(200, 200, 0),black);
860
   grx_text("Channel",589,470,rgb16(255, 0, 0),black);
861
   grx_text("Volt/div             V",589,500,rgb16(255, 0, 0),black);
862
   grx_text("Time/div             ms",589,530,rgb16(255, 0, 0),black);
863
 
864
   //LABEL
865
   grx_text("0 V", 555, 211, rgb16(0, 255, 0), black);
866
   grx_text("+10", 555, 111, rgb16(0, 255, 0), black);
867
   grx_text("+5", 555, 161, rgb16(0, 255, 0), black);
868
   grx_text("-5", 555, 261, rgb16(0, 255, 0), black);
869
   grx_text("-10", 555, 311, rgb16(0, 255 , 0), black);
870
   grx_text("0 V", 555, 481, rgb16(255, 0, 0), black);
871
}