LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW DAQmx simultaneous AI AO using state machine

Hi,

I am trying to implement a DC motor control. The requirement is as follows

Run the motor for 10 seconds forwards, at 90% duty cycle at 1KHz 

stop for 10 seconds

Run again backwards for 10 seconds , at 95% duty cycle at 1KHz

stop again for 10 seconds.

 

Mean while 

acquire the data from the motor tacho out and analyse to find the RPM during forward and backward direction. 

 

My thoughts are to implement this task using state machine as there are start, stop and direction states and use a producer/consumer type to acquire the data to find the RPM. 

 

Attached is the file where I have implemented it without using a state machine and prod/cons type. 

 

Can anyone guide me to find  simultaneous DAQmx AI AO using state machine.

 

Will I be able to extend the vi with out using a state machine? 

 

Thanks. 

0 Kudos
Message 1 of 3
(2,731 Views)

Hi Vikash,

 

My thoughts are to implement this task using state machine as there are start, stop and direction states and use a producer/consumer type to acquire the data to find the RPM.

Attached is the file where I have implemented it without using a state machine and prod/cons type.

I too would use a state machine - but why didn't you implement it right from the beginning?

 

Can anyone guide me to find  simultaneous DAQmx AI AO using state machine.

Did you look at the example VIs coming with LabVIEW?

Simultaneous AI/AO is explained there as well…

 

Will I be able to extend the vi with out using a state machine?

Sure: you can always go without using any proven design suggestions.

But keep in mind: soon you will be the only one being able to understand your VI…

 

On your VI:

- why do you write data to a file and then need to read the data from that file? Why not use the wire containing the data?

- why do you write float values to the file, but read them as integer?

- why do you read the first row of the file 20 times? why do you need to calculate the sum of the first value of this row? why not read the value once and multiply by 5?

- do you expect your AI loop to always notice the "time has elapsed" flag of the CO loop even when there is that 100ms wait in the loop? (Do you know the meaning of "race condition"?)

- why is there a 100ms wait in the AI loop when the loop iteration rate is determined by DAQmxRead needing 20ms to complete?

- why do you set "1000 samples per channel" at DAQmxTiming when you want to read 5000 samples at DAQmxRead? Did you even read the help for DAQmxTiming to understand the meaning of this "1000" parameter?

- what's the purpose of those DAQmxIsTaskDone functions?

- why don't you use the AutoCleanup tool? (Why don't you follow the LabVIEW style guide?)

So many questions for such a small VI…

Best regards,
GerdW


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

Many thanks for your reply.

 

I started learning LabVIEW in last two months. I have completed only Core 1 tutorial.

 

I too would use a state machine - but why didn't you implement it right from the beginning?

 

Because I am not 100% sure how to use it. From one of the labview document it's been mentioned that using state machine for the DAQmx will improve it's efficiency. So I wanted to try using it and I need to add some controls like forward, reverse, stop and start. 

 

Did you look at the example VIs coming with LabVIEW?

Simultaneous AI/AO is explained there as well…

 

Yes. Using those examples I was able to do that task which I uploaded previously. But I was looking examples using state machine. 

 

 why do you write data to a file and then need to read the data from that file? Why not use the wire containing the data?

Because I want to take mean value and visually see what data I get. I haven't tried wire containing the data yet. Will try now. 

- why do you write float values to the file, but read them as integer?

Will change float to integers

.- why do you read the first row of the file 20 times? why do you need to calculate the sum of the first value of this row? why not read the value once and multiply by 5?

I am summing up only first 20 values in a row. Once the AI loop stops the final value looks like a random value. when I get the mean value it's incorrect because of that last random value.

 

- do you expect your AI loop to always notice the "time has elapsed" flag of the CO loop even when there is that 100ms wait in the loop? (Do you know the meaning of "race condition"?)

I want the CO loop to execute only for 5 seconds. when the CO loop stops executing I want the AI loop to stop as well. So I have used local variable. I dont know about race condition. Let me read about it.

 

- why is there a 100ms wait in the AI loop when the loop iteration rate is determined by DAQmxRead needing 20ms to complete?

I dont know about loop iteration rate. I will read about it. 

 

- why do you set "1000 samples per channel" at DAQmxTiming when you want to read 5000 samples at DAQmxRead? Did you even read the help for DAQmxTiming to understand the meaning of this "1000" parameter?

I will read about the DAQmx timing .

 

- what's the purpose of those DAQmxIsTaskDone functions?

This vi is an extension of an example vi provided by the labview. I just copied and executed with the values that I needed. 

 

- why don't you use the AutoCleanup tool? (Why don't you follow the LabVIEW style guide?)

No idea about Auto clean up tool. let me google search, find and read about it. 

 

Many thanks for going through my vi. I will go through all your question and improve my vi. 

 

 

 

 

 

Message 3 of 3
(2,613 Views)