Interupts - My misconceptions

Status
Not open for further replies.

SwingeyP

Member
Ok heres what I think then you can all say Oooh No - thats all wrong.

1:
look at serial line is there a code
NO? goback to 1
Yes? Ok what is the code?
Walk forward code?
Yes - lets walk forwards
Walk forward
Walk forward
walk forward

INTERUPT! - Excuse me!

Oh theres an interupt go to the interupt code

walk forward
walk forward

Interupt code:
Hey the ultrasonic sensor has detected something on the left
Turn right
turn right
turn right

blah blah

Ok now im stuck. What if the interupt comes with something on the right whilst its doing this ....

Hmmmm can anyone give me some psuedo code steps please? or just the basics. I understand that when an interupt is triggered it runs 'other' code - can keep registers etc in their states, and can return to where it left off etc...

Regards - Paul
 
hi Paul,
In Oshonsoft do this

Code:
ON INTERRUPT 
SAVE SYSTEM 
''' save the registers
'clear the flag causing the interrupt
'do whatever the intr subr is written for

' if necessary re-enable the intr
''restore the registers
RESUME


EDIT: which interrupts are you using.??
 
Last edited:
hi Paul,

Interrupts.

Condition #1.
Assume you are watching a DVD movie, the front door bell rings, you stop the DVD player and you go to answer the door.
You take care of the person at the door and then go back and restart the DVD where it left off.

Condition #2.
Assume you are watching a DVD movie, the front door bell rings, you stop the DVD player and you go to answer the door.
While you are talking to the person at the front door the phone rings, it could be important, so you tell the person at the door to wait and you answer the phone.

You take care of the person on the phone , hang up and then go back and deal with the door caller, when done you go back and restart the DVD where it left off.

Condition #3.
Assume you are watching a DVD movie, the front door bell rings and the phone rings at the same time, you stop the DVD player.
You now have to decide which caller will be given priority.

So basically, if you have more than one source of interruption, when an interrupt occurs you test the interrupt flags you have enabled, in order to determine who is interrupting and if necessary decide priority,
 
Hi Eric. That all makes a lot of sense. I haven't even thought about waht interupt i'll be using as yet. The chip will be a pic 16f876a. I'll have a read of the datasheet tonight and see what I can unravel.

Regards - Paul
 
First understand that interrupts MUST originate in hardware, in a very limited number of sources. The interrupt source is something very basic.

So it'd be a doorbell being pressed as the interrupt.
"Hey the ultrasonic sensor has detected something on the left" doesn't make a lot of sense, because there's no hardware module in a PIC which would readily see that and fire off an interrupt. Code would determine whether something's near. Now the ADC may be watching the sound level off ultrasonic receiver hardware, and the interrupt says when the ADC is done and thus your code checks it on a regular schedule to see what the ADC reading means.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…