I'm trying to reverse engineer an old program in Borland C++ that we use in a PC/104 running DOS. There's a physical switch with 18 taps on the front panel that inputs a different voltage (between 0 and 5V) into an analog input that is used to determine which channel the program is looking at.
I'm trying to figure out how the program determines which channel it's looking at, then modify it so that based on a switch setting the program can work with either 18 channels or 24.
EDIT: What I'd like to know is, how does the program interpret the different voltages from the 18 position switch and know which channel is what?
Here is a look at the switch that selects one of the 18 channels. The voltage changes approximately 300mV per channel. (Ch1= 0V, Ch2= .296V, Ch3= .59V, Ch4= .884V,... Ch16= 4.41V, Ch17= 4.71, Ch18= 5.0V) 18 channel switch
Installing a 24 channel switch would change the voltage on each tap to increments of approximately 200mV.
Thanks for the help!
Here's the function I'm working with:
//==============================================================================
// FUNCTION: updateMeters()
// PURPOSE: Outputs selected voltage and current data over D/A outputs.
// ARGUMENTS: None
// RETURNS: Zero on success.
// REMARKS: DACs are 12 bit.
//==============================================================================
int updateMeters(int *voltage, int *current)
{
extern int channelSel;
extern int refVoltage;
long chan = channelSel + 0x8000;
long ref = refVoltage + 0x8001; // 0x8001 assures ref > 0.
chan *= 17;
chan += ref >> 1;
chan /= ref;
if (chan > 17)
chan = 17;
int channel = int(chan);
long temp = voltage[channel];
temp += 0x8000; // Offset for unipolar range.
temp >>= 4; // Truncate to 12 bits.
_AX = uint(temp);
outportb(DMM32S + 4, _AL);
outportb(DMM32S + 5, _AH);
inportb(DMM32S + 5);
temp = current[channel];
temp += 0x8000; // Offset for unipolar range.
temp >>= 4; // Truncate to 12 bits.
_AX = uint(temp);
outportb(DMM32M + 4, _AL);
outportb(DMM32M + 5, _AH);
inportb(DMM32M + 5);
return 0;
}