chipKIT® Development Platform

Inspired by Arduino™

Fubarino Mini interrupt

Created Sat, 26 Jul 2014 22:09:24 +0000 by C-3PO


C-3PO

Sat, 26 Jul 2014 22:09:24 +0000

Hello,

I wanted to trigger an interrupt to the PIN 12. Unfortunately this didn't work. My sketch is as follows:

#define pinInt 12  

void intHandle();

void setup() 
{
  digitalWrite(PIN_LED1, LOW);
  pinMode(PIN_LED1, OUTPUT);
  pinMode(pinInt, INPUT);
  
  Serial.begin(115200); 
  
  attachInterrupt(2, intHandle, RISING);
}

void loop() 
{
  //Debug...
   Serial.println("-> Start...");
   delay(500); 
   Serial.println("-> Loop...");
   delay(500);
   
}

void intHandle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
  Serial.println("Interrupt...");

}

void init_pps()
{
  delay(5000); // Debug
  Serial.println("initialisieren INT1"); //Debug
  
  if (mapPps(pinInt, PPS_IN_INT2))
  {
    Serial.println("success mapping INT2 to 12");
  } 
  else
  {
    Serial.println("failure mapping INT2 to 12");
  }

}

In the ahead thanks for the help


majenko

Sat, 26 Jul 2014 23:53:32 +0000

In what way does it not work? Does the mapPps fail? Does the interrupt fail to trigger?

What is your external circuit?


C-3PO

Sun, 27 Jul 2014 10:52:31 +0000

When I release the interrupt the sketch jumps not in the subroutine "intHandle()". The PPS is set correctly. The external circuit work correct. The electrical circuit is a 10kOhm resistor to 3.3V and a 1kOhm resistor to the Pin12. The push button switches the 1kOhm resistor to GND (-3.3V).) The PIN 12 is a rectangular pulse to the rhythm of the touching (3.3V -> GND; GND -> 3.3V)


EmbeddedMan

Sun, 27 Jul 2014 12:50:09 +0000

C-3PO-

I have confirmed your failure. It does the same for me.

However, if I use INT1 and pin 3, it works. See code below.

I'll work on figuring out why INT2 doesn't seem to be working right.

*Brian

#define pinInt 3  

void intHandle();
void init_pps();

void setup() 
{
  digitalWrite(PIN_LED1, LOW);
  pinMode(PIN_LED1, OUTPUT);
  pinMode(pinInt, INPUT);
  
  Serial.begin(115200); 
  init_pps();
  delay(5000);
  
  attachInterrupt(1, intHandle, FALLING);
}

void loop() 
{
  //Debug...
   Serial.println("-> Start...");
   delay(500); 
   Serial.println("-> Loop...");
   delay(500);
   
}

void intHandle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
  Serial.println("Interrupt...");

}

void init_pps()
{
  delay(5000); // Debug
  Serial.println("initialisieren INT1"); //Debug
  
  if (mapPps(pinInt, PPS_IN_INT1))
  {
    Serial.println("success mapping INT2 to 12");
  } 
  else
  {
    Serial.println("failure mapping INT2 to 12");
  }

}

C-3PO

Sun, 27 Jul 2014 13:27:40 +0000

Hello Brian,

Thank you for the help your skecht running.

*C-3POhttp


EmbeddedMan

Sun, 27 Jul 2014 15:23:03 +0000

C-3PO-

OK, here's a new sketch. Its shows every one of the 5 interrupts working properly. And I've even remapped INT2 to pin 12, and it still works.

I'm now working on identifying the difference between your sketch above and mine below that's causing yours to fail.

*Brian

// Move a wire from pin 11 to each of the hardware interrupt pins to show that
// they print out the proper message.
#define pinSrc 11 // used as external interrupt stimulator

// On Fubarino Mini, INT0 is hard wired to pin 24.
// INT1 starts out on pin 3
// INT2 starts out on pin 0
// INT3 starts out on pin 6
// INT4 starts out on pin 4

void int0Handle();
void int1Handle();
void int2Handle();
void int3Handle();
void int4Handle();

int x;

void setup() 
{
  
  Serial.begin(9600);               // Turn on USB serial
  digitalWrite(PIN_LED1, LOW);      // Start of with LED off
  pinMode(PIN_LED1, OUTPUT);        // Make LED pin an output
  pinMode(PIN_INT0, INPUT);         // Interrupt pin must be an input
  pinMode(PIN_INT1, INPUT);         // Interrupt pin must be an input
  pinMode(PIN_INT2, INPUT);         // Interrupt pin must be an input
  pinMode(PIN_INT3, INPUT);         // Interrupt pin must be an input
  pinMode(PIN_INT4, INPUT);         // Interrupt pin must be an input
  digitalWrite(pinSrc, LOW);        // Simulator pin must start low
  pinMode(pinSrc, OUTPUT);          // And stim pin must be output too
  // Note: Both RISING and FALLING work for the attachInterrupt() calls, but
  // PIC32 does not have a CHANGE, or  HIGH like some Arduinos do.
  attachInterrupt(0, int0Handle, FALLING); // Register interrupt function on Int0
  attachInterrupt(1, int1Handle, FALLING); // Register interrupt function on Int1
  attachInterrupt(2, int2Handle, FALLING); // Register interrupt function on Int2
  attachInterrupt(3, int3Handle, FALLING); // Register interrupt function on Int3
  attachInterrupt(4, int4Handle, FALLING); // Register interrupt function on Int4
  
  // Optional, remap the interrupt pins to show that it can work
  mapPps(12, PPS_IN_INT2);
}

void loop() 
{
   digitalWrite(pinSrc, HIGH);       // Set stim pin high (triggers interrupt)
   delay(1000);                      // wait half a second
   Serial.println("Main loop tick");
   digitalWrite(pinSrc, LOW);        // Set stim pin low
   delay(1000);                      // wait another half second
}

// This function gets called when an external interrupt occurs
void int0Handle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
  Serial.println("int0Handler() triggered");
}

void int1Handle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
  Serial.println("int1Handler() triggered");
}

void int2Handle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
  Serial.println("int2Handler() triggered");
}

void int3Handle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
  Serial.println("int3Handler() triggered");
}

void int4Handle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
  Serial.println("int4Handler() triggered");
}

EmbeddedMan

Sun, 27 Jul 2014 15:27:41 +0000

C-3PO-

OK, so now the following sketch (a very slightly modified version of your original above) is working just fine for me, with the remapping of INT2 to pin 12.

Hope you can get everything working on your project-

*Brian

#define pinInt 12  

void intHandle();
void init_pps();

void setup() 
{
  Serial.begin(115200); 

  digitalWrite(PIN_LED1, LOW);
  pinMode(PIN_LED1, OUTPUT);
  pinMode(pinInt, INPUT);
  
  attachInterrupt(2, intHandle, RISING);
  init_pps();
}

void loop() 
{
  //Debug...
   Serial.println("-> Start...");
   delay(500); 
   Serial.println("-> Loop...");
   delay(500);
   
}

void intHandle() 
{
  digitalWrite(PIN_LED1, !digitalRead(PIN_LED1));
  Serial.println("Interrupt...");

}

void init_pps()
{
  delay(5000); // Debug
  Serial.println("initialisieren INT1"); //Debug
  
  if (mapPps(pinInt, PPS_IN_INT2))
  {
    Serial.println("success mapping INT2 to 12");
  } 
  else
  {
    Serial.println("failure mapping INT2 to 12");
  }

}