06-05-2011 03:42 PM
Hello,
I'm trying to make a state machine, which at specified times should step to the next state. I don't use a timed sequence since you can't stop the sequence.
My problem:
In the state the time is measured. After 3 seconds the comparison becomes true, and the putout of the case should switch from enum 0 to enum 1.
That is exactly what it doesn't do. The probe shows the selector switches from false to true.
Something else that i noticed, the wire inside the case is according to the context help ({unsigned word [16 bit-integer (0-65536)] {enum 1}) the wires outside of the case are the same, except for the {enum 1}
What am i doing wrong?
Greet Nilvo
Solved! Go to Solution.
06-05-2011 03:51 PM
Nilvo,
WIthout the VI it is almost impossible to tell what is happening. As a guess I suspect that one of the cases has something other than the enum wired to the output. Do you have coercion dots at the output tunnel? Is the enum a typedef? Has the enum been changed since you started wiring?
Please post yoru VI.
Lynn
06-05-2011 03:54 PM - edited 06-05-2011 03:55 PM
Since it's a school project with some competition, i can't post the VI. May i send it to you?
I've noticed a red arrow on the tunnel where the Enum becomes a unsigned integer...
Greetz Nilvo
06-05-2011 04:11 PM
I have not heard of a competitive school project since I was a junior, quite a few years ago. The cheapest digital voltmeter (built from an electromechanical counter, discrete transistors, ...) got the highest grade. Everyone who got it working got at least a passing grade.
The red arrow is called a coercion dot. Look up coercion dots in the LV help. It indicates that LV has changed the data type. Fundamentally an enum is an integer data type (with the item texts attached) so it can be converted to ordinary integers. At some point this has apparently happened, probably in one or more cases of your state machine. The other possibility is that you have enum constants which were made from different versions of the enum (for example before and after adding an item to the enum). While you are reading the LV Help, look up typedefs (Type Definitions). If you make you enum a type def, then all the constants made from it will automatically update when you make any changes to the enum. This will mostly prevent the coercion dot issue and the associated problems in the state machine.
Lynn
06-05-2011 04:18 PM
Well... it's not so easy at our school... we have 7 weeks to program a complety car wash, on 3 different interfaces (PLC PC an micro controller)...
The coercion dots appears at the input of the shift register and output of the case...
I'll take a look at the dots tommorrow
Thanx annyway!
06-06-2011 08:26 AM
I took a look at the coercion dots, but i can't find out why they appear in my program. All the connections are tunnels, enum constants or a shift register...
It's very fustrating since i know the whol program works, but the state machine doesn't...
can anyone take a look at the program?
gr Nilvo
06-06-2011 09:21 AM
If at any place you wire in a pure integer (i.e. a "0" constant coming out of a "default" case), everything will be coerced to integers. I think also that shift registers can remember the type you previously plugged in... Try to unwire them from the inside until it loses its type (i.e. black wire), then re-wire it.
06-06-2011 10:34 AM
When using ENUMs for a state machine you should always used a typedefed ENUM. This will avoid th eissue you are seeing now. The typedef will alllow you to modify the defintion (add or remove items) and automatically update all instances of that typedef (they can be controls, indicators or constants) in your code. The coercion dots you are seeing are the result of different data types (yes, an ENUM is a unqiue data type) bing wired on the same tunnel or shoft register.
06-06-2011 11:47 AM
Well... just found out that when you wire only one of the cases, the wire is of the type Enum. When you wire both cases, it becomes an integer...
I'm looking for typedef on this moment, what it is and how to implement.
Gr Nilvo
06-06-2011 11:52 AM
File -> New... -> Control
Put your enum in that control. At the top, there's a listbox with the choices 'Control', 'Typedef', or 'Strict Typedef'. Change it from control to typedef.
In your VI's, you can then drag that .ctl from the project explorer to your block diagram to create a constant with that type, or to the front panel to create a control with that type. You can also right-click on an existing non-typedefed one, and select replace -> select a vi..., and select your .ctl file.