Overactive interrupt triggering using internal pullups

Post here first, or if you can't find a relevant section!
fredbox
Posts: 95
Joined: Tue Jul 07, 2015 4:44 pm

Re: Overactive interrupt triggering using internal pullups

Post by fredbox » Sat Dec 24, 2016 4:23 am

RogerClark wrote:
Basically, I'm doing the same as Nick Gammon describes here

http://www.gammon.com.au/forum/?id=11130

Image
That post on gammon.com.au was updated today with new code that uses pin change interrupts for four encoders.

roffey
Posts: 10
Joined: Tue Sep 27, 2016 8:02 am

Re: Overactive interrupt triggering using internal pullups

Post by roffey » Sat Dec 24, 2016 8:40 am

That looks interesting, and a useful reference.... Single int using change .... should be far more robust.... thanks for putting that up.
I do note however, that you are using 0.1uF electrolytics in your circuit. I would want to swap those out for some decent ceramics, and ground any metal areas on the encoder if they are isolated. Just my preference though :)

User avatar
mrburnette
Posts: 1803
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by mrburnette » Sat Dec 24, 2016 5:06 pm

roffey wrote:That looks interesting, and a useful reference.... Single int using change .... should be far more robust.... thanks for putting that up.
I do note however, that you are using 0.1uF electrolytics in your circuit. I would want to swap those out for some decent ceramics, and ground any metal areas on the encoder if they are isolated. Just my preference though :)
I have not run the time coefficients on this but for the sake of talking, let's say that 0.1uF is the correct value ... then they should be specified as Tantalum.

Ray

octavio
Posts: 42
Joined: Sat Apr 15, 2017 6:41 pm
Location: barcelona
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by octavio » Sun Sep 17, 2017 8:25 pm

The code below counts when button is pressed,the button is connected to a pin with a 10uf capacitor in parallel to filter posible noise,only the internal pullup is used,and it works ok if i press the button betwen calls to " Serial.println(f1);" but if i reduce the delay to 100ms then it counts about 20 times for every button press.As a work around i'm going to directly read the port status and add a digital filter,but this seems to be a important bug in the arduino libraries or the stm mcu.The test was done with a usb to serial adapter.


Code: Select all

//stm32f103cb 20k ram 128k flash

#define B_nextfile PA4

void setup()
{
afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY); // release PB3 and PB5
afio_remap(AFIO_REMAP_SPI1); // remap SPI1 
gpio_set_mode(GPIOB, 3, GPIO_AF_OUTPUT_PP);
gpio_set_mode(GPIOB, 4, GPIO_INPUT_FLOATING);
gpio_set_mode(GPIOB, 5, GPIO_AF_OUTPUT_PP);

  
 Serial.begin(250000);delay(1000);  
 Serial.println("serial ok");
 pinMode(B_nextfile,INPUT_PULLUP) ;
 attachInterrupt(B_nextfile,isr_next,FALLING);
 
}
int f1;
void loop()
{
  Serial.println(f1);
  delay(10000);
 }


 void isr_next(void)
 {
  ++f1;
 }

User avatar
RogerClark
Posts: 6911
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by RogerClark » Sun Sep 17, 2017 10:33 pm

Internal pullups are virtually useless for buttons etc.

The spec says their values can range from 30k to 50k

Use a suitable value external pullup

octavio
Posts: 42
Joined: Sat Apr 15, 2017 6:41 pm
Location: barcelona
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by octavio » Sun Sep 17, 2017 11:33 pm

The pullups values are similar to those found in other microcontrollers (atmega,xmega) and they work without problem in those microcontrollers,with or without filters if the wires are not too large.And 50k seems a suitable value,sometimes i have used 1M external resistors to reduce current consumption and still works.

User avatar
RogerClark
Posts: 6911
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by RogerClark » Mon Sep 18, 2017 12:10 am

octavio wrote:
Sun Sep 17, 2017 11:33 pm
The pullups values are similar to those found in other microcontrollers (atmega,xmega) and they work without problem in those microcontrollers,with or without filters if the wires are not too large.And 50k seems a suitable value,sometimes i have used 1M external resistors to reduce current consumption and still works.
This is irrelevant. They are not a STM processor.

octavio
Posts: 42
Joined: Sat Apr 15, 2017 6:41 pm
Location: barcelona
Contact:

Re: Overactive interrupt triggering using internal pullups

Post by octavio » Mon Sep 18, 2017 6:22 pm

I have disabled the internall pullup and conected a 4k external pullup,problem continues.

stevestrong
Posts: 1609
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Overactive interrupt triggering using internal pullups

Post by stevestrong » Mon Sep 18, 2017 6:36 pm

First, you should define all variables used in ISRs as "volatile".
Second, it does not seem to be a bug for me, it is rather the MCU which runs couple of times faster than the AVR processors.
Third, you should put a resistor (100 Ohm) in series with the capacitor to the button in order to reduce the currents produced by shorting the capacitor when you press the button. Otherwise it can generate noise spikes which can erroneously trigger interrupts.

User avatar
Pito
Posts: 1529
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Overactive interrupt triggering using internal pullups

Post by Pito » Mon Sep 18, 2017 6:38 pm

Your f1 must be volatile..

Code: Select all

volatile int f1;
Steve was faster :)
Btw, I am running here (BPill) 3 attached interrupts at 3 pins, the first fires 1300x per second, the second about 550x, the third about 4-10x per second (all at random times). I am not loosing a single one (so far). In parallel Serial.print(), math, HardWire I2C, bitbanged SPI into Xilinx.
Doing in ISR exactly what you do - incrementing a volatile uint32_t.
Pukao Hats Cleaning Services Ltd.

Post Reply