Can any one guide me

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can any one guide me

1,896 Views
saravanan_TTL
Contributor I
Hi,
As Iam new to this field I need some help from your side. iam using HCS12 TB(MC9s12dp512),ICC12(version 7),Compod12, NOICE debugger.
I have tried some basic program like toggle led,turn on buzzer ect.,
Now I want to learn about interrupts,Like when i press a switch the interrupt should occur.
Did you guide me how to write code to for enabling the interrupts or if you have some sample programs kindly send it to me.
Thanking you.
Regards,
Saravanan.A
Labels (1)
0 Kudos
5 Replies

429 Views
mke_et
Contributor IV
Hi Saravan!

Interrupts are easy. It's more of a mindset that you have to have than anything else.

What I've found is the easiest is to wrote a routine in normal foreground and get it working. Then, make absolutely sure it's 'safe' in that it leaves everything on exit the way it came in. That doesn't mean just registers, but in your case right now that probably doesn't make sense. However, in the future, you can have Interrupt Service routines do things like toggle a character on a display. In that case, your ISR has to be able to do something like sniff out the latch state (or whatever) of say an LCD and save it. What if there's another routine in the middle of streaming a data string to your LCD and you interrupt it in the middle? You have to be able to put the LCD back EXACTLY how you found it, so that the 'stream' can continue. But back to your issue...

Ok, you have the routine to turn on an LED for example. Now, just program the pin for an interrupt and have the vector go to a routine that does NOTHING but return from the interrupt. Nothing should happen, right? And you code shouldn't crash, right? Now just put a JSR MyRoutine in the code and it should work.

The trick is not to be overwhelmed by the fact that you're doing an interrupt. Separate the interrupt from what you want the interrupt to do first. Get the task working, and then just drop it into the ISR.

As to the interrupt itself, that is going to take some comfort level but it's also easy. Just make sure to read the book and know what you want the pin to do.

Mike
0 Kudos

429 Views
saravanan_TTL
Contributor I
Hi Mike,
 
Thanks for your help, Iam started learning about interrupts from books.But still iam unable to follow those things. They are very high for me. If you u explain me with some examples so that I can understand easily.
I will be thankful to you if you guide
1) how to program the pin for an interrupt 
2) how to see that have the vector go to a routine
3) how to put a ISR My routine in the code
 
sorry mike to drouble you,since Iam very much intersted in this field I have to learn some how about this field.
 
Regards,
Saravanan.A
0 Kudos

429 Views
mke_et
Contributor IV
Well, first thing you have to do is get your 'routine' working in a polled setup. Just have your program loop and test a condition. If the condition is valid, then execute your routine. A lot of this involves as a preliminary looking at the hardware and deciding what you want to do. If you are using a 'port pin' type setup, like one line of a port generating an interrupt, then you need to go put that into your code.

For example, test a pin. If in an 'idle' state, don't do anything. If in your 'interrupt' state, then do your special routine you wrote.

Once that's working, then look at the hardware reference and figure out the 'vector' for a pin interrupt for the pin. (You DID make sure you picked a pin that supports an interrupt, right?)

Ok, take the 'test' out of your main loop.

You have the address of your interrupt service routine in the vector table, right?

Now, in your 'init' code' you have to set up the port to enable the interrupt. This will usually involve multiple registers. For example, you may have to set the interrupt for 'high going' sensing. Or low going sensing. Then you have to turn the whole port on, and make sure it's 'masked' correctly. AND make sure interrupts are enabled!

In a lot of 'pin' type setups, you may want to also detect 'bounce' on the pin. But that depends on how you write your routine. If you use a mechanical switch, you could have thousands of interrupts.

Oh, one other thing... there's always the case you could miss it. What? Miss an interrupt? Well, consider that an interrupt is an event trigger, not a continuous state. For example, you have a port configured to use a pin for an active low interrupt. So you get the interrupt. But which pin was it? The interrupt may be saying something much more than a single pin interrupted. It might be indicating that 'some pin on port X generated an interrupt' but you don't know which one until you go in and figure it out. In a simple system, you may not care and just make a safe assumption that if you got the interrupt you got the pin. But what if you are using more than one pin? Get the interrupt, now what? Which pin? So you read the port. But with switchbounce you could be reading the bounce state, so from that point of view there isn't an interrupt!

It's not always so simple. But, just to get going you shouldn't have to worry about those kinds of issues.
0 Kudos

429 Views
saravanan_TTL
Contributor I
Hi,
 
Thanks for your help.I will follow the instruction given by you.If I face any problem ,I hope you will help me again.
 
Regards,
Saravanan.
0 Kudos

429 Views
bigmac
Specialist III
Hello Saravanan,
 
As Mike has already explained, using the keyboard interrupt with mechanical switches may not be a good place to begin, because of switch bounce complications.  I might suggest starting with the use of the timer, perhaps commencing with the timer overflow interrupt, which should be simpler.  I generally find that virtually every program uses timer interrupts, so effort here will not be wasted.
 
As an exercise, you could try controlling the flashing of a LED using the timer overflow interrupt, starting with equal on and off periods, and then allowing for different on and off periods.
 
Regards,
Mac
 
0 Kudos