interupt on pin

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

interupt on pin

Post by brandonb »

what im trying to do is figure out how interupts work, can someone draw up a flowchart for a rising edge pin interupt for a pic16f690? what i was trying to do is when a quick logic edge is applied to a pin it enables a interupt and turns on a led for 1 second, i think that is said backwards because the interupt should always be watching the pin change then when pin change occurs it executes a maco in the main program? usually i would draw up a flowchart but on this one i dont know where to start

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: interupt on pin

Post by medelec35 »

Hi Brandon.
I have created a flowchart that should kill more than one bird with one stone so to speak.
The flowchart uses port interrupt on change, port INT pin (on RA2) and finally timer0 to count 1 second for LED.

Note: normally RB0 is used for port INT. However Port RA2 is used on 16F690. Therefore INT will not work with Flowcode simulator, but should work with real hardware.
With 16F690 port ioc (Interrupt On Change) is maskable, which means you can set the individual pins up. E.g Change on RB4, or RA0 etc.

How interrupts work is the main program runs normally. When an interrupt is fired, then the Main program is halted, the interrupt macro is accessed, then as soon as the interrupt macro has finished, then Main program continues where it was interrupted from.

This flowchart is created to work with non-maskable ioc as well.
Hope this helps.

Regards martin
Martin
Attachments
Flowcode_Interrupts.fcf
(11 KiB) Downloaded 355 times
Martin

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: interupt on pin

Post by medelec35 »

Here is an alternative version with nothing in main.

Martin
Attachments
Flowcode_Interrupts_Alternative.fcf
(11 KiB) Downloaded 337 times
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

martin, thats over my head, can you start me out simple with only one interupt on a page, thats kind of my problem with the interupts is that i dont know on the screen which part goes to what part and how they work together, i guess for simulation purposes could you start me off with just a port interupt, then i can look back over your draw ups in a different light

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: interupt on pin

Post by medelec35 »

Sorry Brandon,
I have simplified flowchart to just run port interrupt on change.

The way to follow how it works is just single step flowchart( press F8 function key).
Then every time you want to change switch state, just click switch, then keep pressing F8 key to follow what happens.

You should be able to see the port interrupt macro accessed when the switch has changed state from on to off
or
off to on

Alternately you can run the simulator on a slower speed, but that makes it a bit more difficult to follow.

Hope this helps

Martin
Attachments
Flowcode_Interrupts_port only.fcf
(8.5 KiB) Downloaded 334 times
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

thanks martin, thats a neat deal - (im gonna dwell on this for a while to give it time to sink in) then i'll get back with you on it if you dont mind...

Werner
Posts: 95
Joined: Sat Jun 11, 2011 4:12 am
Has thanked: 87 times
Been thanked: 31 times
Contact:

Re: interupt on pin

Post by Werner »

Hi Guys, Thanks Martin for the great interrupt examples! Can you please help me understand why the program does not work without the while loop in your Flowcode_Interrupts_Alternative.fcf example. I though I could just take it out because it didn’t look like it was doing anything, but I was wrong?
Werner
Werner
STUDENT OF: Martin - Professor of Flowcode, John, Jan, Fotios and Nicolas "Spanish Dude"

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: interupt on pin

Post by medelec35 »

You welcome.
Werner wrote: I though I could just take it out because it didn’t look like it was doing anything, but I was wrong?
Werner
The program has to be running (even though it's doing nothing but looping) in order to be interrupted and access interrupt macro when the port pin changes.
If you left a loop out, then the chip will just stop working.
In all flowcharts created, there must be a loop so when the last command is carried out, then it must start back at the beginning to carry out all the commands again.
You can put any thing within main loop. E.g read analogue pins, calculations, delays, LCD commands. All those will be constantly accessed, until interrupt is fired, then the current address e.g at the point of displaying a word 'Welcome' on LCD will be saved. The interrupt macro is accessed, then when interrupt macro is left, the program will continue from where it left off e.g finishing displaying the word 'Welcome' on LCD.

Take a look at:
http://www.matrixmultimedia.com/mmforum ... 90&p=15915

Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

suppose hypotheticly if have the chip turn on a output for 1 hour by making an output high then giving a 1 hour delay..... what would happen when i hit an interupt that would turn on another led for 10 seconds?........ what is the difference between a port interupt and a pin interupt? is it that the pin interupt has an option for rising or falling edge, is there anything other than that? .... also i noticed that if i change rocker position on the port interupt right when the led comes on the program goes back to the interupt then back where it was left off which causes a slightly longer delay in the micro seconds range, im guessing pin interupt wont do that

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: interupt on pin

Post by Benj »

Hello,
suppose hypotheticly if have the chip turn on a output for 1 hour by making an output high then giving a 1 hour delay..... what would happen when i hit an interupt that would turn on another led for 10 seconds?
Your 1 hour delay would become 1 hour and ten seconds, assuming you remained in the interrupt service macro for the 10 second delay.
what is the difference between a port interupt and a pin interupt?
Pin interrupt uses a single pin as its source, port interrupt can have multiple pins as the source. available settings for the port interrupt depend on the device you are using. The datasheet should detail the available functionality on your device.
also i noticed that if i change rocker position on the port interupt right when the led comes on the program goes back to the interupt then back where it was left off which causes a slightly longer delay in the micro seconds range, im guessing pin interupt wont do that
This is what all interrupts do. You have to imagine that your program is like a road your driving along. when an interrupt occurs its like a diversion off the main road. When the interrupt is finished you resume driving where you originally left the main road for the diversion. It is best practice to keep interrupt routines as short as possible so as to avoid changing any delays etc.

Hope this helps.

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

ben, i didnt state my question correct on that, the main thing is if i command an output pin on,then give it a long delay, then fire an interupt while the delay is still halting the program to command the output that is currently high to low will it do that even though the delay is not timed out yet? i would figure it would turn off the output then go to the next icon in the flowchart

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: interupt on pin

Post by medelec35 »

In reality it won't be a good idea to have interrupt force another delay whilst a delay is already running or corruption could occur.

But the there theory is if a one hour delay is running, and an interrupt is triggered when only 1/2 hour has passed, and there is 10 seconds in the interrupt macro, then the 1hr delay is paused, 10 seconds elapses, then the rest of 1 hr delay is continued. so 1 hr and 10 seconds elapses.

As Ben says interrupt routines should be kept as short as possible, so delays, and components with delays e.g LCD components should be avoided at all costs.

Not sure if that answers your question?

If it does not, perhaps it would help if you created a flowchart to back up your question and we could explain how it would work.

Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

alright martin i reverse engineered your flowchart for port interupt only... and i dont understand the importance of the rb4_previous=rb4 deal, if i take it out as in the fcf below everything works the same, do i need that in there for some reason? because the command before you turned on the led of led=0 edge triggers it..... i've been playing with some ideas in simulation and understand the importance of short interupts and how if there is a delay in an interupt how that could effect another component on times..... so the main question i should have asked because this is basicly what im trying to do is--> can i use an interupt to stop a long loop... suppose i have a count +1 skeem and on every count i have a pulsewidth loop, but on count #5 lets say i have a 8 minute loop! is there anyway i can use an interupt to stop that loop and not corrupt the chip with out pressing the mclr and resetting the whole thing... basicly i want to restart the loop from when it landed on the count#5.... possibly a count -1+1 calculation which would land me at the beginning of that loop but is it gonna want to go back to where it was after that loop runs through once.... do you want me to draw a fcf up on this?
Attachments
interupt ponder.fcf
(7 KiB) Downloaded 220 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: interupt on pin

Post by medelec35 »

Hi Brandon,
If you are only using 1 port B pin for interrupt then it is true you do not require rb4_previous=rb4 so it can be left out.

The reason I have placed it there is just in case more port B pins are used and the interrupts are not momentary e.g a taco signal. So it was to ensure reliability.

In hindsight, I should have left it out with what you require, I just add it out of habit.

Sorry not got time to help with the last part of question, will help a bit later today.

Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

martin- i'll have to remember that in future, i know everything you draw is there for a reason or future precaution (thats why i asked) :D

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: interupt on pin

Post by medelec35 »

Hi Brandon,
I have now added the timer0 interrupt. This interrupt is accessed 76 times every second. Each time interrupt is accessed, count is incremented by 1. So after 76 counts seconds are then incremented by 1
You can set time to any amount of minutes ( 1 to 32767) To start or continue delay from where it was paused it’s RB5. To pause delay before minutes has run out, it’s RB4.

If you could create a flowchart that shows what you’re after, then I can make alterations to this attached flowchart.
Martin
Attachments
interupt ponder2.fcf
(12 KiB) Downloaded 208 times
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

martin, i like the overflow fcf,that one has me thinking of lcd updating schemes.... i used a port interupt for the pulse counter project you helped with, using the 690 chip with 20Mhz crystal it works great, i wanted to up the enty and use a 16f1939, so i redid the fcf to accomidate that, 2 things i found weird, for one the lcd displays i have does not work with 32Mhz internal clock!! its like the frequency is higher than the lcd can interperate so nothing appears on screen except blocks if i turn the contrast all the wa up.... and the other thing is on the 16f1939 it doesnt have a port interrupt option so i used a int on pin, i found it to be a slower acting interupt, whats up with that? below is the file using the bigger chip with the 20 meg crystal
Attachments
1939 commander.fcf
(28.52 KiB) Downloaded 211 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: interupt on pin

Post by medelec35 »

If you would like to post the flowchart that you set for 32MHz int osc I can have a look at that.
The Miac is running at 48MHz and LCD display works OK.
It could be that you have set clock speed in project options to 32MHz, but the chip could be running at a much lower frequency?

Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

martin i dont think thats the case, because when i command 1m/s on time pulse i get it with the scope, the dipslay signals are there with the scope but it does nothing, when i use 20mHZ or less the display works, its like this with 3 different brands of displays also check out this post on the related http://www.matrixmultimedia.com/mmforum ... 939#p26356 and also this
Pay attention: At 32 MHz the E_block LCD will fail to show data, due to to short waiting times (which will decraese a factor 20/32).

Kind regrads,

Jan Lichtenbelt
i have confermed that at 16Mhz which is osccon0x78 command that it does work, i think jans post answers the question on the lcd, but what about the interupt speed, i thought he was saying something about that in the past also, but i dont remember under which post that was located
Attachments
1939 commander.fcf
(28.66 KiB) Downloaded 200 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: interupt on pin

Post by medelec35 »

Ah, yes, I remember seeing that post now.
brandonb wrote:martin i dont think thats the case, because when i command 1m/s on time pulse i get it with the scope
In that case I take back the suggestions about osc and config settings, they must be correct.
If I get a chance I could have a play and see if I have any luck getting LCD to work (with a different chip that has 32MHz int osc), but not that confident to be honest.

Martin
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

thanks martin, im looking at the datasheet for the 16f1939, could you take a gander at it and tell me which pins do interrupts in flowcode and what those pins are <im trying to use the datasheets to figure this stuff out but it gets confusing because they dont tell me flat out how it works

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: interupt on pin

Post by medelec35 »

Page 17 to page 21 of the datasheet shows RB0 to RB7 as

Code: Select all

Individually controlled interrupt-on-change
Or page 12 shows them as IOC.

The data sheet shows RB0 as INT as well

Since all of portB are Individually controlled you need to select which bits of portB you want to use for interrupts. But...........

However I can totally see why your confused. There is a bug in 16F1939.fcd file so its not allowing you to select portB interrupts (quiet a few of the 16F18xx and 16F19xx have missing portB Interrupt On Change selection). So it's not your fault!

If I get a chance to correct it (if I can of course) I will post it later today

Martin
Last edited by medelec35 on Sun Nov 20, 2011 4:18 am, edited 1 time in total.
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

thats what i seen too, all b port is single pin interupt.... b0 works but the other ones dont

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: interupt on pin

Post by medelec35 »

Hi Brandon,

I have corrected the 16f1939.fcd file. If you place this attachment, in Flowcode V4/FCD directory, then start up Flowcode (close 1st if already running)
You should be able to select the individual portB interrupt on change bits.
Just drag an interrupt component on to your flowchart.
Double click on it, then within the Interrupt on: drop down list there is a new PORT heading to select.
Then click on Properties. Make sure the individual bits are all changed so only the the bits you are using are left on, and all the rest are changed to off.
This fcd file like the others I modify, are unofficial and in this case I can't confirm it will work with your hardware as I don't have a 16F1939 to test with.
Hopefully it will work for you.

Martin

Edit: Changed Count=5 to Count=6
Forgot to do that. Posted corrected file.
But that won't make any difference to IOC issue.
Attachments
16F1939.fcd
(12.84 KiB) Downloaded 202 times
Last edited by medelec35 on Mon Nov 21, 2011 8:08 am, edited 1 time in total.
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: interupt on pin

Post by brandonb »

the port correction file when dropped in didnt work on hardware but did work in simulation, should i contact matrix for a fix on this? it appears that alot of chips are effected this way, below is a file of a port configuration, does work with hardware, is there a more efficient way to obtain the same results using a port configuration........... also form the previous posts the interrupt speed on the 1939 is not a problem anymore
Attachments
port question.fcf
(9.5 KiB) Downloaded 216 times

Post Reply