LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Ardunio Count Pulses

Hi All,

 

It's been 5 years since I've touched my Labview and Arduino. 

 

However, I am using the Arduino as a I/O.

 

I used the example to read a high or lo from PIN 2.

 

I want to set up a simple encoder with one pulse per revolution. 

 

If I know the linear distance my object moves in one rotation, the time between two pulses will give me a speed.

 

I wanted to perform some tests, and have Labview plot the speed curve data so I can export. 

 

BUT - I've forgotten everything. 

 

Can someone look at my code, and help out?

 

Thanks,

 

0 Kudos
Message 1 of 5
(4,333 Views)

A few quick pointers:

 

1) There is the LINX toolkit for Arduino, which has replaced the LIFA toolkit you're using. It may have some more features like advanced counting/frequency measurement. 

2) In your code, you're only reading the pin every 10ms, what happens if your digital pin toggles on and off in that time? You'd miss the pulse entirely! If there isn't a feature for doing counting in the LINX/LIFA toolkits, you would have more success by writing a sketch for the Arduino which has an interrupt on that pin - each time the pin changes (e.g. change/rising/falling edge), you can run a small piece of code which either measures the time between the last interrupt and this one, or keep a running total of the number of counts which you can then sample/output periodically from the Arduino. If you go that route, using VISA to read the data over the serial port isn't too difficult (just do a println() with your data and then read that in LabVIEW with the termination character on). You can also implement custom commands in the LINX Arduino firmware.

3) Other than that, your code doens't look too bad as a start (I didn't check the actual algorithm itself - it's fairly neat which is important!)

 

Aside from those...what is the problem you are having with it? Where have you got stuck?


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 2 of 5
(4,314 Views)

Thanks,

 

It's gonna take some time to get my head back in this space. I just got a limit switch installed on my motor to signal one revolution.

 

It's still not exactly what I want, but I will figure it out.

 

Here is an updated version of the code.

 

The problem is, when the limit switch is triggered, the case statement repeats itself for the duration of the pulse. Sort of need to only do it once and wait for the next pulse. 

 

Thanks,

 

Kamilan

0 Kudos
Message 3 of 5
(4,271 Views)

Hi There,

 

This probably isn't the smartest way, but I used a while loop to stay stop the overture. 

 

Let see what happens tomorrow when I test. 

0 Kudos
Message 4 of 5
(4,257 Views)

Having that while loop in the middle like that - what happens if you never see a pulse - the loop never stops and will run at the maximum speed allowable by VISA / your CPU. For example, if you disconnect the Arduino while that middle loop is running, you'll max out your CPU.

 

Like I said - the ideal and robust solution is to use interrupts and a counter on the Arduino and periodically read that value from LabVIEW.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 5 of 5
(4,251 Views)