Page 1 of 1
Port-pin variables
Posted: Fri May 25, 2012 1:45 pm
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.
Re: Port-pin variables
Posted: Fri May 25, 2012 2:44 pm
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.
Re: Port-pin variables
Posted: Fri May 25, 2012 6:06 pm
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
Re: Port-pin variables
Posted: Fri May 25, 2012 9:49 pm
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
Re: Port-pin variables
Posted: Mon May 28, 2012 2:29 am
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.
Re: Port-pin variables
Posted: Mon May 28, 2012 10:18 am
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.
Re: Port-pin variables TRIS
Posted: Mon May 28, 2012 12:55 pm
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
Re: Port-pin variables
Posted: Mon May 28, 2012 2:43 pm
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
Re: Port-pin variables
Posted: Tue May 29, 2012 2:36 pm
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
Re: Port-pin variables
Posted: Tue May 29, 2012 9:37 pm
by JonnyW
Hi. Nice idea, I don't see why we can't do this in a future release of Flowcode.
Jonny