LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

speed measurement of a motor with Arduino and optical fork sensor

Hello ,

I am doing a project of control and regulation of a DC motor, with an Arduino Uno board and LabVIEW

I want to measure the speed of this motor with the sensorTCST2103

Ayoubas01_0-1647348617709.png

 a disk on a drive shaft with a single tooth, once the disk cuts, the signal provides a low front 

Ayoubas01_1-1647348812692.png

So I want to measure my speed by counting the time between two successive fronts, that makes a complete turn and then we can deduce the speed in rpm. Then in rpm

Ayoubas01_3-1647348973851.png

1-problem A: with Arduino and LabVIEW I can't find a function that allows me to detect a rising or falling edge and that calculates the frequency directly (on the other hand I tried a NI card that has a frequency counter input that works perfectly) but in my case, I thought to make a threshold (in red) below this value it is detected either as a rising or falling edge

-My question is how can I detect an edge with Arduino LINX for example, apart from what I proposed?

-Is there a way to do it with pin 2 interrupts on Arduino?

If not someone can save me either with examples or proposals!

Thanks in advance

 

0 Kudos
Message 1 of 10
(1,598 Views)

Hi Ayoubas,

 

is it an requirement to use LINX?

Why don't you use the ArduinoIDE to create Arduino code? Then all you need is a serial.writeln command to send measurement data to your computer…

 

There are (most probably) existing libraries for the Arduino to count signal edges…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(1,586 Views)

Thank you for responding


in fact it is not an obligation to work with Linx, but it is among the libraries used as LIFA.

 

I made an IDE code with VISA I can read the data well, but to send a PWM signal and read the speed, I can not

with VISA there is not I believe a block for a PWM signal, that's why I opt for LINX or LIFA;
I wanted to do both at the same time acquire the speed with VISA via IDE code and send a PWM signal with LINX but it did not work as the serial port takes only one input channel at a time.

 

How can I acquire the speed and send a PWM signal with either LINX or LIFA?

I hope I was clear in the explanation

 

 

Ayoubas01_0-1647865040151.png

 

0 Kudos
Message 3 of 10
(1,545 Views)

Hi Ayoubas,

 


@Ayoubas01 wrote:

in fact it is not an obligation to work with Linx, but it is among the libraries used as LIFA.

 

I made an IDE code with VISA I can read the data well, but to send a PWM signal and read the speed, I can not

with VISA there is not I believe a block for a PWM signal, that's why I opt for LINX or LIFA;


Why do you  mix LINX and LIFA? They are different drivers and cannot be used mixed with each other!?

 

So you already know how to communicate with an Arduino using VISA functions.

Your only problem is to implement a PWM output on your Arduino? I guess there are Arduino libraries with PWM implementations readily available!

 


@Ayoubas01 wrote:

How can I acquire the speed and send a PWM signal with either LINX or LIFA VISA?


First you send a command to your Arduino, including the PWM duty cycle.

The Arduino handles that command and can then send the acquired speed signal value back to your computer…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 10
(1,529 Views)

yes I understood, but to use VISA (write to send PWM and read the speed at the same time) I have to upload the program which is not practical.


So my question is can you help me to make a program that can measure the time between two edges?
Thanks

0 Kudos
Message 5 of 10
(1,513 Views)

How do you expect Arduino to work without uploading a program you need?

 

 

0 Kudos
Message 6 of 10
(1,504 Views)

the problem with visa is that to measure the speed you have to upload the program on IDE Arduino
to send the PWM signal also we upload and we lose the old program
so is there a way to run two programs at the same time writing and reading?


for me if sincerely I avoid to work with VISA! because of that
I would like to take advantage of the sub vi already made on the LINX or LIFA library to realize my project, my major problem is the detection of the rising or falling edge and to calculate the frequency as I explained in my first message ?

 

0 Kudos
Message 7 of 10
(1,492 Views)

I think you are misunderstanding some concepts here.

 

You write an Arduino program in which you poll the pins for their state to determine motor rpm AND a communication function which either sends rpm data or receives commands (over USB presumably).

 

how that would look like:

-> generate interrupt if pin is low

-> count how many interrupts happened in 1 second

-> average several seconds of data for smoother output (optional)

-> once a second check if any commands were received over comm (or generate interrupt when command comes)

-> execute commands

-> send data once a second

 

 

On the Labview side all you needs is a simple VISA procedure with read/write capability.

 

0 Kudos
Message 8 of 10
(1,485 Views)

this is what i want to make  

Ayoubas01_0-1647961680159.pngAyoubas01_1-1647961731243.png

Ayoubas01_3-1647962088436.png

 

for exemple this is my speed signal and if i detect edges (2 , 3 , 4 , 5 , 6 , 7) is 3 tr /s 

but I think for high speeds it will not be very effective?
here is what I could do someone can improve my program
more thanks

 

0 Kudos
Message 9 of 10
(1,475 Views)

Honestly i don't have much experience with arduino or LINX, but i do have experience with atmega chips.

 

Opening a serial communication, executing two tasks in parallel and then closing it twice is at best gonna give you trouble and at worst won't even work. 

 

Again, not an arduino expert, but on atmega chips there are things called external interrupts, which can be set to be triggered by different changes, a falling edge being one of them. I think you could safely go up to 100kHz motor speed and still have it trigger (it of course depends on your code, interrupt code should be kept simple).

0 Kudos
Message 10 of 10
(1,439 Views)