I have finaly got this simple LED flashing to work in real life ... argh, BUT ...
It work fine in FlowCode concerning the pushbutton - the logic in the flowchart is just like it work in FlowCode.
In real life, when the electronic runs it do NOT run right - I think !
When I turn power on all LED lights up for a short while and then turns off again
If I PRESS and HOLD the pushbutton the LED begins to turn on and off (shifting) and when I depress again the shifting stops (waiting) for the next press and hold.
For me it look like the pushbutton "IN REAL LIFE" is "logic NOT'ed".
I have the pushbutton from MINUS to RA0, and a 10K from Ra0 to PLUS.
What do I mis here ?
Button confusion ???
Moderator: Benj
Button confusion ???
- Attachments
-
- FlashLED.fcf
- (7.5 KiB) Downloaded 347 times
Best regards
KSor, Denmark
KSor, Denmark
- Steve
- Matrix Staff
- Posts: 3434
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Button confusion ???
In your hardware, when the switch is pressed it is presenting a logic level "0" onto the pin. The flowchart thinks that logic level "0" is off and "1" is logic level 1.
Connecting your hardware so that pressing the switch connects "+V" to the pin would make it work like your flowchart.
Connecting your hardware so that pressing the switch connects "+V" to the pin would make it work like your flowchart.
Re: Button confusion ???
??????? Isn't that "upside down" ?
Your advise works, yeah, but I can't see THIS logic in the flowchart and the pushbutton in FlowCode.
The "output term" is connected to pin RA0 and when NOT pressed (=when setting power on) there is logic 1 at RA0 and the flowchart shows "goto A because GoOn=1" and continue turning ALL LEDs on and off - right ?
I think I have set the button up this way by setting the polarity property ="Active LOW" (=when I press it the button goes LOW)
What do I mis here ?
Your advise works, yeah, but I can't see THIS logic in the flowchart and the pushbutton in FlowCode.
The "output term" is connected to pin RA0 and when NOT pressed (=when setting power on) there is logic 1 at RA0 and the flowchart shows "goto A because GoOn=1" and continue turning ALL LEDs on and off - right ?
I think I have set the button up this way by setting the polarity property ="Active LOW" (=when I press it the button goes LOW)
What do I mis here ?
Best regards
KSor, Denmark
KSor, Denmark
- Steve
- Matrix Staff
- Posts: 3434
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Button confusion ???
Hi Ksor,
I think you have found a bug. The simulation of the switch macros "ReadState", "WaitUntilHigh" and "WaitUntilLow" works in a different way to the actual C code when the switch is defined as being "active low".
The confusion is in what the state "high" and "low" actually means in the context of an "active low" switch. The simulation assumes these refer to the logic level presented onto the pin of the microcontroller (i.e. "high" means that there is a voltage level "1" on the input pin), whereas the C code is written with "high" meaning the switch is in its active state (i.e. pressed).
It is difficult to know which definition is "best". But because it is more important that the C code in user's programs remains constant, we have decided to take the "C" code definitions as correct and issue this as a bug in the simulation. This will be fixed in a soon-to-be-released patch of Flowcode V4.
In conclusion, here is a description of those functions:
ReadState - reads the logical state of the switch (i.e. returns 1 when the switch is pressed/active and 0 when it is not pressed/inactive).
WaitUntilHigh - pauses execution of the program until the logical state of the switch is high (i.e. is it pressed/active)
WaitUntilLow - pauses execution of the program until the logical state of the switch is low(i.e. is it not pressed/inactive)
I hope that explains things and thanks for spotting this issue.
I think you have found a bug. The simulation of the switch macros "ReadState", "WaitUntilHigh" and "WaitUntilLow" works in a different way to the actual C code when the switch is defined as being "active low".
The confusion is in what the state "high" and "low" actually means in the context of an "active low" switch. The simulation assumes these refer to the logic level presented onto the pin of the microcontroller (i.e. "high" means that there is a voltage level "1" on the input pin), whereas the C code is written with "high" meaning the switch is in its active state (i.e. pressed).
It is difficult to know which definition is "best". But because it is more important that the C code in user's programs remains constant, we have decided to take the "C" code definitions as correct and issue this as a bug in the simulation. This will be fixed in a soon-to-be-released patch of Flowcode V4.
In conclusion, here is a description of those functions:
ReadState - reads the logical state of the switch (i.e. returns 1 when the switch is pressed/active and 0 when it is not pressed/inactive).
WaitUntilHigh - pauses execution of the program until the logical state of the switch is high (i.e. is it pressed/active)
WaitUntilLow - pauses execution of the program until the logical state of the switch is low(i.e. is it not pressed/inactive)
I hope that explains things and thanks for spotting this issue.
Re: Button confusion ???
OK - I'll have to read your explanation over some times before I get the point.
Does it mean that I have to change my "logic" in the last post .... or are you just dropping the property "Polarity" ?
Does it mean that I have to change my "logic" in the last post .... or are you just dropping the property "Polarity" ?
Best regards
KSor, Denmark
KSor, Denmark
- Steve
- Matrix Staff
- Posts: 3434
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
Re: Button confusion ???
We are not dropping the "polarity" option. We are just confirming that function of those component macros is as in the C code and that the simulation does not work properly.