interrupt

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
DELAK_ALED
Posts: 23
Joined: Sat Jun 21, 2014 11:04 am
Has thanked: 5 times
Been thanked: 2 times

interrupt

Post by DELAK_ALED »

Hello,
With this program I want to increment a counter one time. In simulation it increments two times. How can I avoid this?
Thanks in advance.
Attachments
interrupt.fcfx
(6.83 KiB) Downloaded 259 times

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: interrupt

Post by medelec35 »

Hi DELAK_ALED,
since IOC is Interrupt On Change and there is not a IOC Register on your target device, ISR will be accessed when any of IOC pins go from low to high or high to low.
So If operating one button at a time then the attached flowchart is a simple way around your issue.

It does not take contact bounce into consideration.

Martin
Attachments
interrupt V2.fcfx
(7.28 KiB) Downloaded 258 times
Martin

DELAK_ALED
Posts: 23
Joined: Sat Jun 21, 2014 11:04 am
Has thanked: 5 times
Been thanked: 2 times

Re: interrupt

Post by DELAK_ALED »

Thanks Martin for your reply.
I have tried to adjust your program. My intention was to encrement the variable if I push RB5 and to decrement the variable if I push RB4.
(I must use an interrupt)
In simulation it works fine, but if I download the program in the formula flowcode buggy it doesn't work correctly.
Is it possible to adjust the program in a simple way, so it works also correct on the buggy?
Attachments
interrupt V3.fcfx
(7.84 KiB) Downloaded 243 times

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: interrupt

Post by medelec35 »

Hi DELAK_ALED,
Can you try the attached flowchart, and see if that works the way you want it to.
Tried to keep as simple as possible.

Martin
Attachments
interrupt V4.fcfx
(7.81 KiB) Downloaded 256 times
Martin

DELAK_ALED
Posts: 23
Joined: Sat Jun 21, 2014 11:04 am
Has thanked: 5 times
Been thanked: 2 times

Re: interrupt

Post by DELAK_ALED »

Hi,
Unfortunately, your program interrupt V4 doesn't work in simulation and it doesn't work on the formula flowcode buggy.
In te program interrupt V5 I add one pictrogram and now I see the variable = 100 and if there was one interrupt the variable is always 50.

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: interrupt

Post by medelec35 »

Hi DELAK_ALED,
The flowchart I posted was not tried on hardware, as my hardware was set up for something else.
The attached flowchart takes into account contact bounce.
Both hardware and Flowcode simulator works fine for me.

Can you try it and see if it works any better for you.


Martin
Attachments
interrupt V5.fcfx
(8.36 KiB) Downloaded 235 times
Martin

DELAK_ALED
Posts: 23
Joined: Sat Jun 21, 2014 11:04 am
Has thanked: 5 times
Been thanked: 2 times

Re: interrupt

Post by DELAK_ALED »

Hi Martin,
In simulation it works now fine. For my hardware I have to change the connection of the LCD to portD,
because there is only one subd on portD.
On my hardware (the formula flowcode buggy) it doesn't work. The variable has always the value 100, even if I push B4 or B5

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: interrupt

Post by medelec35 »

Sorry I changed the LCD for my hardware, and forget to change it back to portD.
I have tested with EB007 connected to portB.
Pressing sw5 (connected to B5) incremented display by 1 and sw4 (connected to B4 ) decremented by 1.
So not sure why its not working for you?

Unfortunately I don't have a buggy to test with.

How about creating a flowchart that output on portD is the same as input on portB?
Then you can press the switches and see if output on portD by measuring the voltages on port D.

Also can you measure the voltage at port B4 & B5 when switches are pressed and released?
Martin

DELAK_ALED
Posts: 23
Joined: Sat Jun 21, 2014 11:04 am
Has thanked: 5 times
Been thanked: 2 times

Re: interrupt

Post by DELAK_ALED »

I have tested the program interrupt V5 with the hardware combination EB006-18F4455, LCD EB005 on port D and switches EB007 on portB and indeed the program works fine.
When I use the formula flowcode buggy (with µC 18F4455) the LCD on the subD =portD and the two switches are connected to B4 and B5 the program doesn't work. The variable stays 100
Afterwards I have adjusted the program to interrupt V6. (see attachment) I use now a mask on portB
Result: decrement the variable works fine
increment the variable works sometimes. When I push very fast I have an increment, when I push a little bit slower the variable := variable + 2
Attachments
interrupt V6.fcfx
(8.61 KiB) Downloaded 245 times

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: interrupt

Post by medelec35 »

DELAK_ALED wrote:When I use the formula flowcode buggy (with µC 18F4455) the LCD on the subD =portD and the two switches are connected to B4 and B5 the program doesn't work. The variable stays 100
Sorry not sure why that is?
Very odd though.
DELAK_ALED wrote:increment the variable works sometimes. When I push very fast I have an increment, when I push a little bit slower the variable := variable + 2
Perhaps you can increase the delay in the decision branch to 100ms?

Sounds like your'e nearly there.
Martin

DELAK_ALED
Posts: 23
Joined: Sat Jun 21, 2014 11:04 am
Has thanked: 5 times
Been thanked: 2 times

Re: interrupt

Post by DELAK_ALED »

Thank you for helping me out of my problem.
I have increased the delay time to 150 ms. Now the program works verry good ( the increment and also the decrement) :)
Attachments
interrupt V7.fcfx
(8.61 KiB) Downloaded 208 times

Post Reply