Question about button design

Status
Not open for further replies.

silverwolfman

Junior Member level 1
Joined
Feb 22, 2013
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,408
Hello everyone,

Just a simple question about button design, Do we always need pull up resistor based on the dsPIC33FJ chips? Can I just use the output port to set the pin value to 1 and then read back the value and see if the button is pushed?(I tried this in code, but looks it doesn't work:sad: or maybe I didn't do it the right way)

Thanks.
 

You get no answer?

Maybe because you forgot to give us informations like schematic, and the results of your test.
What did you expect? and what did you get?


Klaus
 

Hi KlausST,

Thank you so much for the reminder, guess I didn't ask the right question, I have already make the button work with pull up resistor, and what I am trying to do now is to implement the button push function without pull up resistor , with dsPIC33FJ chip, how should I do to set the pin level always stays at '1' in order to detect the button is pushed?

Thanks again.
 

Attachments

  • 2.jpg
    183.8 KB · Views: 79

Hi,

i don´t know the dsPIC33FJ, but often modern controllers have built in pullup resistors.
This function often must be enabled by setup. Please read datasheet about port pin functions.

Your top picture shows the external hardware, like you use it with internal pullup.

*****
Usually the controllers have high output drive capability. Therfore using a pin as output may cause overload in port drivers.
Some can handle short circuit currents for a short time. But be sure that this is specified in the datasheet.
Others may be damaged immediately when you press a key,
and again others may overheat within several minutes.

I think it is not a good idea to setup the port as output insteqad of an external pullup.
But the datasheet will tell you.

********

The lower picture is a usual circuit if the controller has no internal pullup function.

****

You tried and said it didn´t work with setup as output. I don´t know how you triedthis and how you recognized that it does not work...

****
I can imagine a "non reliable" solution (not for industry, no high quality product..)... but I don´t reccomend this:

every time you read the button (and this shoud be timed about every 20 -50 ms)
* set the port to output HIGH
* wait one us
* set the output to HIGH Z, and immediately after that
* read the port input

How it works:
For a short time switch the port to output, if now the button is not pressed one will see VCC at the port pin, if the button is pressed the voltage will be low.
Now switch to HIGH Z. The capacitance of the traces, pin, button... will keep voltage some 10 us. so you can read in the buton value.
With the short pulses of less than 2 us every 20 ms you have good chance not to kill the output.

Also supply current is relatively low with this solution. Heating should not occur.

****

But again, i don´t reccomend this, because this is a very dirty solution.

Klaus
 
If you add the 1k resistors in series between the input/output and the button, you will have a safe solution, even with the solution KlausST described. It should still pull down fast enough to be read after pulled up by the output set to high. This may also be used if you for some reason need to use the pushbutton inputs as outputs for something else. If you run out of i/o pins, for example.

It is still hairy, but safe related to the output hanging high against a closed button, for some reason. If you use interrupts you may have an extended output period, if you don't turn off the interrupt while you do the output pullup.
 
Hi,

Thank you so much for the reply! the button push function works when delay is added in between the output and the read back. I think you are right, it is not a stable solution.

Thank you guys again for the detail reply.

Best Regards
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…