FidoNet Echomail Archive
aust_c_here

<<< Previous Index Next >>>

From: Steve McCauley
To: All
Date: 1997-03-12 19:42:24
Subject: ADDA Blues (inp)

Hi,
        I have recently written a C program to test the functionality of an
AD/DA board. Output control using the outp function is working ok (checked
with a multimeter), but reading of input values (output pin wired to the
(channel 15) input pin) is a problem. Output data is listed in the next
message. I believe that my C code is at fault since the same program (more
or less) written in BASIC produces good data, i.e, read data values within
40 units of output data values where data is calculated as:
                DATA = (HiB - 64 * HiB / 64) * 256 - LoB.

        I have included most of the program below in the hope that someone
will spot the obvious flaw. I apologise since it is fairly closely type...
particularly since I wanted to fully comment it.

        The problem may well be with the read function: (int) inp
(unsigned). My complier (Microsoft QuickC 2.5) asks for a .def file and
makes omenous mention of segments on several occasions (as quoted below). I
suspect that I have left out some vital bit relating to segements,
underscores or protected-mode (whatever that might be). I have however
constructed the .def file with the required line in it plus a couple more
about heapsize and stacksize.

                        thanks in advance for any help

                                Steve

PS I hope everybody notices the absence of chewed tabs in the .c and the
        data file! I'm still damp in the eyes after solving that.
        (QEdit | Other | eXpand tabs to spaces)

QC HELP: INP
         You must use a .DEF file to declare the IOSEG segment that the
         run-time library uses to perform input/output on the port. In
         addition, the intrinsic (/Oi) versions of these functions do not
         work unless you put the code in a segment marked with the IOPL
         keyword in the .DEF file.

         Since you cannot do IOPL from a regular code segment, the run-time
         library has declared a separate code segment called _IOSEG. In
         order to use any of these functions in any of the protected-mode
         run-time libraries (?LIBCP, LLIBCDLL, LLIBCMT, or CDLLOBJS-based
         DLL), you must have a .DEF file containing the following line:

                  SEGMENTS _IOSEG CLASS 'IOSEG_CODE' IOPL
QD11.C
#include <stdio.h>
#include <conio.h>

const unsigned int    PORT = 368;

int main()
{   ... initializations.
...
fTable = fopen("qd11.dat", "a+");
for ( i = 1; i < 64; ++i )  /* output voltages from 10/63v to 10/1v     */
  {
  LBo = outp(PORT + 4, 0);        /* set low byte output value = 0        */
  HBo = outp(PORT + 5, i);        /* set high byte output value = 1..63   */
  DataOut = (HBo - 64 * (HBo / 64)) * 256 + LBo;  /* calc output data     */
  Vout = (float)DataOut / 16383.0 * 10.07;        /* calc output volts    */
                ...print data headings to file...
  for ( j = 1; j < 11 ; ++j ) /* take 10 readings at each voltage */
        {
        rv1 = outp(PORT + 1, 0);        /* clear channel register */
        rv2 = outp(PORT, 15);           /* output read channel number */
        for (k = 1; k < 9; ++k)
                {
                v = inp(PORT + 12);     /* High byte AD conversion */
                }
        for (k = 1; k < 9; ++k)
                {
                v = inp(PORT + 10);     /* Low byte AD conversion  */
                }
        LBi = inp(PORT + 2);            /* Read low byte */
        HBi = inp(PORT + 3);            /* Read high byte */
        DataIn = (HBi - 64 * (HBi / 64)) * 256 + LBi;  /* calc data */
        DiDo = DataIn - DataOut;        /* calc diff between inp & out data */
        Vin = (float)DataIn / 16383.0 * 10.07;   /* calc input volts */
        fprintf( fTable, "%d\t%d\t%d\t%d\t%d\t%.3f\t%d\n",
              HBo, HBi, LBo, LBi, DataIn, Vin, DiDo ); /* print to file */
        }
  }
fclose(fTable);
}

---
 * Origin: Melbourne PC User Group BBS (3:632/309)
SEEN-BY: 3/103 50/99 54/99 620/243 623/630 632/50 107 108 158 309 348 360 371
SEEN-BY: 632/504 525 533 535 562 633/374 635/544 728 639/252 640/820 711/413
SEEN-BY: 711/430 934 712/311 407 505 506 517 623 624 704 841 713/317 714/906
SEEN-BY: 800/1
@PATH: 632/309 107 360 50/99 712/624 711/934


<<< Previous Index Next >>>