Newbie.. Counting Pulses every 10 seconds


Martin

Recommended Posts

Dear Colleagues,

I've just started with DF and a Labjack T7 and am looking to configure my T7 to count pulses very 10 seconds and then to reset ready for the next 10 second period.

What I'm after is the total count every 10 seconds from my Geiger counter. At times, during different  I might want to sample every 5 seconds and maybe even by a 1 second during periods of intense activity.

At the moment I have the T7 counting the total count from one of the Kipling examples... it is perfectly in sync with the Geiger so the signal input to the Labjack is OK but I want to use DF to capture that data every 10 seconds and include it with the CSV file I have DF making as it currently captures two thermocouples.

I have the total running count being written to CSV successfully, I just need to be able to specify the Total for a period as we run different experiments. 

A am NOT a programmer (which is why I am looking at DF) and would like to know if there is a convenient way with the DF channel interface to specify the sample period.

If not, could someone point me in the right direction to where I should look to implement a solution?

Regards,

Martin

 

Link to comment
Share on other sites

A simple option for a long interval like this is to simply use DIO#_EF_READ_A_AND_RESET (rather than DIO#_EF_READ_A) and tell DF to only read that register every 10 seconds.

The classical solution is to read DIO#_EF_READ_A as often as you want, but store historical values so whenever you want to display a 10 second count you subtract the count from 10 seconds ago from the current count.

Link to comment
Share on other sites

Thanks Support.

I guess I have so much to learn.

I understand that, with fairly long intervals, resetting the counter is no big deal and especially picking clicks from my Geiger over. 10 second period that if I lose a few it will not break the world.

However the second solution is more elegant.

Is there a way to do this with DF without having to dive into the depths of a scripting or programming language?

Martin.

Link to comment
Share on other sites

I can get Kipling to count and it seems to be making a good job of counting each second the number of pulses from the Geiger counter output.

But, try as I might, I really cannot get DF to pick this up. All that DF keeps doing is to continue adding the counts to the total without any reset. I can vary the sample time... no problem.

I've also used a counter in one of the demonstration files and that keeps adding to the count total without resetting for my next time period.

So what is the secret please?

Link to comment
Share on other sites

Create a second channel, Device Type "Test", I/O type D to A.  Call this one, say "Counts", and call your actual LabJack counter channel "RawCounts".  Expand CHANNELS in the workspace, and select RawCounts.  Then select the Event tab.  In the event type the following:

Counts = RawCounts[1] - RawCounts[0]

The Counts channel will now hold the difference in counts between two consecutive readings.  To get 10 second counts, set the Timing for the RawCounts channel to 10.

Link to comment
Share on other sites

Did not work either... all I got was an error:

07/02/18 17:49:38.003
C1000 Channel or function not found:  Line 1

I'd like to try the first one you gave above as well:

A simple option for a long interval like this is to simply use DIO#_EF_READ_A_AND_RESET (rather than DIO#_EF_READ_A) and tell DF to only read that register every 10 seconds.

but all that seems to do it to aggregate the count rather than resetting the counter as suggested. Any idea why?

Link to comment
Share on other sites

1 hour ago, AzeoTech said:

Create a second channel, Device Type "Test", I/O type D to A.  Call this one, say "Counts", and call your actual LabJack counter channel "RawCounts".  Expand CHANNELS in the workspace, and select RawCounts.  Then select the Event tab.  In the event type the following:

Counts = RawCounts[1] - RawCounts[0]

The Counts channel will now hold the difference in counts between two consecutive readings.  To get 10 second counts, set the Timing for the RawCounts channel to 10.

After a bit of fiddling I got it to work... after a fashion. For some reason it worked if I included  Channel 0 in the "Counts" channel... no idea why. 

Also the bit "Counts = RawCounts[1] - RawCounts[0]" gave me a negative number which drove the graph through the floor.

I just reversed it to: "Counts = RawCounts[0] - RawCounts[1]"

Thanks for that.

Any idea why the first more basic suggestion "DIO#_EF_READ_A_AND_RESET" would not work for me?

Link to comment
Share on other sites

You are right.  I got that backwards.  I was thinking about a regular delta.

The folks at LabJack will need to address the DIO# issue.  But the problem with using this method is that you can lose counts while the counter is being reset.  This probably isn't an issue at low count rates, but at high ones, it can be significant.  That said, at high rates, you also have to change the expression I gave you to account for counter roll over.

Link to comment
Share on other sites

Aha! ... I feel much better as I was pulling my hair out (and I can't really afford to do that) thinking it was me. I was going around in circles all day yesterday and today before finally throwing in the towel. I was reading everything I could find for M and UD devices, forum feeds and PDF files (old and new).

The geiger we need to monitor might well reach a fairly high count rate. How might we manage the counter rollover you mention?

I've just managed a moving graph of the plot as well as bringing in two thermocouples to the CSV file so things are progressing.

I'd really like to stick with DF if possible because my two colleagues are even less interested in programming than me and it would be handy if they can alter relevant criteria without the need to resort to changing code etc.

Thanks for getting back to me.

Martin

Link to comment
Share on other sites

This really only applies if you are running continuously without powering off the LabJack (which resets the counter):

I believe that the LabJack M counter is a 32 bit counter.  So, once you reach 4.2 billion counts or so, its going to reset to 0.  So every so often (like once a month) RawCounts[0] is actually going to be less than RawCounts[1].  So, you have to adjust:

if (RawCounts[1] < RawCounts[0])
   counts = RawCounts[0] - RawCounts[1]
else
   counts = RawCounts[0] + 2^32 - RawCounts[1]
endif

Just FYI: you can do this two other ways in a single line of script, which is more efficient for the computer, but harder to understand by humans:

counts = iif(RawCounts[1] < RawCounts[0], RawCounts[0] - RawCounts[1], RawCounts[0] + 2^32 - RawCounts[1])

or even better:

counts = RawCounts[0] - RawCounts[1] + (2^32) * (RawCounts[0] < RawCounts[1])

The last one is probably 100 times faster than the original if/else, and maybe 20 or 30% faster than the iif(), but I''m guessing at that.

Link to comment
Share on other sites

A huge sigh of relief and a great big "Thanks" to Admin / Guru.

I now have two geiger counters logging counts per second to graphs and a CSV file.

I'd previously had them working with an Arduino and that took me about two days to achieve and around a page of code. Once the Labjack DIO RESET problem was identified and put aside it has taken a couple of hours of serious study and around half a dozen or so lines of code from above.

4.2 billion counts... nope we are not going to hit that. If we did there would be no laboratory left worth to speak of.

Well worth the effort and again... Thanks very much.

Martin Moore

Link to comment
Share on other sites

  • 1 month later...

To end this topic.... on a good note of course.

We now have 5 geiger counters monitoring 4 experiments and 1 background reading working great with the Labjack T7 expansion board.

Along with the geigers are 9 channels of temperature, four channels of current.

So thanks again for the input and guidance. Your assistance has made all the difference.

Regards - Martin

Link to comment
Share on other sites

Archived

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