wjasper / Linux_Drivers

Open source Linux device drivers
GNU General Public License v3.0
111 stars 64 forks source link

How to read the analogue input from different channels (usb1208FS-Plus)? #22

Closed GrantDare closed 5 years ago

GrantDare commented 5 years ago

A call to the following function with actuatorPos(0,0);

and actuatorPos(1,0);

return the same value despite each input having a different voltage

double actuatorPos(int channel, int range){
uint16_t value = usbAIn_USB1208FS_Plus(mc_daq, channel, 1, range);  //1 is DIFF mode
value = rint(value*table_DE_AIN[range][channel][0] + table_DE_AIN[range][channel][1]);
double volts = volts_USB1208FS_Plus(value, range);
double maxV = 4.5;
double maxMM = 40;
double minV = 0.5; 
cout << "brake V " << volts;
double length = maxMM * (volts-minV)/(maxV-minV);
if(length > maxMM)
    length = maxMM;
if(length < 0)
    length = 0;
cout << "\tlength is " << length << "\t on channel " << channel << "\t";
return length;
}
wjasper commented 5 years ago

Grant, does the device work when you use test-usb1208FS-Plus? Use the 'i' option to read from different channels. If it works, use this code as a template for your own code. If not, please send me screen shots of what you see using test-usb1208FS-Plus.

GrantDare commented 5 years ago

Hi Warren,

I have now made this work. My problem was that I was not bridging the AGND of the 1208FS-PLUS to the CH LO of the analogue input. This is specified on page 11 of the user manual.

I am having a new issue however where it will read around 0.2VDC greater than the actual VDC going into the channel.

Thanks, Grant

wjasper commented 5 years ago

It is possible that your ADCs are out of calibration and you have a bias. You might need to calibrate your device (contact MCC) or add a bias when you do your calibration.