Pages

Saturday, 12 October 2013

Hardware Interrupts it is!!!!!! ;)

interrrupt_logoIn this project we'll be dealing with the hardware interrupt functionality of msp430. An interrupt is a specific signal that the processor identifies. Interrupt triggering can be either rising edge or falling edge or level triggered. falling-edgerising-edge
So whenever an interrupt of desired from occurs, it triggers the processor. Just a brief idea about Interrupts. Whenever an interrupt occurs the processor completes the task at hand, then context saving takes place and then context switching. Context saving is nothing but the processor stores the current content of the program counter to the stack. Stack is like a scratch pad where you write data whenever you require. Only difference is that this stack cleans up once you pop the data or take the data back. The vector address (which is nothing but an address that is a hex number) is loaded into the program counter. Each interrupt has a unique vector address for interrupt subroutine(ISR). Now this ISR is executed and once it executes the return instruction(has to be written by programmer in ISR) it goes back into the main program. This is done by taking back the address of the program counter that was stored onto the stack.
Now we'll talk about msp430 and hardware interrupts. In msp430 you can configure each and every pin of all ports as interrupt enabled. So one can have various interrupts and various parts in ISR based on that. For port 0 there is one vector address and for port 1 and so on. So irrespective of which pin the interrupt occurs the control will go to the same ISR. In order to distinguish which port pin has triggered the processor there is a flag register in msp430 called PxIFG which is port x interrupt flag. Each bit corresponds to a the port pin of that register. So whenever there is an interrupt the m pin of port x then the mth bit of PxIFG goes high. We have to clear that bit ourselves, compiler won't do that for us.
Now coming back to the project, in this project we'll write the led pattern code in the main program so that there are some patterns in normal state. We'll be using 6 push buttons to give interrupts. And we have programmed the controller in such a way that led corresponding to the port pin that gives interrupt will glow. So if P2.3 gives the interrupt I've programmed this such that P1.3 led will glow(same port pin number just for tracking purpose.)
Note you can easily vary this program to write a code to display the pin number on a 7- segment display. All you need is a BCD to seven segment decoder and a seven segment display. I got this idea after returning home when I had purchased the push buttons. I really didn't want to go to the shop so I stuck to this led concept.
Hope you gained some knowledge about the wonderful world of interrupts. This is a really important part of any controller and how a programmer writes code for this is also important. Thank you for reading this blog. Please do come again for some new concepts or entries.
P.S: For a couple of weeks I'll be using grace for initializing all peripherals. Later I'll be covering assembly language.
111020131216
The above circuit diagram shows the connections.
Tutorial:
[youtube=http://www.youtube.com/watch?v=XBJZdlFqOoE&w=640&h=360]
Project :
[youtube=http://www.youtube.com/watch?v=o1PNTw96Wsc&w=640&h=360]

No comments:

Post a Comment