Doubt

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

Doubt

1,488 Views
admin
Specialist II

Hi,

I am working on Code warrior Development Studio version 5.0 for MC9S12XDP512 MCU on SK-S12XDP512A demo kit. I want to check the status of the pushbutton on led connected to the PortB Pins. Can the pushbutton be given as an interrupt? If so, what interrupt type would it be? a Hardware Trigger? a Real time Interrupt? or what? 

Labels (1)
Tags (1)
0 Kudos
7 Replies

544 Views
Lundin
Senior Contributor IV

All pushbuttons have something called "contact bounce". When you press down a button, the mechanical parts bounce up and down and generate an electrical disturbance for a short time. Connect an oscilloscope to any button and check, you will see a short sine wave when it is pressed.

Another issue is electro-magnetical interference (EMI), "glitches" that are caused by noisy electronics. Such glitches can be removed through hardware with decoupling capacitors etc, but a serious embedded software designer will still have glitches in mind when writing the program.

Because of the two issues above, you must "debounce" a button whenever you read its status. 

This is typically done this way:

1) Set an interrupt on the port where the button is connected, or alternatively read ("poll") the port from the main program.
2) When the port goes active, you have either found a user pressing the button, or a contact bounce from a previous button press, or an EMI glitch. You don't know which.

3) Start a timer. 5ms is a good timer value. During this time, ignore the button port.
3) When the timer has elapsed, read the port again. 
4) Make sure that the values are the same during the 1st and the 2nd read. If they aren't, disregard the whole keypress - it was likely caused by EMI.
5) If the values were the same, light the LED etc.


0 Kudos

544 Views
admin
Specialist II

hello, thank you so much. that was very informative... i will try it.thank u agn

0 Kudos

544 Views
CrasyCat
Specialist III

Hello

 

You cannot generate an interrupt clicking on a push button in the visualization tool window.

 

CrasyCat

0 Kudos

544 Views
admin
Specialist II
hello, thank you.
0 Kudos

544 Views
admin
Specialist II

But can we make it work on a Demo Kit? The input will be the push button the status of which can be seen on an led...

SK-S12XDP512A is the demo kit I am using.

0 Kudos

544 Views
vivek31be
Contributor I
Hi, checkout the processor expert help "Tutorial for Freescale HCS12 Project 2 Step 4" . I think it will solve your problem. It has given how to generate interrupt on button, since you are using a hardware demo kit it should work. Thanks, Vivek
0 Kudos

544 Views
admin
Specialist II

Hello Vivek,

 I have just tried it the way u suggested, but I am advised not to use the processor Expert as the code is generated within.... As a newbie this will not help me understand the programming of my microcontroller..

If u have any other idea of doing it.. just let me know..

0 Kudos