Page 1 of 1

Switches problem

Posted: Sun Sep 05, 2021 12:25 pm
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

Re: Switches problem

Posted: Sun Sep 05, 2021 3:32 pm
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

Re: Switches problem

Posted: Mon Sep 06, 2021 2:53 pm
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

Re: Switches problem

Posted: Tue Sep 07, 2021 1:00 pm
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.

Re: Switches problem

Posted: Tue Sep 07, 2021 3:15 pm
by medelec35
Hi Frank,
Do you want to see if the attached flowchart does what you want it to do?

Re: Switches problem

Posted: Tue Sep 07, 2021 4:12 pm
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.

Re: Switches problem

Posted: Tue Sep 07, 2021 4:14 pm
by medelec35
OK thanks, so the flowchart I created is what you wanted it to do?

Re: Switches problem

Posted: Tue Sep 07, 2021 4:29 pm
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”)

Re: Switches problem

Posted: Tue Sep 07, 2021 8:41 pm
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

Re: Switches problem

Posted: Sun Sep 12, 2021 10:05 am
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?

Re: Switches problem

Posted: Sun Sep 12, 2021 11:36 am
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 8631 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.

Re: Switches problem

Posted: Sun Sep 12, 2021 12:31 pm
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 !

Re: Switches problem

Posted: Sun Sep 12, 2021 1:00 pm
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.

Re: Switches problem

Posted: Sun Sep 12, 2021 6:50 pm
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?

Re: Switches problem

Posted: Mon Sep 13, 2021 2:53 pm
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.

Re: Switches problem

Posted: Mon Sep 13, 2021 5:28 pm
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.

Re: Switches problem

Posted: Tue Sep 14, 2021 4:32 pm
by Frank607
Hi Martin,

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

Re: Switches problem

Posted: Wed Sep 15, 2021 4:10 pm
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

Re: Switches problem

Posted: Wed Sep 15, 2021 6:22 pm
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.