InterruptIn & PwmOut conflict

18 Apr 2019

Serious bug, or maybe I'm missing something? I'm using a Nucleo-f303k8 and haven't tested this on other boards.

Problem - when using high frequency pwm some input interrupts are triggered multiple times by a single rise or fall.

I was having trouble with a rising edge InterruptIn on PA_12. Every time it was triggered with a switch (filtering included) it would trigger exactly twice on when pressed, and once on release.

Spent time fiddling with different resistor and filter caps, but this persisted. The results were exactly the same every time, so a switch bounce issues was doubtful. The same problem happened when changing the interrupt to falling edge.

I moved the interrupt to PA_0 and it worked as expected. I moved the interrupt back to PA_12 and commented out sections of my code.

I was using the fastpwm library with a period of 16uS and once this was removed the PA_12 interrupt worked as expected. Tried the native mbed PwmOut and had the same problem. Then I lowered the pwm period to 1 second and the interrupts worked correctly.

Interrupts triple trigger on the following pins: PA_7 PA_10 PA_12 PF_0 PF_1 PB_5 PB_4

Interrupts single triggler (correctly) on the following pins: PA_0 PA_1 PA_3 PA_4 PA_5 PA_6 PB_7 PB_6

All other pins couldn't be tested because of other connections.

stripped code down to nothing and the problem persists.

#include "mbed.h"
PwmOut my_pwm (PA_8);
InterruptIn tap_switch(PB_4);
uint8_t tap_stage = 0;

void tap_event()
{
    tap_stage= tap_stage + 1;
    printf("tap stage: %u \n ",tap_stage);
}

int main()
{
    my_pwm.period_us (16);
    my_pwm.write (.50);
    tap_switch.rise(&tap_event);        

    while(1) {
    }
}