CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Floating input pin issue [solved]
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 4:01 am     Reply with quote

I liked the method.

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: 19195

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 5:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 6:25 am     Reply with quote

Tested it.
This method works very nice even with low debounce time.
Thank you for your help.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group