Help with Flowchart Please

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
JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Help with Flowchart Please

Post by JDR04 »

Hello folks, could somebody please help me with my program.

I have attached a flowchart of what I am trying to achieve. (Might explain better what I am wanting to achieve)I have also attached the program I have done so far but am really struggling, so any help with it wil be appreciated.

Basically, I have a infrared sensor that goes HIGH when activated.(3.3 Volts)

I would like to create a program that by way of a rotary switch (5 positions) I can turn a LED ON for different time periods. ie, 1 sec, 2 sec, 5 sec,8 sec and 12 seconds. Selectable by the rotary switch.

I would then also like to have a TIME OUT period which also is selecatble by a 5 position rotary switch. The TIME OUT period is intended to delay the whole cycle before the PIC executes the cycle again.

I've been trying for 2 days now to figure out how I can read what position the switch is in and how to make it follown the intended activation and delay period that is intended. I also need to know how I can read a pin when it has the 3.3 VOLTS on it.

I've attached the program I have tried so far but alas have failed.

I would really appreciate the help, many thanks John
Attachments
IR Detect Program 1.fcf
(10 KiB) Downloaded 254 times
IR Detector Flow Chart 1.doc
(32 KiB) Downloaded 261 times

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

Re: Help with Flowchart Please

Post by medelec35 »

Hi John,
Attached is one way of achieving what you want.
The configuration settings have not been set up, so that will have to be completed before trying on hardware.

If there are a fair amount of switches, Then you can use just one analogue pin and use all the switches to be part of a potential divider.
It means connecting additional resistors, but the cost saving are in a smaller microcontroller and PCB.
Just a thought.

Hope this is near to what you want.

Martin
Attachments
IR Detect Program 1a.fcf
(18 KiB) Downloaded 267 times
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Help with Flowchart Please

Post by JDR04 »

Many thanks for that. I'll need a day or two to go through it and get back to you.

Really appreciate your help-Thanks again John

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

Re: Help with Flowchart Please

Post by medelec35 »

No problem John.
I have changed the LED connection just so the switches can be connected to the same port to simplify software.
Hop it goes well for you.

Martin
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Help with Flowchart Please

Post by JDR04 »

Thanks for all the help so far.

To understand it all I have decided to build in a delay period before the LED actually comes on and then I will add it to the flowchart you have alread done for me.

I've managed to get most of it to work but have a problem when I use switch A3/4, delay of 2 seconds. However when I use this switch I get a UNINITIALSED VARIABLE. Clearly I'm missing something here as I've tried to replicate Martins flowchart but have missed something out.

If somebody could spot my mistake I would really appreciate it. Thanks again - John
Attachments
2ND FLOWCODE PROGRAM.fcf
(11.5 KiB) Downloaded 260 times

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

Re: Help with Flowchart Please

Post by medelec35 »

Hi John.
The uninitialised error will occur if the bank of switches connected to port a are switch in such a way that the value of Read_Switch2 does not equal to any of the switch branch values i.e 1, 2 or 4
When that happens the switch component exits our of the default bottom branch instead of the right hand side.
Error shows because the uninitialised variable is being read before its written to (assigned with a number).
You

All you need to do is either:
1) assign an initial value of Delay variable by going into Project explorer and selecting global tab.
Double click the variable in question then enter a number for the Initial value box.

2) Place a calculation box with

Code: Select all

Delay = x
(Replace x with the required delay time) either on the default branch (bottom branch)
or just after Output 1>A0 icon.

Martin
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Help with Flowchart Please

Post by JDR04 »

Hi Martin, I'm not sure I understand this properly.

Are you saying that the switch numbers and connections must be the same as the bit numbers of the port.ie Switch1 connects to bit 1 of the port. The next switch connects to bit 2 and so on? I've tried it but have missed something as;

When I add a variable two branches of the switch do not work? Also, I noticed in your flowchart you have "SwitchReadSwitch1" for the second branch. Is this just a oversight or is it for a good reason?

Anyway, I have attached my flowchart and would appreciate your correction. Many thanks,again......John
Attachments
2ND FLOWCODE PROGRAM.fcf
(12 KiB) Downloaded 248 times

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

Re: Help with Flowchart Please

Post by medelec35 »

Hi John
JDR04 wrote:Are you saying that the switch numbers and connections must be the same as the bit numbers of the port.ie Switch1 connects to bit 1 of the port.
No not necessarily.
You can connect any switch to any i/p pin, so long as you have the correct values set up in the switch component.
I have placed this in the attached flowchart as a reminder:

Code: Select all

Switch connected          Variable value
to portA                  if sw is connected to +5
0                               1
1                               2 
2                               4
3                               8
4                               16
5                               32
6                               64
7                               128
You can have switch connected to porta 6.
So long as one of branches = 64 then switch will be detected.  
So if a switch is connected to porta3. a5 and a7 the branches has to be:
switch component1.png
(19.89 KiB) Downloaded 5649 times
JDR04 wrote:When I add a variable two branches of the switch do not work?
I have corrected your flowchart. the branches had the wrong value for the switch connections.
medelec35 wrote: Is this just a oversight or is it for a good reason?
It's error.
Should have been SwitchReadSwitch2 not SwitchReadSwitch1.

I have also added a continuous loop to the attached flowchart so you can keep trying the different switch combinations.

Another thing to note:
you have detect multiple switch detection, so long as you place the correct value within switch component.
E.g If I want to detect two switches, one connected a2 and the other connected to a3 then value when both switches are on simultaneously is 4+8 = 12
Therefore 12 is required in the branch.

I have also assigned Delay variable with an initial value of 0.

Martin
Attachments
2ND FLOWCODE PROGRAM a.fcf
(12.51 KiB) Downloaded 270 times
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Help with Flowchart Please

Post by JDR04 »

Thanks Martin, really,really appreciate your time and patience.

I'm going to check out what you have done and get to understand it.

Thanks again.........John

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

Re: Help with Flowchart Please

Post by medelec35 »

No problem John,
Hope I have helped :-)

Martin
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Help with Flowchart Please

Post by JDR04 »

Ping..........the penny finally dropped. I now understand the switches etc.

Could I ask you how I could replace all the switches with one adjustable delay. I think I would now like to learn how to do an "adjustable delay" up to about 30 seconds.

Would really appreciate the extra help. Thanks a lot- John

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

Re: Help with Flowchart Please

Post by medelec35 »

Hi John,
JDR04 wrote:Ping..........the penny finally dropped. I now understand the switches etc.
Nice one.
Feels good doesn't it. :)
First it would be best if you decide what hardware is required to adjust delays.
I could be a variable resistor (potentiometer or trimmer) so you would use the ADC component.
Or 2 switches. 1 for increase delay, 1 for decrease delay.
Then you will need to decide the delay resolution, i.e. the minimum value of delay for each step.

Then we can take it further.

Martin.
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Help with Flowchart Please

Post by JDR04 »

Hi Martin, yep it feels good to start putting bits and pieces together......thanks to your patience.

I have strated another flowchart and have taken it as far as I can.(attached) It would be nice if I could use a potentiometer to adjust the delay period. The greater the resolution the better as very small amounts of adjustment would in the end make my life a lot easier.

Thanks a ton...John
Attachments
Adjustable Delay Program 1.fcf
(7 KiB) Downloaded 191 times

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

Re: Help with Flowchart Please

Post by medelec35 »

Hi John,
No problem.

Attached is a flowchart that will have an adjustable delay (two lots in fact) from 0 to 30.6 seconds with a resolution of 30ms
It work by reading analogue channel and converting from 0 to 1023 (When you use ReadAsInt).
The 0 to 1023 is multiplied by 30 to give a range of 0 to 30690 which is used for the ms delay component.
By adding two delays the the LED will be on and off for equal times.

Martin
Attachments
Adjustable Delay Program 1.1.fcf
(7.5 KiB) Downloaded 190 times
Martin

JDR04
Posts: 271
Joined: Tue Mar 05, 2013 10:49 pm
Has thanked: 111 times
Been thanked: 13 times
Contact:

Re: Help with Flowchart Please

Post by JDR04 »

Thanks a ton, I'll play around with it for a while and see what happens.

Really appreciate your time and help......and patience of course . John

Post Reply