Retrieving Time From A Pulse Counter Channel


Recommended Posts

Hello,

 

I've put together a LabJack / DAQFactory interface controlling a bipolar stepper motor via the Easy Driver from Sparkfun. I've set-up a pulse counter collecting frequency out timer data and the counter looks to be working as expected.

 

Now, in order to be able to utilize the counter data (from my counter channel "Pulse_Counter" with a set timing of 0.01) I put the counter data into a channel named Displacement, and I do that via a while() loop in an autostart sequence via:

 

Displacement.AddValue(insertTime(blablabla, Pulse_Counter.Time[0],0))

 

but... unless I include a wait(0.1) before the above code I get a "Uncaught error in sequence" and I assume this has something to do with the internal timing of the Pulse_Counter channel and the above autostart sequence in DAQFactory, it seems it needs a slight delay to allow for the Pulse_Counter to fill up with some data to be able to use its timestamps. If this is the case (I might be missing something else) - is there a better way to solve this without using the wait(0.1), which might be a computer/operating system dependent delay, and still having the counter channel sequence set as autostart?

 

Thanks,

 

Marcus

Link to comment
Share on other sites

The problem is that the Pulse_Counter channel (and any channel without Persist enabled) won't have any data on startup.  I don't remember whether Auto-Start sequences or Channel Timing's start first, and truthfully, its undocumented and could change so you should never assume one or the other.  As you also pointed out, using wait(0.1) may also cause problems as the system moves from machine to machine.  BTW: you probably want delay() instead of wait().  Wait() is for a very particular purpose and delay() should be used for general delays.

But back to the question at hand:  you should simply check if pulse_counter[0] is empty before entering your loop:

 

while(isempty(pulse_counter[0]))

   delay(0.01)

endwhile

 

// your loop.....

 

isempty() returns true (1) if the variable doesn't exist or doesn't have any values.  It returns false (0) if it does contain values.  So you just want to loop until it returns false.

Link to comment
Share on other sites

What a wonderful 3-line solution that makes it platform independent and allows for safe autostarting at the same time, thanks :) Also, I must say that the DAQFactory / LabJack / Easy Driver is a very powerful solution, works really great together with the bipolar stepper motor I use. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.