LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Signal to controller to enable motor, periodic within periodic duty cycle

Hi,

 

I would like to generate a signal which can be read by an Escon 50/5 speed controller and in turn, enable a motor. 

The controller accepts DI (programmable as logic 0, logic 1, or PWM duty cycle), and AI (+/- 10V programmable as speed.)

I have USB-6001 with 2x AO and 1x counter. Also a USB-6210 with zero AO and 2x counter.

 

I can program the set speed while setting up the controller, and I won't need to change the speed after that, only enable to set speed or zero.

I want to run 4 sec on 2 sec off repeatedly for 6 min then rest for 4 min. then repeat from beginning until some condition is met, maybe a temperature reached.

I also want to use the USB-6210 counter to measure system speed, so I believe this eleminates any counter options on this device. But I'm not sure.

 

I can get a counter output as well as an analog output shipping example to pulse (at least my led light) 4/2 sec. on/off for the 6 min period, but I'm stuck at getting it to wait and then repeat.

Also, I have seen the below example using Q&R comparison, but I cannot get this working.

 

-What is an appropriate approach for generating this signal?

 

Along with generating the motor signal, I also may try to generate an AO to control a brake, more or less synchronized with the motor signal. Same timing for both signals using two channels sounds possible.  I also plan to take regular temperature readings as well as torque and speed measurements.

 

Many Thanks

Download All
0 Kudos
Message 1 of 11
(991 Views)

Hi Surfmase,

 


@Surfmase wrote:

Also, I have seen the below example using Q&R comparison, but I cannot get this working.


Looks like an old example of mine: where do you found it?

All you need to "get it working" is to add a suitable stop input to the loop condition…

 


@Surfmase wrote:

I want to run 4 sec on 2 sec off repeatedly for 6 min then rest for 4 min. then repeat from beginning until some condition is met, maybe a temperature reached.

 

What is an appropriate approach for generating this signal?


What about implementing a state machine?

Best regards,
GerdW


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

Hello Gerd,

 

well spotted.  Yes this was from a post of yours here:  https://forums.ni.com/t5/LabVIEW/Relay-control-by-PWM/m-p/3758272

 

I'm adding my vi.  If I do six 1 sec itterations in a while loop, I can get my 4s/2s on/off period operating continuously.  I thought I could replace the while-loop with a 600 itteration for-loop to repeat that 6 sec period for 6 min.  The task and error out lines are not happy tunneling through that.

 

I thought for the case structure I could compare the itteration number to the last itteration (600) which could switch to a false state- a while loop with only wait 4 min inside.  I had trouble here getting the itteration number out and making a usefull comparison.  Data types were not compatible.

 

Am I getting closer?

0 Kudos
Message 3 of 11
(951 Views)

Hi Surfmase,

 


@Surfmase wrote:

The task and error out lines are not happy tunneling through that.


Did you do any basic LabVIEW training? Did you visit the resources offered at the top of the LabVIEW board?

Tunnels at loop borders are a very basic and fundamental LabVIEW feature, so you should know how to handle them correctly!

And when you learn about tunnels you should also take the lesson on shift registers…

 

Why do you need to compare an integer number with a float value of "3.99"? Comparing "<=3.99" is the same as "<=3" when handling integers!!!

See this:

 


@Surfmase wrote:

Am I getting closer?


Well, a little step.

Right now your wait times are a big no-go! In one case you wait for 240s (or 4min), in the other case you run loops for 6*600=3600s=60min. In both cases there is no way to (gracefully) stop! And even worse: in the FALSE case your loop with most probably run one more iteration (which takes 4min) before it will really handle the user STOP request - THINK DATAFLOW!

 

General suggestion:

Learn about using state machines, this will simplify your VI a lot. And it will also improve UX a lot!

Best regards,
GerdW


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


Did you do any basic LabVIEW training? Did you visit the resources offered at the top of the LabVIEW board?

Hi Gerd, glad you asked! I sure did take the Core1 course.  Unfortunately the instructor's native language was not English and they basically read word-for-word from the participants guide. I honestly expected to gleen a lot more through discussions on the usefullness of these tools.  Could have saved myself 2500 chuffs by buying the self-paced course material instead.  That's a shame, but it seems to fit a general trend in the stance NI appears to have towards it's customers.

 

General suggestion:

Learn about using state machines, this will simplify your VI a lot. And it will also improve UX a lot!


I've got this state machine working by single default transitions between an on/off case and a 4 min wait case.  I've added an AI intended to monitor temperature and end the test upon reaching a certain limit.  Otherwise it will run perpetually and as you say, there is no way to "gracefully" stop. 

 

What other means of generating the enable signal do I have without the wait function?  I actually do want run on/off 6 minutes and wait 4 minutes.

 

I've placed the elapsed time function inside the while loop but outside the case structure.  I've placed the read AI voltage within the case structure.  Both update only when transitioning between states.  How could I continuously keep track of elapsed time and temperature?  I assume this has to do with the previous question on eliminating the wait function.

 

Best Regards,

0 Kudos
Message 5 of 11
(851 Views)

Hi Surfmase,

 

your last VI attachment was for LV2019, which is fine for me.

Now you upload for LV2022Q3, which I cannot open…

Please downconvert!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 11
(842 Views)

Hi Gerd, 

 

ah yes, sorry here it is.

0 Kudos
Message 7 of 11
(839 Views)

Hi Surfmase,

 

well, you should think about defining more/other states…

 

Right now two of those states will run for a long time (6min, 4mins), without any option to to end them on user action.

What about using a state of "wait 1s" and call this state 240 times instead of one state of "wait 4mins"? The program will do the very same stuff, but the user has an option to stop each second…

And the same "wait 1s" can be used to break your "4/2 seconds" loop into several states!

You also need just one state, which sets the DO and reads the AI samples, no need to duplicate code.

 

Hint:

Add one shift register to hold "state internal" data, like loop counters. Example: when you want to start the "4mins" you initialize the counter to 240 and with each iteration of the "4mins" state you decrement by one. Then you go to the next state when that counter reaches zero…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 11
(827 Views)

Hi GerdW,

 

Thanks for the tips. It sounds great reading it, but when I open the programm, I'm immediately overwhelmed.

 


What about using a state of "wait 1s" and call this state 240 times instead of one state of "wait 4mins"? The program will do the very same stuff, but the user has an option to stop each second…


It did cross my mind to use "wait 1s" in a for-loop 240 times, but I didn't realize it would change user interuptability.  Now you say "call this state 240 times" as in, not using a for-loop for 240 times? 

 


Hint:

Add one shift register to hold "state internal" data, like loop counters. Example: when you want to start the "4mins" you initialize the counter to 240 and with each iteration of the "4mins" state you decrement by one. Then you go to the next state when that counter reaches zero…


Basic question here: do I need any loops inside this 4min state? Or do I initialize outside the overall while loop and decrement inside the state case?

 


And the same "wait 1s" can be used to break your "4/2 seconds" loop into several states!

You also need just one state, which sets the DO and reads the AI samples, no need to duplicate code.


This sounds like I can't use the duty cycle Q&R function to write T or F to the DO.  I can't imagine how to split this into 2 states without having the write function present in both states.  So if I split this into two states: write DO true (4s) and write DO false (2s) how do I repeat for 6 min? And how do I add the logic of temp limit?  Should I start the while loop with the full 600s (10 min period) and decrement somehow to the different states?

 

Wow, I'm pretty confused now.  I did see this vi. from DarinK which I thought might help, but my programm is really all over the place now without any logic

https://forums.ni.com/t5/LabVIEW/Loop-counter-in-state-machine/m-p/1089148

 

Cheers,

 

 

 

 

 

0 Kudos
Message 9 of 11
(809 Views)

Hi Surfmase,

 


@Surfmase wrote:

It did cross my mind to use "wait 1s" in a for-loop 240 times, but I didn't realize it would change user interuptability.  Now you say "call this state 240 times" as in, not using a for-loop for 240 times? 



All you need is one while loop around the statemachine - no FOR loops inside the states…

 


@Surfmase wrote:

This sounds like I can't use the duty cycle Q&R function to write T or F to the DO.  I can't imagine how to split this into 2 states without having the write function present in both states.  So if I split this into two states: write DO true (4s) and write DO false (2s) how do I repeat for 6 min? And how do I add the logic of temp limit?  Should I start the while loop with the full 600s (10 min period) and decrement somehow to the different states?


As I wrote before: use one more shift register to hold state-internal data.

These "internal" data may include:

- counters for "overall" repetitions, like 240 times "wait 1s" or 60 times "repeat 4/2 cycle"

- counters for specific operations, like "4 times 1s output HIGH", "2 times 1s output LOW"

 

To "add that temp limit" you just need to define your state change conditions: right now there is a large FOR loop, but you replace it by some states (wait 1s, do current state action) and the needed conditions to change from state to state (like: IF counter>0 AND "temp limit not reached" THEN continue heating)…

 

It always helps to draw a scheme of the state machine (aka their states) on a sheet of paper - before starting to code!

Best regards,
GerdW


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