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

Using U3-HV to measure times


  • Please log in to reply
7 replies to this topic

#1 kenny.stjernstroem

kenny.stjernstroem
  • Members
  • 7 posts

Posted 24 June 2014 - 12:21 PM

Hi,

 

I'm using a labjack u3-hv to read two analouge signals and measure period time of a signal from a hall effect sensor. The analouge readings works fine but I don't get any period measurements. I'm trying to configure IFO4 as an timer but I don't get it working. I have also tried to configure FIO4 as analouge and read the signal and then I got a quadratic signal with a minimum voltage of 0.2 V and maximum voltage of 2.4V so I think the period time should be measurable with the timers in the u3. I'll attach the code I'm using to configure the labjack.

 

        

 

       //Open the first found LabJack U3.
       u3 = new U3(LJUD.CONNECTION.USB, "0", true); // Connection through USB
       //Start by using the pin_configuration_reset IOType so that all
       //pin assignments are in the factory default condition.
       LJUD.ePut(u3.ljhandle, LJUD.IO.PIN_CONFIGURATION_RESET, 0, 0, 0);

       //Configure FIO0 and FIO1 as analog, all else as digital.  That means we
       //will start from channel 0 and update all 16 flexible bits.  We will
       //pass a value of b0000000000000011 or d3.
       LJUD.ePut(u3.ljhandle, LJUD.IO.PUT_ANALOG_ENABLE_PORT, 0, 3, 16);


       //Configure the stream:
       //Set the scan rate.
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_SCAN_FREQUENCY, scanRate, 0, 0);

       //Give the driver a 5 seconds buffer (scanRate * 3 channels * 5 seconds).
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_BUFFER_SIZE, scanRate * 3 * 5, 0, 0);

       //Configure reads to retrieve whatever data is available without waiting (wait mode LJUD.STREAMWAITMODES.NONE).
       //See comments below to change this program to use LJUD.STREAMWAITMODES.SLEEP mode.
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.STREAM_WAIT_MODE, (double)LJUD.STREAMWAITMODES.NONE, 0, 0);


       //Define the scan list as AIN0 then AIN1.
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.CLEAR_STREAM_CHANNELS, 0, 0, 0, 0);
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL, 0, 0, 0, 0);
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL_DIFF, 1, 0, 32, 0);

       //Execute the list of requests.
       //LJUD.GoOne(u3.ljhandle);

       //Set counter to channel FI04.
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_COUNTER_PIN_OFFSET, 4, 0, 0);
       //Enable timer0.
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.NUMBER_TIMERS_ENABLED, 1, 0, 0);
       //Set CLock base.
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_CLOCK_BASE, (double)LJUD.TIMERCLOCKS.MHZ48_DIV, 0, 0);
       //Set divisor
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_CONFIG, LJUD.CHANNEL.TIMER_CLOCK_DIVISOR, 100, 0, 0);
       //Set timerMode
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.PUT_TIMER_MODE, 0, (double)LJUD.TIMERMODE.FALLINGEDGES16, 0, 0);
       //Add timer0 to stream list.
       LJUD.AddRequest(u3.ljhandle, LJUD.IO.ADD_STREAM_CHANNEL, 200, 0, 0, 0);


       //Execute the list of requests.
       LJUD.GoOne(u3.ljhandle);

 

 

As stated I get nice readings from the analouge readings when starting the stream but I don't get anything from the timer. Any suggestions of how to find the problem?

 



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 24 June 2014 - 12:53 PM

0.2V to 2.4V should work.  Start by using the test panel in LJControlPanel and see if the period timer works as expected there.



#3 kenny.stjernstroem

kenny.stjernstroem
  • Members
  • 7 posts

Posted 04 July 2014 - 02:12 AM

I have now tried the control panel and then I get good values.



#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 07 July 2014 - 10:11 AM

But still does not work in your stream program?  Do you get back numbers or just 0?

 

You likely want to stream channel 224 also to get the MSW of the timer value:

 

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



#5 kenny.stjernstroem

kenny.stjernstroem
  • Members
  • 7 posts

Posted 10 July 2014 - 11:48 AM

I get numbers back and I don't get it working in my stream program.

If I'm not wrong I don't need the MSW since I configured the timer in 16 bit mode or am I wrong?

#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 10 July 2014 - 01:38 PM

Correct.  Since you are using FALLINGEDGES16 you do not need the MSW.

 

What sort of values do you get?

 

What is the frequency you are sending to the input?  Your clock is 480kHz, so you should be able to time a signal with frequency 7 Hz or greater, but if the frequency is less than 7 Hz the 16-bit register will roll over.

 

When you try it in the test panel, you get the correct numbers using all the same timer settings including Mode=FALLINGEDGES16?



#7 kenny.stjernstroem

kenny.stjernstroem
  • Members
  • 7 posts

Posted 24 July 2014 - 04:07 AM

I don't understand what you want to know about the sort of values that I get. The times I get seams reasonable. The frequency varies from 10 hz to 120 Hz.. I choosed to use 480 Khz to get the best possible accuracy.

 

I have used the same settings when tried in the control panel and then it works but it does not in the program. When I measured in the control panel I had control over the frequency and that's why I'm thinks the values are correct. But the problem is that I get absolutly nothing in the program.



#8 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 24 July 2014 - 08:09 AM

 

 

I don't understand what you want to know about the sort of values that I get.

But the problem is that I get absolutely nothing in the program.

 

In post #4 we asked if you just get back 0, but in post #5 you said you get numbers.  So for your read of channel 200 do you always get 1, or 65535, or random numbers, changing numbers that climb to 65535 and then roll, or something else?

 

 

I suggest you enable a 2nd timer in Frequency Output Mode 7 and write a Value of 0 for it so you get an output frequency of 938 Hz on FIO5.  Connect FIO4 to FIO5 and Timer0 should measure about 510 ticks.  Again try this in the test panel and if it works there then try it in your program.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users