Port-pin variables

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

Post Reply
Brian Walsh
Posts: 29
Joined: Thu Jan 14, 2010 10:43 pm
Has thanked: 3 times
Contact:

Port-pin variables

Post by Brian Walsh »

First on the list of new software features in V5 is 'Port-pin variables to directly reference individual ports or pins'. I can't find anything in help about this and the video on the subject just shows the V4 procedure.

What I am expecting is a method whereby a variable can be associated with a port or a bit only once and thereafter the variable reflects the state of the i/o or vice versa directly without having to restate the variable / i/o relationship each time.

So can anyone explain how port-pin variables differ from the previous method and how to create and use them?

Thanks,

Brian Walsh.

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

Re: Port-pin variables

Post by Benj »

Hello Brian,

The variables are all available as standard when you load the v5 program.

Lets say you wanted to use a calculation icon to send the value 255 to port B.

In the calculation icon properties window select the ports tab of the variable manager and drag in PORTB.

Then add " = 255" without the quotes to give you.

$PORTB = 255

You can also do things like

$PORTA = $PORTB

And you can use this notation in any of the Flowcode parameter fields.

Eg the following component macro call would allow you to mask off the lower nibble of Port B and send it directly via the UART.

RS232_Send ( $PORTB & 0x0F )

Using . notation allows you to access the pins. The following code would set pin RB0.

$PORTB.0 = 1

Hope this helps.

saschech@gmx.de
Posts: 714
Joined: Wed Jan 31, 2007 12:41 pm
Has thanked: 1 time
Been thanked: 26 times
Contact:

Re: Port-pin variables

Post by saschech@gmx.de »

Hello Benj

What is the difference between the "OUTPUT-macro >> single bit portb 0 >> 1" and $PORTB.0 = 1?

Regards Wolfgang

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Port-pin variables

Post by JonnyW »

Hi. There should be no difference really - it is simply two ways of doing the same thing. I would say use whichever method you are comfortable with.

Jonny

Brian Walsh
Posts: 29
Joined: Thu Jan 14, 2010 10:43 pm
Has thanked: 3 times
Contact:

Re: Port-pin variables

Post by Brian Walsh »

Hi Benj,

OK, I get it. I can now see that the training video flowchart example updates Port A using the original Output Icon method and updates Port B using the new Port Variable assignment within a Calculation Icon method. Also thank you for confirming the .n bit access syntax.

I have to say, that being a huge fan of the graphical/visual nature of Flowcode, I am a little worried that I/O operations, previously on open view, can now lurk within calculation icons. That said, I have yet to evaluate the potential benefits of this new feature, which may warrant the risks, and I can still use the original style if readability is paramount.

I would add to your thanks quota but I can't figure out how to do that! (not much use eh?)

Brian Walsh.

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Port-pin variables

Post by JonnyW »

Hi Brian.

Yes, its always a concern when adding to the language. In v5 if you want to find all uses of a particular port you can go to the Project Explorer, select the 'Ports' tab and in the menu for your port select 'List occurrences'. This will show all the uses of the variable. Note this does not list the input/output icon uses (though perhaps it should).

This feature was added originally so that no variables need to be used to do certain operations, such as an input icon that does 'PORTA -> $PORTB' to copy the contents of PORTA to PORTB without an intermediate variable.

I hope this helps put any fears to rest!

Jonny

PS: To thank, there is a little 'thumbs up' icon to the top right of each post. Clicking on this should thank for the post.

Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Re: Port-pin variables TRIS

Post by Mark »

Hi Jonny,

What is the interaction of the variables with the TRIS registers?

For example, if you have previously used an Output and an Input Icon and effectively defined, say, TRISB as 0b11110000.
1 - In if I recall.

Then since I am writing the ports with a byte (presumably by definition), such as $PortB = 0b01010101.
Then what will actually be going to happen? Both to the Port and to TRIS?

Whilst I expect I can find this out by experiment I would rather know the underlying rule.

Many thanks,

Mark
Go with the Flow.

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Port-pin variables

Post by JonnyW »

Hi. The TRIS will always be written as required for input or output.

This means if you do $PORTB = 0b01010101 the TRIS will always be set as an output first for all bits, so TRIS = 0b00000000. In project-wide cases where this is not necessary you can add the following to supplementary code:

#define FCP_USE_TRIS 0

This will prevent writing to the TRIS on the 'variable' use - note the input and output icons will still set the TRIS for that operation. This may be more efficient if you are pushed for speed but I think it will take the same space.

Cheers,

Jonny

Mark
Posts: 209
Joined: Thu Oct 19, 2006 11:46 am
Location: Bakewell, UK
Has thanked: 20 times
Been thanked: 16 times
Contact:

Re: Port-pin variables

Post by Mark »

Hi,

Thanks, and thanks for providing the 'workaround'.

My request is that the '#define FCP_USE_TRIS 0' be implemented as a checkbox in the global setup options in some future version.
I can see all sorts of problems from using say Variable = PortC, the previous outputs then become high impedance and,
say, a motor control line then floats giving rise to all sorts of interesting effects.

Many thanks,

Mark
Go with the Flow.

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: Port-pin variables

Post by JonnyW »

Hi. Nice idea, I don't see why we can't do this in a future release of Flowcode.

Jonny

Post Reply