# Floating input pin with external pull-up

I would like to improve the performance of my push buttons, which sometimes don't respond when pressed. They have external pull-up resistors and have been initialised as floating input pins. Does not using the internal pull-up reduce performance?

Also, the code is using the internal HSI oscillator instead of external crystal. Could this also be affecting performance of the buttons?

The above image shows the circuit for the push button. The initialisation is:

GPIO_Init(PORT_SWF, But_Play, GPIO_Mode_In_FL_No_IT);

And here is the code for the button being pressed:

if (GPIO_ReadInputDataBit(PORT_SWF, But_Play) == 0)
{

delay_test(0xff); //decrements from 0xff to 0 for delay

if (Key_Button.Pn == 1)
{ Mode = P1_Run; USART_Send("P1->Play\r\n", 13); }
...
}


The code goes through all the possible buttons that can be pressed (14 in total).

The buttons are being polled every 200ms:

void TIM2_ISR(void)// interrupt every 200ms
{
}


Should this period be shorter? Timer 2 clock is at 8MHz

I should say the performance is usually really good, most of the time the response is as expected, but not always, so the problem isn't that the buttons are broken or have stopped working. I would like to make it always responsive, naturally.

Finally, we don't appear to have any problems with buttons coming on inadvertently. They require firm user action.

Thanks in advance for any help!

• If they have external pull-ups then they aren't floating. Are you employing any method of debouncing? Show your circuit and your code if you want better answers. – David Aug 24 at 20:34
• Hi David, I’ve updated my initial question with additional details on schematics / code. Are you able to provide any further insight? Thanks for your above reply. – Pi Squared Aug 25 at 17:31
• The only thing I can think with what you're describing is the polling rate of the 14 switches like you mentioned. I think you're going to have to experiment with the rate but I would increase the polling rate and see if that improves things or makes it worse then adjust from there. If you have an oscilloscope I'd look at what the input to the micro-controller looks like when you press the button. I'd expect your solution will be some kind of balance between the value of your debouncing capacitor and your polling rate. – David Aug 25 at 18:15
• Many thanks for your answers. Its good that everyone here has ruled out two of the potential causes. We can play around with polling and may be the capacitor to see if there is an improvement. – Pi Squared Aug 25 at 19:44

No, to both questions.

Omitting the internal pull-up does not reduce performance of reading buttons, unless the external resistors are completely unsuitable in value.

Using the internal oscillator also does not affect the performance of reading buttons.

• Thanks for the clear answers! What about how fast button presses are polled? The code does this every 200ms, I’ve seen other examples on this site where button presses are polled at shorter time intervals. The timer clock is 8MHz so can reduce the 200ms figure. – Pi Squared Aug 25 at 17:39

What I have experienced with push buttons is that sometimes the microcontroller does not detect a high or a low logic when the button is pressed because the mechanical contacts of the button is worn out especially when the button has been in use a lot.

Another reason for this could be that your microcontroller is not detecting the logic change on its input pin. I suggest you connect a digital multimeter to the button and see what logic levels you get when you press and release the button. This would eliminate any mechanical issues with the button. Mechanical issues with buttons are not common but they do exist.

• I agree with testing for a mechanical issue. If it's one of those small, board mounted, buttons with the four legs and the rubber button, I've defiantly had those fail mechanically. – David Aug 25 at 1:06
• @David, yes you are right. Although I have not worked with tactile switches in a while, I do know that these switches sometimes fail after a few pushes of the button even though their datasheet claims to have 10,000 press/release cycles or some big number like that. I rather use SPST switches that are again mechanical but soft to press that last for a long time. – David Norman Aug 25 at 1:29
• Yes the push button has four legs, but they do work well most of the time. Definitely not broken as wouldn’t work at all. Occasionally there is no response but then it works when pressed again. – Pi Squared Aug 25 at 18:04