Page 1 of 1

If Decision Fails Flowcode 5

Posted: Tue Nov 20, 2012 8:58 am
by JLeith
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

Re: If Decision Fails Flowcode 5

Posted: Tue Nov 20, 2012 10:44 am
by Benj
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.

Re: If Decision Fails Flowcode 5

Posted: Tue Nov 20, 2012 9:37 pm
by JLeith
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

Re: If Decision Fails Flowcode 5

Posted: Tue Nov 20, 2012 10:26 pm
by JLeith
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 9798 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

Re: If Decision Fails Flowcode 5

Posted: Tue Nov 20, 2012 10:38 pm
by Enamul
Hi John
This what Ben says..

Re: If Decision Fails Flowcode 5

Posted: Tue Nov 20, 2012 11:21 pm
by dbasnett
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

Re: If Decision Fails Flowcode 5

Posted: Tue Nov 20, 2012 11:36 pm
by JLeith
Thank you,
dbasnett & Enamul

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

I really thank everyone,

John

Re: If Decision Fails Flowcode 5

Posted: Tue Nov 20, 2012 11:46 pm
by JLeith
Hi all,
Happy clear.jpg
Happy clear.jpg (4.92 KiB) Viewed 9786 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

Re: If Decision Fails Flowcode 5

Posted: Wed Nov 21, 2012 6:45 am
by JLeith
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 9781 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

Re: If Decision Fails Flowcode 5

Posted: Wed Nov 21, 2012 1:37 pm
by LeighM
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

Re: If Decision Fails Flowcode 5

Posted: Wed Nov 21, 2012 9:22 pm
by JLeith
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

Re: If Decision Fails Flowcode 5

Posted: Wed Nov 21, 2012 11:39 pm
by medelec35
Hi John,
Attached is how I detect which switch has been pressed.

It's the easiest way I can think of.

Martin

Re: If Decision Fails Flowcode 5

Posted: Wed Nov 21, 2012 11:53 pm
by dbasnett
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.

Re: If Decision Fails Flowcode 5

Posted: Thu Nov 22, 2012 2:09 am
by JLeith
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

Re: If Decision Fails Flowcode 5

Posted: Thu Nov 22, 2012 3:16 am
by JLeith
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