Interrupt pin not working on Nucleo F303K8

Hello guys,
I am struggling with an apparently naive problem…
In short I need to decode the two-channels PPM signal (basically a 15ms period stram of three pulses) coming from an RC receiver to generate speed (PWM) and direction outputs.

I started writing down some dirty code to see if I was able to reach the target and I successfully obtained what I need on a Nucleo 411RE. So I decide to switch to a F303K8 to squeeze the circuit, that has to be housed in the RC car.

No way to get an interrupt! I tested D0 through D13 without success…
I verified the PWM output is correctly generated.
The LED, that on 411RE blinks when the PPM signal is applied, does nothing on F303K8…
What could be wrong?

#include "mbed.h"
#include "string.h"

#define TMIN    100 // tens of us
#define TGOMIN  140  
#define TIDLE   150
#define TGOMAX  160
#define TMAX    200

// Nucleo F303K8 board

//------------------------------------------------------------------------------

DigitalOut  LED   (D13);    // Status LED (signal OK)
PwmOut      PWMO  (D5);     // PWM output (speed)
DigitalOut  FWD   (D4);     // Forward direction (relais)
DigitalOut  TM    (D6);     // Test Mode (output)
InterruptIn PPM   (D7);     // PPM signal input

Ticker Sampler;
Serial  PC(USBTX, USBRX);        // Virtual COM via USB (PC connection)

//------------------------------------------------------------------------------

void Restart_Count(void);
void Stop_Count(void);
void Count(void);

//------------------------------------------------------------------------------
                       
uint8_t i;
uint16_t Counter, Ton, T1, T2;
bool    PSTART=0, PDET=0;
double PWMX;

//------------------------------------------------------------------------------

int main()
{    
 PC.baud(115200);        // set baud-rate of virtual COM port (PC connection)

 PPM.mode(PullUp);
 PWMO.period_ms(3);  
 PWMO.write(0.0);  
 
 LED = 1;        // initial LED flash         
 wait_ms(100);
 LED = 0; 
    
 Sampler.attach_us(&Count, 10); // counter ticker
      
 PPM.rise(&Restart_Count);   // enable interrupt on rising edge
 
 while(1)
 {  
          
     if((PDET==1)&&(Ton>500))
     {             
         PDET = 0;            

         PPM.rise(NULL);
         PPM.fall(NULL);
         
         while(PPM==0);
         Counter=0;
         
         while(PPM==1);
         T1 = Counter;

         while(PPM==0);
         Counter=0;
         TM=1;
         while(PPM==1);
         T2 = Counter;
         TM = 0;  
                   
         LED = 1;          
     }
     
     else
     {
         T1 = 0;
         T2 = 0;
         LED = 0;
     }

     if(T2!=0)
     {       
         PWMX = (double) (T2-TMIN)/(TMAX-TMIN);
         

         if(PWMX<0.0)
             PWMX = 0.0;
         if(PWMX>1)
             PWMX= 1.0;
                 
         PWMO.write(1.0 - PWMX);
         
         //PC.printf("P2= %d, PWM= %3.2f\n", T2, PWMX);
     }

         
 PPM.rise(&Restart_Count);
             
 }        
}


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

void Count(void)
{      
Counter++;
return;
}

//------------------------------------------------------------------------------

void Restart_Count(void)
{      

PPM.rise(NULL); 

PSTART = 1; // pulse start detected
Counter = 0; 
TM=1;
PPM.fall(&Stop_Count); 

return;
}

//------------------------------------------------------------------------------

void Stop_Count(void)
{      

PPM.fall(NULL); 
if(PSTART == 1)
{   
 Ton = Counter;
 PSTART = 0;
 PDET = 1;
 TM=0;
}

PPM.rise(&Restart_Count);

return;
}

Hi Walter,

For publishing a piece of code use correct formatting.

   ```
     // your code
   ```

Interrupts normally works on this board, I use it for read a rotary encoder, of course is is probably not so fast.

However I tested your code and it never reach the loop and stay stuck. It seems like the board is nonstop in ISR, probably it is slow for this. When you change the value 10us of your ticker (Sampler) to 15us the program easily reach the loop.

BR, Jan

Thank you Jan!

Got it about formatting, post fixed!

Hello Walter,

As Jan says, It seems that your method to decode PPM signal with Ticker works fine with faster MCUs, like a NUCLEO-F411RE, but it’s beyond the capabilities of a NUCLEO-F303K8. To verify, you can change the Ticker’s period, as suggested by Jan, or swap the following two lines:

...
    //Sampler.attach_us(&Count, 10); // counter ticker
    //PPM.rise(&Restart_Count);   // enable interrupt on rising edge

    PPM.rise(&Restart_Count);   // enable interrupt on rising edge
    Sampler.attach_us(&Count, 10); // counter ticker
...

NOTE: return; is not needed in void functions (unless you want to return before reaching the end of function).

As an alternative you can try to use Joseph Roberts’ PPM library. It does not seem to utilize a Ticker. The example program is available here. Good luck.

Zoltan