gkemper Posted September 30, 2011 Share Posted September 30, 2011 What I am trying to do is to set the beat on a pendulum(s). I have a IR Emitter/Detector setup up at the bottom of it's swing so it will be detected twice during a cycle. One cycle will be for example: releasing it and having it swing out and back to the point of it's initial release. I will be lengthening/shortening the length of the pendulum to set it to a specific beats per minute. From between 50 and 70 beats per minute. I chose the bottom of it's swing since it will swing a smaller and smaller arc over time, but will always pass the center point in the same amount of time. Ideally what I would like to do is get a value in Beats per Minute so that I can adjust it "live" getting the results updated as I raise/lower it. I have been trying to do it for over a week now with no luck! Any help? Thanks Link to comment Share on other sites More sharing options...
AzeoTech Posted October 1, 2011 Share Posted October 1, 2011 Sorry, I can't give much help without knowing what you tried and what went wrong with what you it. You should start with one of the Timer/Counter samples, probably the Timer that determines period. From that you can easily calc the beats per minute in real time. But you need to get the timer working first. The DF-LabJack App Guide should explain it and include a sample. Link to comment Share on other sites More sharing options...
gkemper Posted October 1, 2011 Author Share Posted October 1, 2011 I have been using PureBasic to try to do it. Which doesn't have the consistency to do the job. I have just started messing with DF a couple of days ago. The timer in the U3, I was told by LabJack was was only accurate to 1.5%. That's almost a second at 60 seconds, so that won't work. I did get the counter working in DF but the display doesn't keep up. I have to stop the inputs to let it catch up. I was thinking that I would use the precision timer mentioned in your manual, but I have note seen any commands that take advantage of it to the sub second. I figure that I could use your timer to time the period between counts of the counter. Then display the time. If I can get that far, than it's just a matter for me to figure the beats per minute. Even If I have to wait a couple of beats for the display to catch up. The question, at this point, is I guess is how do I access your precision timer. Link to comment Share on other sites More sharing options...
AzeoTech Posted October 3, 2011 Share Posted October 3, 2011 You are always accessing the precision timer. There is only one. When you do systime() you get a timestamp to the microsecond. You just usually don't see it because all the formatting is to the millisecond. However, that's not going to help you since there is no way to have a labjack trigger an event in DAQFactory for you to record the time, and even if there was, you'd be off by 4ms because that's how long it takes the LabJack to communicate with the PC. The only way you'd get this to work without additional hardware would be to stream the counter at high speed and then search through the data for the pulse and look at the difference in time. This would be challenging in real time, but is probably doable depending on your skill level. A better, and more reliable way, is to put a square wave generator on the counter, and then stream the counter in trigger mode, letting the pendulum trigger the counter read. Then you can use the period of the square wave and the number of counts between reads to determine the period of your pendulum. Link to comment Share on other sites More sharing options...
BeeHay Posted October 10, 2011 Share Posted October 10, 2011 Hello gkemper! We use a momentary push button switch to count "strokes per minute" and I understand your observation of the "display catching up"... AzeoTech helped me out a while back with my Counter setup... 1.) Make 2 Channels - Counts and Beats....Counts being a device type of "Test", I/O type "A/D", Chn# 0, and a timing of zero...Beats being a device type of "Labjack", I/O Type of "Counter", Chn # 0 2.) In the events tab of channel Beats, put this code - Counts.AddValue(Beats[0] - Beats[1]) 3.) Ensure you have the Counter init code from Labjack working! //Usually in an auto-start seq... using("device.labjack.") include("c:\program files\labjack\drivers\labjackud.h") global ID = 1 ePut(ID, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0) //first counter on FIO4 AddRequest (ID, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 4, 0, 0) // enable counter 0 & 1 and reset them: AddRequest(ID, LJ_ioPUT_COUNTER_ENABLE,0,1,0,0) AddRequest(ID, LJ_ioPUT_COUNTER_ENABLE,1,1,0,0) AddRequest(ID, LJ_ioPUT_COUNTER_RESET,0,0,0,0) ErrorHandler(ID) GoOne(ID) 4.) Create a while(1) loop to count the BPM - global BeatsMin while(1) BeatsMin = Sum((Counts[0,17])/3)*20 //formula for our spm..If you need a history, use .addvalue... endwhile 5.) Count the counts time...I think you could use Counts.Time[0]-Counts.Time[1] to see the time between the 2 "beats"...Counts is pretty much "beats per/sec".. Hope this is useful and correct me if I'm wrong AzeoTech! Link to comment Share on other sites More sharing options...
BeeHay Posted October 11, 2011 Share Posted October 11, 2011 I was thinking about it yesterday, and I think my point #5 is wrong... I think it would be something like this - (Counts.Time[0] - Counts.Time[1]) / Counts[0] Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.