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

Counting with U3

Counter U3

  • Please log in to reply
4 replies to this topic

#1 daromander

daromander
  • Members
  • 5 posts

Posted 01 July 2014 - 08:41 AM

I am trying to make a program in Visual Basic 2010 Express that will be able to count incoming pulses over a variable amount of time (set by the user) and only report the amount of counts when the time is over. Instead of putting the program to sleep (as is suggested by the counter/timer example) I wanted to do it in a way that won't stop the rest of my program. At first I tried using the internal timer (mode 10) but I couldn't get it to work properly. Would I want to set it into a while loop so it doesn't read the counter until the internal timer reaches that point? If that is the way to go I can't seem to properly reset the counters and timer so that the program can run multiple times. My other idea was to try and set up a stream where the length of the stream is the variable amount of time set by the user. If that is the way to go, I have no clue how to properly set up the stream with a counter in Visual Basis.

 

Thank you for any help you can give me. It is much appreciated.



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 01 July 2014 - 09:11 AM

Make sure you want to count over time, rather than just timing the most recent pulse:

 

https://forums.labja...?showtopic=1105

 

What does the rest of your program do?  For example, if your program normally does a single add/go/get block once per second, you could give the user a control that lets them pick the count time in 1 second increments and then you just use the counter read you get at those matching times.



#3 daromander

daromander
  • Members
  • 5 posts

Posted 01 July 2014 - 10:43 AM

The program does a lot of different things depending on what actions the user would take (like the ramping of output voltage of DAC or determination of current by measuring voltage over a resistor) so while it is counting it might need to also be doing other things. That affects the amount of time it takes to run certain pieces of code so I don't believe I can rely on the length of the coding. That is why I assumed using the internal clock in the Labjack would be the best (as it hopefully would not be affected by other parts of the program). My problem is I don't know the best way to work with and code the mode 10/11 in that way. The frequency measurement forum you sent me to would be good if the pulses were coming in at a set constant frequency but that is not the case.

 

Is there a way to set the counter to only count for a certain amount of time?

 

Thanks again for your quick response



#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 01 July 2014 - 10:54 AM

There is no way on the U3 to tell it to count for a certain amount of time in hardware.  It is more reasonable to read the count whenever you can, at a time close to what the user wants, and then note the actual counting time rather than assuming the time specified by the user was the actual time.

 

One good way to design an application like this is to choose your max communication rate and have 1 loop that runs at that rate.  Say you decide the max rate you need is 20 Hz.  You then set up a main while loop that executes every 50 ms, and then in that 1 loop you can do whatever things you want at the proper times.



#5 daromander

daromander
  • Members
  • 5 posts

Posted 01 July 2014 - 11:05 AM

Ok, thank you for your help. I will try out multiple things and see what works well.





Also tagged with one or more of these keywords: Counter, U3

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users