[SOLVED] PIC32 external trigger

User avatar
jwzumwalt
Posts: 12
Joined: Wed Dec 02, 2015 10:43 pm

[SOLVED] PIC32 external trigger

Post by jwzumwalt » Thu Mar 03, 2016 5:06 am

How2 interrupt attachInterrupt()

Postby jwzumwalt » Tue Mar 01, 2016 4:37 pm
I am trying to get attachInterrupt() to work in Pinguino. The interrupt is supposed to toggle the LED at reqular intervals.

The Arduino format for using attachInterrupt() is shown at

https://www.arduino.cc/en/Reference/AttachInterrupt

a simple example is shown

I tried 1 thru 14 for the interrupt number without success... any ideas?

Code: Select all

int pin = 13;
int state = LOW;

void blink() {
  state = !state;
}

void setup() {
  pinMode(pin, OUTPUT);
  attachInterrupt(<1 thru 14>,blink,LOW);
}

void loop() {
  digitalWrite(pin, state);
}
How do I have an external pin event trigger a interrupt routine?
I'm not picky about /RISING/FALLING, I'll settle for anything.
Last edited by jwzumwalt on Tue Mar 08, 2016 6:10 am, edited 1 time in total.
Thanks!
jwzumwalt
(\__/)
(='.'=)
(")_(")

EmbeddedMan
Posts: 597
Joined: Tue May 24, 2011 9:24 pm
Location: Minneapolis, MN
Contact:

Re: PIC32 external trigger

Post by EmbeddedMan » Sat Mar 05, 2016 1:53 am

Check out the first example on this page - maybe it will help you : https://github.com/fubarino/fubarino.gi ... e-Examples

*Brian

User avatar
jwzumwalt
Posts: 12
Joined: Wed Dec 02, 2015 10:43 pm

Re: PIC32 external trigger

Post by jwzumwalt » Sat Mar 05, 2016 6:41 am

Check out the first example on this page - maybe it will help you : https://github.com/fubarino/fubarino.gi ... e-Examples
*Brian
After reviewing the above example you provided, it appears that the attachInterrupt() is not working with Pinguino.
Can anyone else confirm this
Thanks!
jwzumwalt
(\__/)
(='.'=)
(")_(")

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: PIC32 external trigger

Post by majenko » Sat Mar 05, 2016 1:46 pm

The attachInterrupt works fine with the Pinguino micro.

I have tested all 5 interrupts and found where they are connected to:
  • Interrupt 0 is connected to the button
  • Interrupt 1 is connected to CONN1-14
  • Interrupt 2 is connected to UEXT-6
  • Interrupt 3 is connected to UEXT-5
  • Interrupt 4 is connected to CONN1-13
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
jwzumwalt
Posts: 12
Joined: Wed Dec 02, 2015 10:43 pm

Re: PIC32 external trigger

Post by jwzumwalt » Mon Mar 07, 2016 12:49 am

Would you please post the program listing you used?
thx
Thanks!
jwzumwalt
(\__/)
(='.'=)
(")_(")

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: PIC32 external trigger

Post by majenko » Mon Mar 07, 2016 1:48 am

I don't have it now, but I will see if I can recreate it here:

Code: Select all

void setled() {
    static bool lval = false;
    lval = !lval;
    digitalWrite(26, lval);
}

void setup() {
    pinMode(26, OUTPUT);
    attachInterrupt(0, setled, FALLING);
}

void loop() {
}
If I got the LED pin number right then pressing the user button should toggle the LED.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

User avatar
jwzumwalt
Posts: 12
Joined: Wed Dec 02, 2015 10:43 pm

Re: PIC32 external trigger

Post by jwzumwalt » Mon Mar 07, 2016 8:18 am

The above code did not seem to work.
I modified the program to see if it was working and it does appear to lock up.

int lval = 0;
int state = 0;
void setled() {
lval = !lval;
digitalWrite(10, lval);
}

void setup() {
pinMode(10, OUTPUT);
pinMode(13, INPUT);
attachInterrupt(0, setled, FALLING);
}

void loop() {
state = !state;
digitalWrite(10,state);
delay(2000);
}
Thanks!
jwzumwalt
(\__/)
(='.'=)
(")_(")

GastonLagaffe
Posts: 101
Joined: Sun Oct 26, 2014 2:50 pm

Re: PIC32 external trigger

Post by GastonLagaffe » Mon Mar 07, 2016 9:38 am

Salut,

I tested it on my Olimex PIC32-Pinguino-Micro:

Code: Select all

volatile int state = 1;

void blink() {
	state = !state;
}

void setup() {
	pinMode(PIN_LED1, OUTPUT);
	pinMode(PIN_LED2, OUTPUT);
	attachInterrupt(0, blink, FALLING);
}

void loop() {
	digitalWrite(PIN_LED2, state);
  digitalWrite(PIN_LED1,!digitalRead(PIN_LED1));
  delay(500);
}
Pushing the button will toggle the led, the second LED is only used to show that the processor is working (simple blink)

I hope, this helps.

Ciao, Mathias

User avatar
jwzumwalt
Posts: 12
Joined: Wed Dec 02, 2015 10:43 pm

Re: PIC32 external trigger

Post by jwzumwalt » Mon Mar 07, 2016 4:45 pm

YAHOOO!!!

It worked!

I did rearrange things to prove to myself the interrupt routine was doing the work
Thanks, everyone for the help.

Code: Select all

// green led blinks using loop delay.
// yellow led toggles if button pushed using interrupt routine

int state = 1;

void blink() {
   state = !state;
   digitalWrite(PIN_LED2, state);
}

void setup() {
   pinMode(PIN_LED1, OUTPUT);
   pinMode(PIN_LED2, OUTPUT);
   attachInterrupt(0, blink, FALLING);
}

void loop() {
  digitalWrite(PIN_LED1,!digitalRead(PIN_LED1));
  delay(500);
}
Last edited by jwzumwalt on Tue Mar 08, 2016 6:08 am, edited 1 time in total.
Thanks!
jwzumwalt
(\__/)
(='.'=)
(")_(")

GastonLagaffe
Posts: 101
Joined: Sun Oct 26, 2014 2:50 pm

Re: PIC32 external trigger

Post by GastonLagaffe » Mon Mar 07, 2016 5:18 pm

Great!

The Olimex documentation is a bit confusing as it refers to it more from a Pinguino point of view.

Ciao, Mathias

Post Reply