Switches problem

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

Moderator: Benj

Post Reply
Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Switches problem

Post by Frank607 »

I have a problem with switches. I think it is a small problem but I can’t figure it out.

I have four momentary buttons and I get them to work. They won’t come out of the loop.
It must be a simple error what I have made.

Attached is the fcfx file.

I hope that someone can find this error.

Thanks,

Frank
Attachments
Switches Test - 01.fcfx
(45.21 KiB) Downloaded 102 times

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: Switches problem

Post by siliconchip »

hi frank
from what i can see in your macros your main loop is "loop while 1" therefore continuously looping, I've changed the first 2 macros to "loop count 1" so they will only loop once and i changed the cross and corner macros to "loop count 4" as an example is this what you were looking for

bob
Attachments
Switches Test - 01.fcfx
(52.64 KiB) Downloaded 97 times

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

Hi Bob,

Thanks for helping.

All Macro’s must loop forever until I press a switch for the next Macro. I have modified the file to show what I mean.

Frank
Attachments
Switches Test - 02.fcfx
(44.96 KiB) Downloaded 105 times

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

I have made a better flowcode but still the switches don’t work. And I can’t figure out why.

When I press a switch it must immediately show the Macro what belongs to the switch. Not waiting before the running Macro is finished.

Attached is what I have made so far.
Attachments
Switches Test - 03.fcfx
(44.68 KiB) Downloaded 100 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: Switches problem

Post by medelec35 »

Hi Frank,
Do you want to see if the attached flowchart does what you want it to do?
Attachments
Switches Test - 04.fcfx
(58.22 KiB) Downloaded 111 times
Martin

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

Hi Martin,

Wow, very nice work !! Total different than I had in mind. It keeps me learning.

I will work on the Cross macro according the Arrow Left and Right tomorrow.

I will let you know how it goes and post the final fcfx code here for other users.

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: Switches problem

Post by medelec35 »

OK thanks, so the flowchart I created is what you wanted it to do?
Martin

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

Yes, this PCB (switch input) will be controlled by a other component what only give short pulses on the switch inputs on this PCB.

So, in simulation it works great. Tomorrow I will test this in hardware. (if I have no call for a “rush job”)

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: Switches problem

Post by medelec35 »

Hi, Frank.
The attached flowchart is designed to exit the current looping macro within 20ms of pressing a switch.
It should not matter where within the macro is currently being executed.
I can imagine that is more what you are after?

Note:
When running on hardware, the IsSim branch within Timer ISR is false
Attachments
Switches Test - 05.fcfx
(61.62 KiB) Downloaded 108 times
Martin

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

Hi Martin,

I’m working with Switches Test - 04.fcfx. (05 gives errors, but that is for later)

The switches (B0, B1, B2 and B3) pin’s on the PIC gets a GND signal from optocouplers. So the switches are Active Low.

I thought it was easy to change this is this 04 code. But unfortunately not.

Can you tell me what I have to change to get this to work in Hardware?

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: Switches problem

Post by medelec35 »

Hi, Frank.
To change the flowchart so switches are active low, all you need to do is change the switch properties from active high to active low.
That is so the simulation will work correctly.
Then within the timer interrupt, I added a calculation icon, just below the input icon:
Added Calculation.png
Added Calculation.png (27.58 KiB) Viewed 4873 times

Code: Select all

.Switch = 15 - .Switch
Frank607 wrote:
Sun Sep 12, 2021 10:05 am
05 gives errors
That can be fixed.
If the issue is a message stating 'This project was built with a newer version' etc that can be ignored.
If related to IsSim then make sure you run a full update with the Full-Database option.
If that does not fix it then there is a way around it.
Attachments
Switches Test - 04 Inverted.fcfx
(50.06 KiB) Downloaded 75 times
Martin

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

Hi Martin,

I had changed the properties of the switches from High to Low. That dint work, so I chanced so more things to see if it works. But it didn’t.

Your calculation did the job ! It works now perfectly :-)

Many thanks !

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

Hi Martin,

On the PCB is also a remote control connect to D7, D0, C3 and C1 - Active High. I have to program the remote control (KEELOQ) and then I will try to implement this into the 04 - Inverted file.

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: Switches problem

Post by medelec35 »

Hi Frank,
Your welcome.
Is the remote is going to override the opto's?
Or will it be the other way around?
I'm just thinking what if both was active at the same time?
If I was you, I would give one priority over the other.
I can help you with that if required?
Martin

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

Hi Martin,

Thanks.

For what I understand is that the external box in the car will send pulses to the switches. So the working of this code is good. See YouTube link: https://youtu.be/ckraJEgPnIs . I have made a small test board with 5mm LEDs to see of it works.

So the remote control sends pulses from 0.5 second long in an Active High state directly to the PIC.

When I was developing this PCB I was unsure how this external box will work, that why I choose to use four extra pins for the remote control. Just to be safe.

Example:
When one of the switches is activating Macro1 and when I press a switch on the Remote Control for Macro2, than Macro2 must be active. And so on. Apart from each other.

Attached is the code so far I have.
Attachments
Switches Test - 05 - Inverted Switches with RC.fcfx
(52.22 KiB) Downloaded 61 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: Switches problem

Post by medelec35 »

Hi, Frank.
Wow, the video looks great!
Adding the extra switches that are active high making it slightly more complex.
I have done that for you.
What makes it more complex are the extra switches are C1,C3, D0 and D7 rather than D0, D1, D2 and D3 etc.
Now you can use the combination of active high and active low switches.
The command will always be the last switch detected.
Attachments
Switches Test - 06 - Inverted Switches with RC.fcfx
(54.22 KiB) Downloaded 63 times
Martin

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

Hi Martin,

I will answer tomorrow. To many things to do :-(

Frank607
Posts: 192
Joined: Mon Mar 04, 2013 8:07 pm
Has thanked: 29 times
Been thanked: 15 times
Contact:

Re: Switches problem

Post by Frank607 »

Hi Martin,

Wow this works perfectly!! Thank you very much for this code. I'm trying to understand this code so that I can understand it better as well.

Unfortunately the pins have different ports and not D0, D1, D2 and D3. This has to do with how the PIC is placed on the PCB. I tried to keep lines as short as possible to all MOSFETs.

Thanks again.

Greeting,

Frank

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: Switches problem

Post by medelec35 »

Hi, Frank.
Frank607 wrote:
Wed Sep 15, 2021 4:10 pm
Wow this works perfectly!! Thank you very much for this code.
That's excellent, I glad its working for you.
You are welcome.
Frank607 wrote:
Wed Sep 15, 2021 4:10 pm
Unfortunately the pins have different ports and not D0, D1, D2 and D3. This has to do with how the PIC is placed on the PCB.

I totally understand and that is how it should be done.
All I was saying it makes it slightly more complex.
I stated that in case you waned to see how the flowchart works.
Martin

Post Reply