Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Analog input reading


  • Please log in to reply
8 replies to this topic

#1 nsilva

nsilva
  • Members
  • 10 posts

Posted 03 April 2013 - 04:50 AM

Hi, I'm trying to configure chanel FI04 of labjack U3 as analog input, to read a signal that varies from 0 to aproximately 5 volt. I've tried to use the pseudocode in the user's guide, but I'm not reading the same values as in the labjack painel - I'm not reading nothing at all. Can you help me? The code that I'm using is this: //Start by using the pin_configuration_reset IOType so that all pin assignments are in the factory default condition. lngErrorcode = ePut (lngHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0); ErrorHandler(lngErrorcode, __LINE__, 0); //Configure FIO4 as an analog input. lngErrorcode =ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_BIT, 4, 1, 0); ErrorHandler(lngErrorcode, __LINE__, 0); //Request a read from AIN4. lngErrorcode = AddRequest (lngHandle, LJ_ioGET_AIN, 4, 0, 0, 0); ErrorHandler(lngErrorcode, __LINE__, 0); //Execute the requests on a single LabJack. The driver will use a //single low-level TimerCounter command to handle all the requests above. lngErrorcode = GoOne (lngHandle); ErrorHandler(lngErrorcode, __LINE__, 0); // get the result lngErrorcode = GetResult(0, LJ_ioGET_AIN, 4, &dblValue); ErrorHandler(lngErrorcode, __LINE__, 0); printf("AIN4= %f\n", &dblValue); I'm using the hadling error function of the labjack code examples for visual studio. Maybe it is a very simple thing but I'm really begining using this device. Thank you for the attention. Kind regards, Neuza

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 03 April 2013 - 08:12 AM

Are you getting any errors? What are you getting for dblValue?

#3 nsilva

nsilva
  • Members
  • 10 posts

Posted 04 April 2013 - 02:01 AM

When it runs the lines : lngErrorcode = GetResult(0, LJ_ioGET_AIN, 4, &dblValue); ErrorHandler(lngErrorcode, __LINE__, 0); it gives an error of 'invalid handle'.

#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 04 April 2013 - 07:47 AM

That points to your problem. You are passing 0 for the handle. Try instead: lngErrorcode = GetResult(lngHandle, LJ_ioGET_AIN, 4, &dblValue); Alternatively, if you just want to read one analog input, try using the easy function eAIN() instead.

#5 nsilva

nsilva
  • Members
  • 10 posts

Posted 05 April 2013 - 05:44 AM

That points to your problem. You are passing 0 for the handle. Try instead:

lngErrorcode = GetResult(lngHandle, LJ_ioGET_AIN, 4, &dblValue);


Alternatively, if you just want to read one analog input, try using the easy function eAIN() instead.


Oh yeah, this was a distraction, because first I use 'lngHandle' instead of '0', and my problem was that it only returns zeros... It is not changing the values as I move the sensor. I use the eAIN() function and it's happening the same.
Using the painel, I can read between 0.5 and 2.428 V as I move the sensor (rotation movement). Also, I think that are not the expected values. I'm using a contactless anlge sensor type Vert-X-13. I connect its power supply to VS, and ground to ground and I'm trying to read the signal in FI04. It suppose to give an output like between 10 and 90% of VS.
Do you think that maybe I'm doing something wrong with the conections? I'm really not seeing what the problem is. :S

#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 05 April 2013 - 11:46 AM

Are you saying the Voltage parameter of eAIN() returns exactly 0.000000 every time, but the call does not return an error? That would be unusual. Show us a code snippet for that.

http://labjack.com/s...rs-guide/4.2.17

http://labjack.com/s...ers-guide/4.3.9

Does the easy function example work correctly?

Can you get varying voltage readings from other channels? Do you have an LV or HV?


As for your pot, keep in mind that the input range of a low-voltage analog input is 0-2.4V (or 0-3.6 when set to special range):

http://labjack.com/s...users-guide/2.6

I suggest you use DAC0 to excite your pot, rather than VS. Set DAC0 to 2.3V. For best results you would use another low-voltage analog input to measure the actual excitation voltage in real time.

#7 nsilva

nsilva
  • Members
  • 10 posts

Posted 08 April 2013 - 04:53 AM

Are you saying the Voltage parameter of eAIN() returns exactly 0.000000 every time, but the call does not return an error? That would be unusual. Show us a code snippet for that.

http://labjack.com/s...rs-guide/4.2.17

http://labjack.com/s...ers-guide/4.3.9

Does the easy function example work correctly?

Can you get varying voltage readings from other channels? Do you have an LV or HV?


As for your pot, keep in mind that the input range of a low-voltage analog input is 0-2.4V (or 0-3.6 when set to special range):

http://labjack.com/s...users-guide/2.6

I suggest you use DAC0 to excite your pot, rather than VS. Set DAC0 to 2.3V. For best results you would use another low-voltage analog input to measure the actual excitation voltage in real time.


Yes. It returns exactly 0.0000000 every time without any error.
I've try other channels but the result is the same.

This is the code that I used to read the value:
lngErrorcode = eAIN (lngHandle,4,31,&dblValue,0,0,0,0,0,0);
ErrorHandler(lngErrorcode, __LINE__, 0);
printf("AIN4= %f\n", &dblValue);

#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 08 April 2013 - 06:43 AM

Do you have a U3-HV or U3-LV? If you use different software like LJLogUD or the test panel in LJControlPanel, do you get proper readings from analog inputs? Looks like you are using the VC6_LJUD archive. Try running the u3_efunctions example and see if that works properly.

#9 nsilva

nsilva
  • Members
  • 10 posts

Posted 08 April 2013 - 07:32 AM

Do you have a U3-HV or U3-LV?

If you use different software like LJLogUD or the test panel in LJControlPanel, do you get proper readings from analog inputs?

Looks like you are using the VC6_LJUD archive. Try running the u3_efunctions example and see if that works properly.


I have U3-HV.
I use the example that you metioned and it worked. Then, I found that my problem was on 'printf' function. :S

Thank you very much for the help.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users