Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Toggling LED with a pushbutton using interrupt

Status
Not open for further replies.
Hi,

You don´t say where you see a problem...

And maybe this is because there is no clear definition of operation.
Use a paper and a pencil and do some drawings - we professionals need to do this, too.

* Schematic
* some kind of timing diagram where we see initial states, the key press signals and the LED signals..

Klaus
 

H
* some kind of timing diagram where we see initial states, the key press signals and the LED signals..
Klaus
when key is pressed, we just wait for debouncing and then again check key press

We can set timer interttupt i don't understand how the interttupt is use for debouncing time

IMG_20200926_191040.jpg
 
Last edited:

Hi,

Do you want me to guess what the problem is...
Do you want me to guess what´s your timing for debouncing, toggling, timer...

... which microcontroller, which language, which compiler, which port pins..

really?

Klaus
 

somewhere in the code there is a timer that starts when the button is pushed
it then counts down a few milliseconds (50?)

when the count gets to zero, the bouncing of switch should be finished,
and the interrupt is executed

you really need to get the manual for the processor and start learning the assembler
 

Hi,

Do you want me to guess what the problem is...
Do you want me to guess what´s your timing for debouncing, toggling, timer...

... which microcontroller, which language, which compiler, which port pins..

really?

Klaus
Problem is I don't understand how to use timer interrupt for the switch debouncing ,

I understand simple we check button if key is pressed, wait for 40ms, again check button if key is pressed toggle LED

Pic16F877A, c programming, MPLAB XC8,
RB0 for LED
RD0 for button
 

First decision is do you want key to be just bounced in or in and out before you
act on the key press. That controls of course the program logic flow.

Generally speaking if you generate an interrupt on a pin edge or level, then start
a timer and set a flag. Set timer up to generate an interrupt when it is done, or poll it.
When timer finishes and you check that flag is set, and switch pin is still pressed, then
either perform the function needed or bounce it out/pin release and then perform function.

Best way is draw a flow diagram for your code, makes it easy to see and find where you have
not done everything necessary.

Many people use 50 mS or there abouts for bounce time, I have had switches bounce for
several hundred mS. That is your timer period. Note when you get first isr off pin you reset
and start the timer.


Regards, Dana.,
 
Last edited:

Hi,

if you want to write code - it doesn´t care whether you are experienced or not - you need to have clear requirements. .. an idea how you want it to work.

Your requirements don´t depend on microcontroller or timer...
In your case it´s just a button and a LED...
You need to exactly desribe how the LED should work with repsect to button press .. and maybe your timing requirements.
A timing diagram could do. It is simple, just two lines. One for the button one for the LED to start with.
Then you may add some lines and text for timing and other information. Everyone in the world will understand - independent of language.
If you are not able to show what you want - nobody can help you ....

****
Function:
There are many ways for doing what you want.
You may do an internet search to find (maybe millions) examples, descriptions, code, schematics, timing diagrams...
Read through some of them .. then decide your own way to go.
There will be no 100% wrong, there will be no 100% right. Ask 10 engineers and get 10 different opinions.
Thus "your" way...not our or anyone else´s way

****

Klaus
 

Some ref material on bounce handling, attached.


Regards, Dana.
 

Attachments

  • Debounce.zip
    6.8 MB · Views: 132

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top