DAS  3.1.6 - 18/09/2017
Dscad.c
Go to the documentation of this file.
1 //=============================================================================
2 // File: DSCADSample.c v2.0
3 // Desc: Sample program that demonstrates how to take an AD sample
4 // Date: 9/7/01 KL
5 //(c) Copyright 2001 Diamond Systems Corporation. Use of this source code
6 //is subject to the terms of Diamond Systems' Software License Agreement.
7 //Diamond Systems provides no warranty of proper performance if this
8 //source code is modified.
9 //=============================================================================
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <conio.h>
13 #include <math.h>
14 #include "mgui.h"
15 #include "DAS_Spatram.h"
16 #include "dscud.h"
17 
18 
19 
20 // macros defined
21 #define ERROR_PREFIX "DMM Driver ERROR:"
22 
23 
29 // var declarations
30 BYTE result; // returned error code
31 DSCB dscb; // handle used to refer to the board
32 DSCCB dsccb; // structure containing board settings
33 DSCADSETTINGS dscadsettings; // structure containing A/D conversion settings
34 DSCADSCAN dscadscan; // structure containing A/D scan settings
35 WORD* samples; // sample readings
36 double voltage; // actual voltage
38 extern int Incr_Read_Temp;
39 
40 DSCAIOINT dscaioint; // structure containing auto-calibration settings
41 DSCS dscs; // used for interrupts.
42 
44 
45 void D_readtemp_int(void);
46 
47 
48 void DSCAD_Error(char *err, int w)
49 {
50  MOBJECT sh, lbl;
51  char buf[64];
52  sh = MCreateShell("AD Error", 0);
54 
55  sprintf(buf, "%d ) %s",w, err);
56  lbl = MCreateLabel(sh, buf, HELV_SMALL);
59  MObjectSetShadow(lbl, WS_SHADOW_OUT, 1, 0);
60  MShellRealize(sh);
61 }
62 
63 
64 void D_rt(void)
65 {
66 
68 
69 }
70 
71 void D_readtemp_int(void)
72 {
73 
74  int i;
75 //=========================================================================
76 // V. SCANNING AND OUTPUT
77 //
78 // Perform the actual sampling and then output the results. To calculate
79 // the actual input voltages, we must convert the sample code (which
80 // must be cast to a short to get the correct code) and then plug it
81 // into one of the formulas located in the manual for your board (under
82 // "A/D Conversion Formulas").
83  //=========================================================================
84 
85 
86  if( ( result = dscADScan( dscb, &dscadscan, samples ) ) != DE_NONE )
87  {
88 // fprintf( stderr, "%s%s\n", ERROR_PREFIX, dscGetErrorString( result ) );
89 // free( samples ); // remember to deallocate malloc() memory
90 // return;
91  }
92 
93  for( i = dscadscan.low_channel; i < dscadscan.high_channel + 1; i++)
94  {
95  if( dscadsettings.range == RANGE_10 && dscadsettings.polarity == BIPOLAR)
96  {
97  voltage = ((short)dscadscan.sample_values[i] / 2048.0 * 10.0) - 10.0;
98  }
99  else if( dscadsettings.range == RANGE_5 && dscadsettings.polarity == BIPOLAR )
100  {
101  voltage = ((short)dscadscan.sample_values[i] / 2048.0 * 5.0 ) - 5.0;
102  }
103  else if( dscadsettings.range == RANGE_5 && dscadsettings.polarity == UNIPOLAR )
104  voltage = ( (short)dscadscan.sample_values[i] / 4096.0) * 5.0;
105  else voltage = ( (short)dscadscan.sample_values[i] / 4096.0) * 10.0;
106 
107  OMUTHR.ADVolt[i] = (voltage / pow(2, dscadsettings.gain));
108  }
109 }
110 
111 
112  int D_InitPC104(void)
121 {
122  //=========================================================================
123  // I. DRIVER INITIALIZATION
124  //
125  // Initializes the DSCUD library.
126  //
127  // Initialize the driver, using the driver version for validation
128  //=========================================================================
129 
130  if( dscInit( DSC_VERSION ) != DE_NONE )
131  {
132  dscGetLastError(&errorParams);
133  DSCAD_Error(errorParams.errstring, 2);
134  return 1;
135  }
136 
137  //=========================================================================
138  // II. BOARD INITIALIZATION
139  //
140  // Initialize the DMM board. This function passes the various
141  // hardware parameters to the driver and resets the hardware.
142  //
143  //=========================================================================
144 
145  dsccb.boardtype = DSC_DMM;
146  dsccb.base_address = 0x300;
147  dsccb.int_level = 3;
148  dsccb.dma_level = 3;
149  dsccb.clock_freq = 1000000;
150 
151  if(dscInitBoard(DSC_DMM, &dsccb, &dscb)!= DE_NONE)
152  {
153  dscGetLastError(&errorParams);
154  DSCAD_Error(errorParams.errstring, 2);
155  return 1;
156  }
157 
158  //=========================================================================
159  // III. AD SETTINGS INITIALIZATION
160  //
161  // Initialize the structure containing the AD conversion settings and
162  // then pass it to the driver.
163  //
164  //=========================================================================
165 
166  // PRE-FILLED EXAMPLE
167  dscadsettings.range = RANGE_5;
168  dscadsettings.polarity = UNIPOLAR;
169  dscadsettings.gain = GAIN_1;
170  dscadsettings.load_cal = (BYTE)TRUE;
171  dscadsettings.current_channel = 0;
172 
173  if( ( result = dscADSetSettings( dscb, &dscadsettings ) ) != DE_NONE )
174  {
175  dscGetLastError(&errorParams);
176  DSCAD_Error(errorParams.errstring, 2);
177  return 2;
178  }
179 
180  //=========================================================================
181  // IV. AD SCAN INITIALIZATION
182  //
183  // Initialize the structure containing the AD scan setting and allocate
184  // memory for our buffer containing sample values.
185  //
186  //=========================================================================
187 
188  // PRE-FILLED EXAMPLE
189  dscadscan.low_channel = 0;
190  dscadscan.high_channel = 15;
191  dscadscan.gain = dscadsettings.gain;
192 
193  samples = (WORD*)malloc( sizeof( WORD ) * ( dscadscan.high_channel - dscadscan.low_channel + 1 ) );
194 
195  return 0;
196 
197 }
198 
199 
200 
201 
202 
203 
DSCADSCAN dscadscan
Definition: Dscad.c:34
void DSCAD_Error(char *err, int w)
Definition: Dscad.c:48
void MObjectSetBackgroundRGB(MOBJECT obj, int r, int g, int b)
WORD * samples
Definition: Dscad.c:35
MOBJECT lbl
Definition: DFileMan.c:42
WORD base_address
Definition: DSCUD.H:353
void MObjectSetShadow(MOBJECT obj, int type, int in, int out)
BYTE DSCUDAPICALL dscADSetSettings(DSCB board, DSCADSETTINGS *settings)
BYTE range
Definition: DSCUD.H:433
BYTE current_channel
Definition: DSCUD.H:431
void MShellRealize(MOBJECT obj)
#define RANGE_10
Definition: DSCUD.H:190
Definition: DSCUD.H:340
BYTE DSCUDAPICALL dscGetLastError(ERRPARAMS *errparams)
MOBJECT MCreateLabel(MOBJECT parent, const char *text, MTFont font)
BYTE polarity
Definition: DSCUD.H:434
Definition: DSCUD.H:595
short DB_BG_Albl[3]
Background ACTIVE Label Colors.
ERRPARAMS errorParams
Definition: Dscad.c:37
#define DSC_VERSION
Definition: DSCUD.H:155
BYTE load_cal
Definition: DSCUD.H:435
DSCCB dsccb
Definition: Dscad.c:32
palette DPAL
Definition: 2DPlot.c:27
char * errstring
Definition: DSCUD.H:479
#define WORD
Definition: DSCUD.H:65
double voltage
Definition: Dscad.c:36
#define DSCB
Definition: DSCUD.H:140
BYTE dma_level
Definition: DSCUD.H:354
#define HELV_SMALL
Definition: Mguidefs.h:881
BYTE DSCUDAPICALL dscInitBoard(BYTE boardtype, DSCCB *dsccb, DSCB *board)
LONG clock_freq
Definition: DSCUD.H:355
#define GAIN_1
Definition: DSCUD.H:195
DSCB dscb
Definition: Dscad.c:31
BYTE gain
Definition: DSCUD.H:432
BYTE boardtype
Definition: DSCUD.H:346
short DB_FG_Albl[3]
Foreground ACTIVE Label Colors.
omuthr OMUTHR
Definition: Dscad.c:43
BYTE gain
Definition: DSCUD.H:451
MOBJECT MCreateShell(const char *title, int flags)
#define DE_NONE
Definition: DSCUD.H:273
DSCADSETTINGS dscadsettings
Definition: Dscad.c:33
short DB_BG[3]
Default Background Color.
#define RANGE_5
Definition: DSCUD.H:189
int D_InitPC104(void)
Starting function that calls the driver functions used NOTE: By convention, you should capture the BY...
Definition: Dscad.c:120
Function prototypes.
BYTE low_channel
Definition: DSCUD.H:448
#define UNIPOLAR
Definition: DSCUD.H:193
BYTE result
Definition: Dscad.c:30
BYTE DSCUDAPICALL dscADScan(DSCB board, DSCADSCAN *dscadscan, DSCSAMPLE *sample_values)
BYTE high_channel
Definition: DSCUD.H:449
int Incr_Read_Temp
Definition: DAS_Spat.c:101
#define BIPOLAR
Definition: DSCUD.H:192
#define TRUE
Definition: DSCUD.H:105
#define BYTE
Definition: DSCUD.H:55
void * MOBJECT
Definition: Mguidefs.h:192
DSCS dscs
Definition: Dscad.c:41
void D_rt(void)
D_readtemp_int callback .
Definition: Dscad.c:64
#define DSC_DMM
Definition: DSCUD.H:165
BYTE int_level
Definition: DSCUD.H:360
void MObjectSetForegroundRGB(MOBJECT obj, int r, int g, int b)
DSCAIOINT dscaioint
Definition: Dscad.c:40
double ADVolt[16]
PC104 AD samples reading array.
OMU Thermoregulation structure .
DSCSAMPLE * sample_values
Definition: DSCUD.H:450
#define WS_SHADOW_OUT
Definition: Mguidefs.h:957
void D_readtemp_int(void)
Definition: Dscad.c:71
BYTE DSCUDAPICALL dscInit(WORD version)
______________________________________________________________________________________
Generated on Mon Sep 18 2017 11:44:08 for DAS - Rel. 3.1.6 - 18/09/2017.