[SOLVED] Push button

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
I am curious to know how do you develop best system. I would like to follow your technique @KeithWalker @MrChips

Assume we have everything to develop embedded system, one push button , Microcontrller and LCD display. We want our system to display "System ON" on screen When button Pressed.

Okay!! I have complete requirements and I need to design embedded software system for it.

I stop here because I don't know What is shortest and longest time the button will be pressed?

While thinking How should think to resolve problem occurs in planning

I do appreciate any help
 
Last edited:

Ya’akov

Joined Jan 27, 2019
9,070
The trouble with your scenario is that it's not real. You need to have a problem to solve in order to write a good specification and plan a solution.

There is nothing to fall back on when questions are asked because you will just have to make things up in a disconnected way that has no corresponding feature in something real.

Choose a real problem to solve, present the problem, present the constraints (i.e.: budget, MCU platform, programming language, etc.) and then you will be able to follow the process.

This process always starts with a problem to be solved, it is a technical solution.
 

BobTPH

Joined Jun 5, 2013
8,813
Your “specification” leaves a bit to be desired.

What is displayed when the button is not pressed?

What does “when the button is pressed” mean? Does it mean only while the button is down, or does it mean for all time after the button is pressed for the first time, or something else?

Can you imagine the questions I might have is this was for a real system that actually does something?

Bob
 

BobTPH

Joined Jun 5, 2013
8,813
If that was my homework problem, I would be tempted to write it such that it ignored the button and just displays the message. If the prof said it was wrong, I would demonstrate it by pressing the button snd asking him/her what it displayed.

Bob
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
Choose a real problem to solve, present the problem, present the constraints (i.e.: budget, MCU platform, programming language, etc.) and then you will be able to follow the process.
@Yaakov Why do you think this is not real problem?

Any PIC, PIC16F877A
Push Button
LCD 16*2
C programming

What is displayed when the button is not pressed?
@BobTPH Nothing, Only display would be on

What does “when the button is pressed” mean? Does it mean only while the button is down, or does it mean for all time after the button is pressed for the first time, or something else?
When button is pressed one time, take the action just like in a mobile keypad, TV remote, Calculator

Homework, most probably.
Not a homework. I don't need code. It's all about how to design system when we have list of requirements
 

Ya’akov

Joined Jan 27, 2019
9,070
@Yaakov Why do you think this is not real problem?

Any PIC, PIC16F877A
Push Button
LCD 16*2
C programming
Because what you just specified is a solution to something, not a problem. You have turned your solution into a problem and you want to know how to solve it.

Because the solution is the problem you will not be able to answer questions about the problem which you haven't already thought of and so you will just toss things in as you are asked. That means you won't learn how to solve the problem, so the exercise is meaningless.
 

MrChips

Joined Oct 2, 2009
30,712
Slapping a bunch of hardware and software components together does not a real problem make.

Take a simple single push-button. Press the button and something happens, simple enough. Not so fast!
Think through the design specifications more carefully and precisely.

1. Does the action start when the button is first pressed or when the button is released?
2. What happens if the button is pressed and held down continuously?
3. Does the action stop when the button is released?
4. What happens if the action is already active and the button is pressed?
5. Is there a different action if the button is pressed and released within 1/10 second or held longer, for example 3 seconds.
6. What happens when the button is pressed and released in quick succession twice?
7. What happens when the button is pressed and released in quick succession multiple times, for example 3 times?
8. If the button is pressed in error is there a way to cancel the operation?
9. What happens if the button is pressed while the power is turned off and on again?
10. What indicators are visible to show that the action has been activated or is currently active?

I have a power pack that looks like this:
1620308639624.png
It has one push-button. A bunch of different things happen depending on its current state and how you press the button.
 

BobaMosfet

Joined Jul 1, 2009
2,110
I am curious to know how do you develop best system. I would like to follow your technique @KeithWalker @MrChips

Assume we have everything to develop embedded system, one push button , Microcontrller and LCD display. We want our system to display "System ON" on screen When button Pressed.

Okay!! I have complete requirements and I need to design embedded software system for it.

I stop here because I don't know What is shortest and longest time the button will be pressed?

While thinking How should think to resolve problem occurs in planning

I do appreciate any help
@Pushkar1 - You don't start with the hardware, whenever dealing with human interaction. You start with the human- this is a field called 'heuristics'. If you know heuristics, you know how quickly a person and push a button, max, and you also know about feedback issues and so forth- like outputting a clicking sound when a button is pushed. Sometimes, people need that extra tactile/sensory feedback or things seem 'unresponsive'.

After you understand the heuristics, which define your human constraints, then you identify the constraints around the purpose of the applications. Once that's done, you figure out a method likely to solve it, and then begin choosing hardware to fit that solution. Software can then be written.

'Best System'- That is a good way to get 'average' because 'best system' is always determined by committee.
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
Thank you all of you for giving best suggestion

@MrChips you have answered my question. I'm releasing I asked questions incorrectly. But you addressed it correctly.

I think the points you have shown are the specifications, not the requirements.
 

MrChips

Joined Oct 2, 2009
30,712
Thank you all of you for giving best suggestion

@MrChips you have answered my question. I'm releasing I asked questions incorrectly. But you addressed it correctly.

I think the points you have shown are the specifications, not the requirements.
What is the difference between a specification and a requirement?
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
What is the difference between a specification and a requirement?
I don't see much difference between two. I think requirements is single statement of something system must do. Specifications may have many requirements

Let's leave it for now it's not so important. I'm focusing on the 10 points you shown. Right now there are many questions in my head. I'm reading about push Button to collect more information.
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
@MrChips I have been reading push button for long time on internet. My conclusion when button pressed or released, Microcontrller sense many high or low signal at input pins because of switch bouncing.

When button pressed or released We need to wait for some time to get stable input signal that is switch denounce time.

But I am confused I look in many places they don't wait for switch denounce. They only check button is pressed if yes then turn on the led.
Where denounce needs and where doesn't need in system?
 

peterdeco

Joined Oct 8, 2019
484
I write my programs in basic. I simply write:

IF PORTA.1 = 1 THEN HIGH PORTB.1 (to light up an LED)

or to light LED upon release:

START:

IF PORTA.1 = 0 THEN START (stay here until button pushed)

WAITFORRELEASE:

IF PORTA.1 = 1 THEN WAITFORRELEASE (stay here until porta.1 is no longer high)

HIGH PORTB.1
 

BobTPH

Joined Jun 5, 2013
8,813
In your scenario— where the first press of the button switches states and subsequent presses are ignored— you do not need debouncing.

You need debouncing when each press has an effect, for example, if you increment a counter.

Bob
 

peterdeco

Joined Oct 8, 2019
484
START:

IF PORTA.1 = 0 THEN START (stay until button pushed)

HIGH PORTB.1 (turn on LED)

PAUSE 50 (debounce)

WAITHERE1:

IF PORTA.1 = 1 THEN WAITHERE1 (stay until button released)

WAITHERE2:

IF PORTA.1 = 0 THEN WAITHERE2 (stay until button pushed again)

LOW PORTB.1 (pushed again turn off LED)

PAUSE 50

WAITHERE3:

IF PORTA.1 = 1 THEN WAITHERE3 (stay until button released)

GOTO START
 

BobTPH

Joined Jun 5, 2013
8,813
Not a homework. I don't need code. It's all about how to design system when we have list of requirements
And you have failed once again. You never said before that a second press of the button had any effect, and yet your code does that.

Bob
 

MrChips

Joined Oct 2, 2009
30,712
@MrChips I have been reading push button for long time on internet. My conclusion when button pressed or released, Microcontrller sense many high or low signal at input pins because of switch bouncing.

When button pressed or released We need to wait for some time to get stable input signal that is switch denounce time.

But I am confused I look in many places they don't wait for switch denounce. They only check button is pressed if yes then turn on the led.
Where denounce needs and where doesn't need in system?
Stop reading and think through your problem. You don't need the internet to solve problems like this one.

Here is one such solution:

OUT = BUTTON;

No switch debounce required.

Give examples of situations where this will work.
Give examples of situations where this will not work.
 

Papabravo

Joined Feb 24, 2006
21,159
As is often the case, when your requirements lack clarity, it is hard to define what done means. This is not so bad when you are first learning things on your own dime. It is fatal when money and your reputation are on the line. The switch bounce problem has been around for over half a century and there still is no standard one size fits all solution. Most practitioners fiddle with one algorithm or another until they get something that "seems to work" and they move on. Most of the time this approach is good enough. Occasionally it is not. One thing we have nowadays that we didn't have 50 years ago is simulators that can model a bouncing switch so we can study the effects of different design choices.

As Mr. Chips has pointed out, sometimes there is no problem with detecting multiple sequential switch closures without a release.
 

Thread Starter

Pushkar1

Joined Apr 5, 2021
416
Here is one such solution:

OUT = BUTTON;

No switch debounce required.

Give examples of situations where this will work.
Give examples of situations where this will not work.
If the response time of controlling device is more than the switch device. In this situation no debnounce needs.

Example- No debnounce needed
LED = BUTTON
Turn ON / OFF LED for 2 Seconds When button is pressed.

In this situation, no debounce needed because ON/OFF time of LED is greater. If switch bounce it will not affect on the LED flashing.

Example - Debnounce needed
Counter = Button

If I want to count how many times button has been pressed, then certinaly need to deal with switch buttons
 
Top