If Decision Fails Flowcode 5

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

If Decision Fails Flowcode 5

Postby JLeith » Tue Nov 20, 2012 8:58 am

I thought I had a grip but tonight I’m stumped.

I set a Decision statement to see if PORTA > 2 so it can jump into a routine to check which switch has been activated.

I activate ( Ball ) or Port A Bit 7.

So the Decision does activate because PORT A is value 7.

The display for Ball advances then I stop the switch so now PORTA = 0

The Decision FAILS and just keep looping thru all my scan keys.

Here is a picture

Here I have 1 = Ball displayed
The Variable table list PORTA as value 0 but for some reason when I get back to the Loop and into Decision does PortA > 2 it buzzes right past ??

IF Statement Fail 2.jpg
I had to make the image a Little smaller to upload
(212.69 KiB) Downloaded 1333 times


John

User avatar
Benj
Matrix Staff
Posts: 14786
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4750 times
Been thanked: 4358 times
Contact:

Re: If Decision Fails Flowcode 5

Postby Benj » Tue Nov 20, 2012 10:44 am

Hello John,

The $PORTA reads the entire port including the pins you are using to drive the 7-seg displays.

I would instead use an input icon with masking to copy the input pins into a variable and then use that variable in your decision icon.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: If Decision Fails Flowcode 5

Postby JLeith » Tue Nov 20, 2012 9:37 pm

Hi Benj,

Thank you for your endless help.

So the decision works the first time waiting for the switch say A7 to go active and then the flow picks up the A7 and activates Ball 1 segment. But oddly why does the Variable window say PORTA = 0 ?

Let me follow you thoughts.
1. use an input icon with masking to copy the input pins into a variable ( So I would need 1 variable to cover the corresponding switches ? )
2. and then use that variable in your decision icon. ( I will give this a try )

John

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: If Decision Fails Flowcode 5

Postby JLeith » Tue Nov 20, 2012 10:26 pm

Hi Benj

Well I think I tried but I tried everything I could think of for the Decision step but I could not get the flow to come in to detect the switch.

I simplified it to be just 1 switch A5 Port A.

Varibale control.jpg
Varibale control.jpg (110.71 KiB) Viewed 5315 times


I believe I followed your steps. But I must be missing something.

I spend just about equal time doing images as to working the project.

John

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: If Decision Fails Flowcode 5

Postby Enamul » Tue Nov 20, 2012 10:38 pm

Hi John
This what Ben says..
Attachments
test.fcf
(7 KiB) Downloaded 114 times
These users thanked the author Enamul for the post:
JLeith (Tue Nov 20, 2012 11:33 pm)
Rating: 5%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

dbasnett
Posts: 125
Joined: Mon Aug 15, 2011 1:54 pm
Has thanked: 8 times
Been thanked: 11 times
Contact:

Re: If Decision Fails Flowcode 5

Postby dbasnett » Tue Nov 20, 2012 11:21 pm

If you want to check one bit (bit 7) your if should be:

($PORTA AND 128) > 0

The other bits are:
($PORTA AND 1) > 0 - bit 0
($PORTA AND 2) > 0 - bit 1
($PORTA AND 4) > 0 - bit 2
($PORTA AND 8 ) > 0 - bit 3
($PORTA AND 16) > 0 - bit 4
($PORTA AND 32) > 0 - bit 5
($PORTA AND 64) > 0 - bit 6

The 'AND' values are the mask. If you wanted to check multiple values on at the same time, say bit 0 & bit 7, the if would be
($PORTA AND 129) = 129
These users thanked the author dbasnett for the post:
JLeith (Tue Nov 20, 2012 11:33 pm)
Rating: 5%
 

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: If Decision Fails Flowcode 5

Postby JLeith » Tue Nov 20, 2012 11:36 pm

Thank you,
dbasnett & Enamul

I totally missed the point and will take the information and work with it.

I really thank everyone,

John

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: If Decision Fails Flowcode 5

Postby JLeith » Tue Nov 20, 2012 11:46 pm

Hi all,
Happy clear.jpg
Happy clear.jpg (4.92 KiB) Viewed 5303 times


it is a happy day with the great help.

It worked and now I just nee to see how to address the common Anode issue.

John

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: If Decision Fails Flowcode 5

Postby JLeith » Wed Nov 21, 2012 6:45 am

Hello all,

Well with the help of "dbasnett ' outlining the code to determine when a incoming request was sent.

Now I would like to add a little more. it is inspiring to learn more.

Port action.jpg
Port action.jpg (88.3 KiB) Viewed 5298 times


I tried to read the PORTA variable but I could not read the value. I know the formula works because when I requested a switch the decision returned the result.

now I would like to add a further step and calculate the PortA and return the value so I can speed up the next step. I have 8 buttons to scan and send of to display the correct score.

Seeing the ($PORTA AND 224 ) > 0 results in that decision I would like to take the PORTA value and come up with a 1 - 8 selection so I can go directly to the segment selection. At present I have to scan button from 1 - 8 so If I could jump say to 5 if PortA bit 5 (32) comes up I could - 27 from PortA and come up with Selection 5. I think I would need 8 formulas to cover all the keys but maybe their is a better way.
If I can address the Switch to select the correct key it would be a Little cleaner

John

User avatar
LeighM
Matrix Staff
Posts: 2009
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 480 times
Been thanked: 688 times
Contact:

Re: If Decision Fails Flowcode 5

Postby LeighM » Wed Nov 21, 2012 1:37 pm

Hi

I am not totally sure what you are trying to do.
If you were to somehow encode 8 selections onto PORTA bits 7,6,5
Then your formula would be
SW = (($PORTA AND 224) >> 5) + 1
Where SW now has a value 1 to 8

If you are using all of PORTA for 8 separate switches, then you could have a Switch icon to test for values 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
That will only work when only one switch is pressed at a time, otherwise you will need 8 separate If icons and test ($PORTA AND 0x80) etc, as Ben’s code.

Hope that helps.
Leigh
These users thanked the author LeighM for the post (total 2):
Enamul (Wed Nov 21, 2012 1:41 pm) • medelec35 (Wed Nov 21, 2012 2:19 pm)
Rating: 10%
 

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: If Decision Fails Flowcode 5

Postby JLeith » Wed Nov 21, 2012 9:22 pm

Hello Leigh

Thank you for the further information. My plan is to see if it is possible to take the single Push buttons and use the value to route directly down the Switch Value.

Here is a sample flow I put together to show the flow.

I tried to different formulas but it is not my forte. I had trouble coming up with a formula.

There will be 8 incoming push buttons. They will be PORT B ( 0 - 7 ).

The vision is have PORT B - 0-7 as Port B set to (INCOMING) then the code will switch to Port B to (OUTPUT) and send the bit pattern out to control chips.

Switch Route.jpg
(178.91 KiB) Downloaded 1256 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8809
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2553 times
Been thanked: 3712 times
Contact:

Re: If Decision Fails Flowcode 5

Postby medelec35 » Wed Nov 21, 2012 11:39 pm

Hi John,
Attached is how I detect which switch has been pressed.

It's the easiest way I can think of.

Martin
Attachments
Direction Flow 414 V2.fcf
(73.92 KiB) Downloaded 80 times
These users thanked the author medelec35 for the post:
JLeith (Thu Nov 22, 2012 3:07 am)
Rating: 5%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

dbasnett
Posts: 125
Joined: Mon Aug 15, 2011 1:54 pm
Has thanked: 8 times
Been thanked: 11 times
Contact:

Re: If Decision Fails Flowcode 5

Postby dbasnett » Wed Nov 21, 2012 11:53 pm

JLeith wrote:Hello Leigh

Thank you for the further information. My plan is to see if it is possible to take the single Push buttons and use the value to route directly down the Switch Value.

Here is a sample flow I put together to show the flow.

I tried to different formulas but it is not my forte. I had trouble coming up with a formula.

There will be 8 incoming push buttons. They will be PORT B ( 0 - 7 ).

The vision is have PORT B - 0-7 as Port B set to (INCOMING) then the code will switch to Port B to (OUTPUT) and send the bit pattern out to control chips.

Switch Route.jpg


I am confused. Is port B or port A the push buttons? In the attachment you are reading A.

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: If Decision Fails Flowcode 5

Postby JLeith » Thu Nov 22, 2012 2:09 am

Sorry about the mix up.

When I copied the picture I was trying to see what Port would work out.

I have a odd process that is causing me a Little concern is that I will be using a process that was in the OLD scoreboard I was given to try and bring back to life. I determined that I could use the PIC 16F1826 that the same process with Port A as timer and Port B as the port to receive the Wireless input that will be providing momentary outputs to PORT B 0 - 7. and once the push button in principle goes High then I can still develop the code in Flowcode 5. So I was trying to use Port B push buttons to simulate the wireless inputs.

I was hoping to determine the Port B state and select the correct path. Currently I come into the "Switch Value" and scan all 8 looking for the button. I thought that If I could get into the "Switch Value" quicker it will make sure the push button was still active.

I hope this helps. I have a development power point but I can't upload it.

John

User avatar
JLeith
Posts: 521
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 143 times
Been thanked: 26 times
Contact:

Re: If Decision Fails Flowcode 5

Postby JLeith » Thu Nov 22, 2012 3:16 am

Hello Martin,

Wonderful work on the Switch Value and this allow the switch value to process correctly.

Now I have 1 more glitch that maybe you can help.

How can I set the switches to be Input on port B and once it goes into the routine to produce the display be Port B output. Do I have to add in "C" code to make that happen.

Just so I don't have the LED on port b respond to the buttons. When I make the PIC I have to have that working.

I have added the new improved Switch action to the growing work.

I really like getting the Knowledge and excellent help.

John
Attachments
Direction Flow with new switch.fcf
New switch layout.
(93.63 KiB) Downloaded 76 times