A simple flowchart, does not work as expected

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

Moderators: Benj, Mods

Post Reply
medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

A simple flowchart, does not work as expected

Post by medelec35 »

Very Basic application. With 12F615

PWM stopped working so I suspected actual chip.

Created a very basic test.
Surprisingly if use whole port = 1 or use port masking only Bit 0 works in simulation and in practice on real hardware.
However If I use separate port A bit 0, bit 1, and bit2 etc. then ports work as expected.
Why don’t all bits toggle every ½ second?
Attachments
12F615 port test.fcf
(4 KiB) Downloaded 268 times
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: A simple flowchart, does not work as expected

Post by medelec35 »

With entire port A set at 1, so all of port A should be at 5V (except GP3 which is input only) here is C code created by Flowcode:

//Output
//Output: 1 -> PORT A
trisio = 0x00;
gpio = 1;

That’s why only A0 only lights up
Also If I’m right about GP3, should Flowcode warn that GP3 is an I/P only pin.

Otherwise I would expect it to light LED on my chip since it does in the simulation.
Martin

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

Re: A simple flowchart, does not work as expected

Post by Steve »

Setting porta to 1 will only set pin A0 high. If you want to set all of a port high, set it to 255 (0xFF in hex or 0b11111111 in bin).

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: A simple flowchart, does not work as expected

Post by medelec35 »

medelec35 wrote:
whole port .

Above code was automatically compiled by Flowcode, after port A output was set for ALL bits = 1
See attachment.

I would assume that if all bits of port A set to 1
Then Flowcode would light All LEDs and not just bit 0 LED
So question is why is only bit 0 set, when I ticked ENTIRE port A to be set for 1?
Attachments
port question.JPG
port question.JPG (51.32 KiB) Viewed 5417 times
Martin

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

Re: A simple flowchart, does not work as expected

Post by Steve »

The value "1" is 0b00000001 in binary and would only turn on output A0.

If the value was "2", this is 0b00000010 in binary and would only turn on output A1.

If the value was "3", this is 0b00000011 in binary and would turn on both A0 and A1.

If the value was "255", this is 0b11111111 in binary and would turn on all outputs on the port.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: A simple flowchart, does not work as expected

Post by medelec35 »

So are you saying : If you tick Entire port and set for 1 as in the picture then only bit 0 will be set at 1. if thas the case why is there a option to have Entire port ticked. If I did not know any different, if i saw an option for Entire port , and put a 1 in the Variable or Value box, I would expect the whole port (bits 0-7) to be set at 5 V (unless its i/p only) Not just set bit 0 to 5V and bits 1-7 to 0V.

Aslo if I set bit 3 to a value of 1

then after a delay set Enitre port to a value of 0
then LED at bit 3 will will go out.

So in effect Entire port set to 1 = only bit 0 will be set at 1, all other bits (1 -7) set a 0 (this is what you are saying)?

then Entire port set to 0 = all bits witll be set at 0..... This does not make sence, surly its wrong, or am I missing somthing obvious?
Martin

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

Re: A simple flowchart, does not work as expected

Post by Steve »

A port on a PICmicro is 8-bit's wide. When outputting to an entire port, you are setting the output that should be present on the entire port - and the value you enter will be the value (ie. the bit-pattern) on the entire port.

If you want an entire port to be on, write 255 to the port.
If you want an entire port to be off, write 0 to the port.
If you want the top half of the port to be on and the lower half of the port to be off, write 0xF0 to the port.

"Entire port" means you are setting the output of the entire port at once. It does not mean you are setting every individual pin on that port to the same value.

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: A simple flowchart, does not work as expected

Post by medelec35 »

Ah I see. That explains it!
So that means also If i want certain bits on, all I need to do is set port at 255 Enable Entire port, then use masking, mask bits I would like to be set.
Simple when you know how. :mrgreen:
Martin

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

Re: A simple flowchart, does not work as expected

Post by Steve »

Yes - you've got it!

And just for completeness, if you are using the "single bit" option, then you need to enter "0" for "off" and anything else for "on".

Post Reply