That is the worst documentation I've ever seen!!! It is incorrect and imcomplete. Notice the "GOSUB 550" in the test program - there is no line 550!!
You could never get A/D to work with that kind of documentation.
From you questions:
1) Yep, that's a "typing error". This is how they sample and convert.
2) "(C/16 - INT (C/16)) * 16" is just taking the lower nibble (4 bits) of C. This is because it's a 12bit A/D (4 bits in the hight byte and 8 bits in the low byte)
3) Well, I found the German version of the documentation!!! And it has Pascal and C source! I've attached the documentation I found. It looks like this documentation had several "typing error's" as well, but I combined all the info together to come up with something that hopefully is correct.
Code:
#include <iostream.h>
#include <dos.h>
//convenient types
typedef unsigned short WORD;
typedef unsigned char BYTE;
//Port# card if configured for
const WORD PORT = 0x278;
//Millisecond delay to use during conversion...
//this was used in the Pascal version of the code, I would reduce this # until
//it stops working correctly
const WORD MS_DELAY = 100;
//Function to perform A/D conversion on given channel (0-15)
WORD ad(BYTE channel);
int main()
{
for (BYTE n = 0; n < 16; n++)
{
cout << "A/D on channel " << n << " is " << ad(n) << endl;
}
return 0;
}
WORD ad(BYTE channel)
{
//check parameter
if (channel > 15)
channel = 15;
//select channel
outportb(PORT,channel);
//clear register
outportb(PORT+3,0);
//perform sampling/conversion
int i;
for (i = 0; i < 5; i++)
{
inportb(PORT+4);
delay(MS_DELAY);
}
for (i = 0; i < 9; i++)
{
inportb(PORT+5);
delay(MS_DELAY);
}
//return lower 12bits of result
return inport(PORT+1) & 0x0FFF;
}
gg