01-13-2011 06:16 PM
I need help with my labview program. My goal is to write a program that allows the user to turn a toggle button on/off. When they do this it will start a loop witch turns on a digital switch for 45 minutes then off for 30 seconds and on and on till the user toggles the switch off. The timing does not have to be precise. I am using the NI 9476 digital output card.
I have written the code to turn the switch on/off. I know need to add the looped fuction for on 45 minutes/off 30 seconds. I assume the most efficient method would be using a state machine, but I was having trouble figuring it out.
Attached is the program I have written thus far without the loops.
Thanks,
Barrett
Solved! Go to Solution.
01-13-2011 07:15 PM
I cannot see your code since I don't have 2010 installed. A state machine would be good approach but in order to allow the user to cancel and possibly abort the process at any time your state machine should have a state such as "Check for timeout". In teh loop containing the state machine use a shift register to pass the desired delay value and the start time time for that particular delay. Once the user starts the process set the delay time to your desired time (45 minutes expressed as seconds) and have another shift register that contains the next state to go to after the delay completes. Use a small delay (100ms to 500ms depending on how accurate you want your times to be) to prevent your state machine from free running and then check the delay again. Use the current time and compare it to the start time. If the desired time has passed then go to the next state. You can store the next state in a shift register. No do the same thing for your Off Time state.
01-13-2011 07:16 PM
Take a look at the elapsed timer function and the examples. I bet you'll get a idea or two
01-13-2011 09:16 PM - edited 01-13-2011 09:25 PM
I could not open your vi because I don't have some of the subvi's.
Nothing wrong with the first example posted but I interpreted the specification a little differently.
Edit: There was a small bug in the first zipfile.
01-14-2011 12:05 PM
Thanks for the posts -- this will help a lot since its just what I needed!
I do have one unrelated question towards the files you sent me. What are the purpose of the .CTL (labview control) files? I have seen those several times when looking at state machine examples -- but not all state machine examples have them... I am assuming you created them, but I can't find them referenced inside the code anywhere.
Thanks again for your help,
Barrett
01-14-2011 12:15 PM
The CTL files are typedefed controls. If you know C programming these are analogous to header files. They define a specific type of data that when used in applications you only have to update the typedef and everything that uses it will be updated. I should have mentioned that the ENUMs in my example were not typedefs. In the actual application they should be. I wrote that very quickly and didn't create the typedefs.
For simple data types like integers and such you generally don't need to create typedefs. For clusters, ENUMs and more complex data types you should always use typedefs.
01-14-2011 12:45 PM
Mark already answered about the CTL files.
One thing that you might want to do to the state machine is add initialization and cleanup states. To do that you open the state.ctl, right click and select add items, then add your initialization and cleanup items.
After you do that the state machine will be broken. To fix it just right click on the case structure and select "add items for every value". Now you will have the new states. Change the shift register initialization constant to initialize and put your code in that state. Right click on the state output tunnel and select create constant and change that to "idle". Change the state machine so that when stop is pressed it goes to the cleanup state and then exits.
If you have any trouble with that just post back and myself or someone else will be happy to help! but you should try to figure it out on your own first. It is the best way to drill into your mind how this works.