wjasper / Linux_Drivers

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

How to measure multiple channels on USB-TC #40

Closed robot-army closed 2 years ago

robot-army commented 2 years ago

Hi,

I have a USB-TC, and I'm modifying the example code to read all 4 channels.

Is this a reasonable way to do it?

        usbSetItem_USBTC(hid, ADC_0, CH_0_TC, bIReg);
        usbSetItem_USBTC(hid, ADC_1, CH_0_TC, bIReg);
        usbSetItem_USBTC(hid, ADC_2, CH_0_TC, bIReg);
        usbSetItem_USBTC(hid, ADC_3, CH_0_TC, bIReg);
        flag = fcntl(fileno(stdin), F_GETFL);
        fcntl(0, F_SETFL, flag | O_NONBLOCK);
        do {
          usbTin_USBTC(hid, CH0, 0, &temperature);
          printf("%.2f degress Celsius or %.2f degrees Fahrenheit.\n", temperature,
                 celsius2fahr(temperature));
          fflush(stdout);
          usbTin_USBTC(hid, CH1, 0, &temperature);
          printf("%.2f degress Celsius or %.2f degrees Fahrenheit.\n", temperature,
                 celsius2fahr(temperature));
          fflush(stdout);
          usbTin_USBTC(hid, CH2, 0, &temperature);
          printf("%.2f degress Celsius or %.2f degrees Fahrenheit.\n", temperature,
                 celsius2fahr(temperature));
          fflush(stdout);
          usbTin_USBTC(hid, CH3, 0, &temperature);
          printf("%.2f degress Celsius or %.2f degrees Fahrenheit.\n", temperature,
                 celsius2fahr(temperature));
          fflush(stdout);
          sleep(1);

I seem to get fairly sensible readings, but I'm not sure if I should be doing something with eg. channels 4-7, or CH_1_TC rather than CH_0_TC.

My thermocouples are hooked up to + and - for each channel. Does this line up with the default ADC/input mux configuration?

Thanks, R

wjasper commented 2 years ago

Well almost. If you have 4 thermocouples you will want to read them on channels 0-3. However, each A/C supports 2 channels, , so I think you want usbSetItem_USBTC(hid, ADC_0, CH_0_TC, bIReg); // CH0 usbSetItem_USBTC(hid, ADC_0, CH_1_TC, bIReg); // CH1 usbSetItem_USBTC(hid, ADC_1, CH_0_TC, bIReg); // CH2 usbSetItem_USBTC(hid, ADC_1, CH_1_TC, bIReg); // CH3

Then you can read the channels in the do loop like you have. To test this out, you will need to hook up 4 thermo c The way you set it up in your examples, you would read from CH0, CH2, CH4, CH6.

I would hook up 4 thermocouples and make sure you are reading correctly (put one in hot water to make sure that it's value is changing :)