But there is a problem, when the pin is low and button pressed, there is 10mA extra current consumption.
I making the pin low all the time looks a bit problematic in that case.
What if I put the pins as inputs all the time, but discharge them on every 10ms time (output->low->input) before reading the input, then make the pin input again?
One step further is to discharge the pin when button is not pressed only. So no any extra current drown.
Can this method help too?
Thanks
Ttelmah
Joined: 11 Mar 2010 Posts: 19659
Posted: Mon Jan 10, 2022 5:06 am
Problem then is that the floating pin will be prone to EMI. Pins should never
really be left floating. The solution that avoids the extra current, is:
Code:
//Set the pins high and drive them at boot:
output_drive(PIN_B5); //This sets TRIS to 0 on the pin
output_high(PIN_B5); //pin is now driven high
//then when you want to test the pin:
output_low(PIN_B5); //set the pin low
delay_us(1); //allow time to pull low
output_float(PIN_B5); //pin is now set as an input
delay_us(1); //wait 1uSec
state=input_state(PIN_B5); //read the pin level
output_drive(PIN_B5); //set the pin back to being driven
output_high(PIN_B5); //and drive high
FFT
Joined: 07 Jul 2010 Posts: 92
Posted: Mon Jan 10, 2022 6:25 am
Tested it.
This method works very nice even with low debounce time.
Thank you for your help.
All times are GMT - 6 Hours Goto page Previous1, 2
Page 2 of 2
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum