IO pin as variable

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
CamargoF
Posts: 36
Joined: Thu Aug 02, 2018 8:16 pm
Location: Sao Paulo, SP - Brazil
Has thanked: 6 times
Been thanked: 7 times
Contact:

IO pin as variable

Post by CamargoF »

Can you please clarify the following doubts about IO in Flowcode?
  • Is it possible to create a macro were the PORT and/or PIN can be provided as parameter? If it is possible, can you please provide some example?
  • I set on panel properties panel few definitions of digital pin to be used on macros. So I can change the PORT/PIN easilly, but the INPUT/OUTPUT blocks do not accept any of these definitions. The only way to use it is using the CALCULATION blocks. Can you please confirm these two code writing will generate the same code, configuring all register correctly?

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: IO pin as variable

Post by mnf »

Unfortunately (I think it would be a useful feature) - FC doesn't seem to support this directly.

However it is pretty easy to implement a macro to do it for you:
SetPortPin.fcfx
(7.93 KiB) Downloaded 201 times
Note that this is specific for AVR (328p) processors - with ports B, C and D - and would need to be tweaked for other MCUs. The principle is simple though...

Martin

User avatar
CamargoF
Posts: 36
Joined: Thu Aug 02, 2018 8:16 pm
Location: Sao Paulo, SP - Brazil
Has thanked: 6 times
Been thanked: 7 times
Contact:

Re: IO pin as variable

Post by CamargoF »

And what about the properties?
If I create a property TXpin = $PORTC.3 and a local bir variable .flag, the compiled code will be the same read an input pin:
  • INPUT BLOCK $PORTC.3 --> .flag
  • CALCULATION BLOCK .flag = TXpin
and to write to an output pin:
  • OUTPUT BLOCK .flag --> $PORTC.3
  • CALCULATION BLOCK TXpin = .flag

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: IO pin as variable

Post by mnf »

The Input/Output blocks don't accept/use the variables - however using them in a calculation works perfectly.

Code: Select all

TXpin = .flag
.flag = TXpin
generates:

Code: Select all

    
    SET_PORT_PIN(B, 1, FCL_FLAG);
    FCL_FLAG = GET_PORT_PIN(B, 1);
(With TXpin set to port B1)

Martin

User avatar
Steve
Matrix Staff
Posts: 3421
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: IO pin as variable

Post by Steve »

Another thing you could do if you wanted to preserve the look of your flowchart is to use an input or output icon and customize the C code appropriately.

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: IO pin as variable

Post by Benj »

For dynamic pins where you want easy configuration but fixed at compile time use a pin property and calculation icons.

For dynamic pins where you need dynamic functionality on the embedded device use a function like Martin created.

The I/O icons are not currently dynamic and will always target a fixed port or pin and so if you change the pin you will have to edit every icon that references it.

Post Reply