Counter channel confusion


Recommended Posts

I'm currently using DAQFactory to plot channel AI0 vs. time and would like to plot AI0 vs. distance. To do this I would like to use a proximity sensor on a pulley. I figured it would be best to use the counter. Unfortunately, I'm having trouble manipulating the data from the counter. I can't seem to get the counter to increment by 1 unit at a time. Any advice would be a great help.

Thanks!

Link to comment
Share on other sites

Is it incrementing several units each cycle? If so, then you need to debounce the sensor. You can do it in hardware with simple circuits. Look online or ask the LabJack guys about it. I'm presuming you are using a LabJack. Actually with the UE9 and U3 there is a timer mode that does debounce I believe.

You could also do it in software provided you there was a good pause between counts, but hardware is probably a better choice since its so simple there.

Link to comment
Share on other sites

I guess i should say that i'm using a U12... I've got a 10k resistor going from CNT to GND to "pull" the voltage down. Is this what you mean by debouncing the sensor? I'm using 5 volts to increment the counter.

When looking at the table of values for my counter channel should i see continously increasing numbers? Right now i'll get numbers like 1, 2, 9, 3, 7, 15, .... I guess i'm asking should the program automatically sum the counts and would my vector at any given time resemble [8, 7, 6, 5, 4, 3, 2, 1]?

Thanks

Link to comment
Share on other sites

No, a pull down doesn't debounce, it just ensures that when the input is floating that the actual input gets pulled down to ground and doesn't just float. Its required when using switches that are either On or disconnected (like a reed switch), and are probably a good idea in general.

Debounce is required for mechanical switches because when the switch transitions from one state to another the mechanical aspect causes it to jump back and forth between on and off several times before settling on the new state. The counter is sensitive enough to pick this up and so you get numbers that jump by more then one each time. As I said, debounce is quite common and you should be able to find an debounce circuit on the net somewhere. I'm not a hardware guy, so can't pull it off the top of my head.

You can also debounce in software. Assuming your counter channel is called RawCounts:

1) create another channel, device type Test, 0, A to D, 0, Timing = 0. Timing = 0 is critical. Call it RealCounts.

2) Click on "RawCounts" in the workspace under CHANNELS:, then click on the event tab

3) enter this script:

RealCounts.addvalue(Inserttime(RealCounts[0] + (RawCounts[0] != RawCounts[1])))

You will also need to initialize RealCounts to 0 in an autostart sequence by doing:

RealCounts.AddValue(0)

You say your readings go 1,2,9,3,7,15. Why do they reset from 9 to 3? Are you resetting the counter? I recommend against this. Just let it free run.

Link to comment
Share on other sites

Thanks for the debouncing tip. I'm still haveing trouble with the counter counting total occurences. To my knowledge, i'm not telling it to reset at all. In the "Table" tab for RawCounts i'm seeing 0's and then a 1 when I make my contact. However, when i make another contact, it still shows another 1 in the table. For example, i'll see [0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0] for two cycles. To clarify, my event tab for "RawCounts" resembles the following:

RealCounts.AddValue(InsertTime(RealCounts[0] + (RawCounts[0] != RawCounts[1])))

RealCounts.AddValue(0)

Does this mean my most recent value in "RealCounts" should be the total count?

Also, am i still reseting the counter by accident somehow?

Thanks for your assistance!

Link to comment
Share on other sites

You are accidently resetting RealCounts by doing RealCounts.addvalue(0). In the event you just want the first line. You need to do RealCounts.addvalue(0) in an autostart sequence. Go to SEQUENCES, right click and select Add Sequence, call it StartUp, put that line of code, check AutoStart at the top, then Apply and save your document. Also, if you ever want to manually clear the counts, you can put that line in the Quick Sequence of an event.

RealCounts.AddValue(0) puts a 0 into the ReadCounts channel. It is required because when DAQFactory starts there is no value in the channel. The RawCounts event references RealCounts[0], but if there is no value available, the formula will fail. So, we have to initialize it with a 0.

Link to comment
Share on other sites

Thanks for the info... I have it set up that way now. For some reason the RealCounts channel is still not incrementing even though i see each response in the RawCounts channel table tab. The autosequence starts it at 0 (I see this in the table tab) but there is no activity within the RealCounts table after the initial 0 value. Is any code needed in the RealCounts event tab to make it increment?

Thanks

Link to comment
Share on other sites

You should get a value in the RealCounts table for every RawCounts reading even if the RealCounts remains the same. This is because you have RealCounts.AddValue() in the event without any if() to keep it from running. If its not doing it, then you likely have a typo in that line or another prior line in the event (if any), and come to look at it, I gave you an incomplete expression, as InsertTime() requires 3 parameters. You want:

RealCounts.addvalue(Inserttime(RealCounts[0] + (RawCounts[0] != RawCounts[1])),systime(),-1)

Sorry about that! I forgot to tell InsertTime() what time I wanted inserted :D

Link to comment
Share on other sites

I managed to get it working. I ended up modifying some parentheses and chaning the timing at the end. I'm using a faster sampling rate for RawCounts to ensure that i obtain the signal i need. I used:

RealCounts.addvalue(Inserttime(RealCounts[0] + (RawCounts[0] != RawCounts[1]),systime(),-.03))

The only thing i have left is a minor debouncing circuit modification. At times is counts 2 or 3 times instead of 1.

Thanks again for your assistance. It's greatly appreciated.

Link to comment
Share on other sites

You are right. I don't know why I keep typing your expressions in wrong. I'm doing it right into the forum and I guess am a bit spoiled by DAQFactory's parenthesis highlighting.

Hmm, the RealCounts should only increase by one unless you are sampling the counter quicker than the bounce. You shouldn't need to sample faster to catch an event unless the events are spaced close together. The counter will catch an event as short as a microsecond I believe even at a timing of 10. So, set the timing to a value 1/2 the minimum interval of events. If your bounce is longer than that, you'll have to use hardware to debounce.

Link to comment
Share on other sites

Archived

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