Rob

Do external interrupts work for

Recommended Posts

Hi, I'm new to the papilio one, just received mine last weekend. I had time to get a couple of sketches working in the papilio-arduino IDE and learn some VHDL as well. I have two questions at this point. I have searched for days trying to figure this out, I'm ready to throw myself at your mercy.

 

Do external interrupts work for the core that the papilio-arduino IDE uses? I tried to use attachinterrupt(0, isrfunction, FALLING), had a counter increment in the ISR and printed the counter to an lcd. The ISR never gets called. I have checked the lcd code by incrementing the counter in the loop() function, that works fine. I just want to increment a counter when an IO pin changes state (on the falling edge). I can provide the scripts(sketches?) if needed, though they are very simple. 

 

Also I can not get the papilio-loader GUI to run. I starts a 64bit java process and hangs. I have the latest version (afaik) from the newer gadgetfactory site, version 2.4. I'm running Win 7 x64. Other java apps seem to run just fine, though most seem to be 32 bit. I have removed and re-installed several times, nothing changed. 

 

Hopefully i Haven't left anything out. Thanks in advance!

 

Rob

 

 

Share this post


Link to post
Share on other sites

I'm afraid the external interrupts are connected to ground:

 

--****************** Timer/Counter **************************TmrCnt_Impl:if CImplTmrCnt generateTmrCnt_Inst:component Timer_Counter port map(	           -- AVR Control               ireset     => core_ireset,               cp2	      => clk16M, -- clk,			   cp2en	  => vcc,			   tmr_cp2en  => vcc,			   stopped_mode   => gnd,			   tmr_running    => gnd,               adr        => core_adr,               dbus_in    => core_dbusout,               dbus_out   => tc_dbusout,                iore       => core_iore,               iowe       => core_iowe,               out_en     => tc_out_en,			   -- External inputs/outputs               EXT1           => gnd,               EXT2           => gnd,			   OC0_PWM0       => OC0_PWM0_SIG,			   OC1A_PWM1A     => OC1A_PWM1A_SIG,			   OC1B_PWM1B     => OC1B_PWM1B_SIG,			   OC2_PWM2       => OC2_PWM2_SIG,			   -- Interrupt related signals               TC0OvfIRQ      => core_irqlines(15),  -- Timer/Counter0 overflow ($0020)			   TC0OvfIRQ_Ack  => ind_irq_ack(15),			   TC0CmpIRQ      => core_irqlines(14),  -- Timer/Counter0 Compare Match ($001E)			   TC0CmpIRQ_Ack  => ind_irq_ack(14),			   TC2OvfIRQ      => core_irqlines(9),	-- Timer/Counter2 overflow ($0014)			   TC2OvfIRQ_Ack  => ind_irq_ack(9),			   TC2CmpIRQ      => core_irqlines(8),	-- Timer/Counter2 Compare Match ($0012)			   TC2CmpIRQ_Ack  => ind_irq_ack(8),			   TC1OvfIRQ      => open,			   TC1OvfIRQ_Ack  => gnd,			   TC1CmpAIRQ     => open,			   TC1CmpAIRQ_Ack => gnd,			   TC1CmpBIRQ     => open,			   TC1CmpBIRQ_Ack => gnd,			   TC1ICIRQ       => open,			   TC1ICIRQ_Ack   => gnd,				PWM0bit		   => PWM0bit,				PWM10bit		   => PWM10bit,				PWM11bit		   => PWM11bit,				PWM2bit		   => PWM2bit);

I'll see if I can make some time to connect those as swappable pins.

 

Jack.

Share this post


Link to post
Share on other sites

Thanks, I've been digging around in the AVR core, but I've got about a week of VHDL under my belt and that core is a little overwhelming. I did follow the tutorial on connecting a signal to an external pin (the pwm tutorial). I also watched the tutorial on adding a custom user core and simulating it. I've made it through both of those, and tried a couple of things to get the interrupt going, but no luck yet. I can tell you about 5 ways that don't work!  

 

for example scroll down to the unused core_irqlines section of the avr top module. and I wrote this

core_irqlines(0) <= porta(2);   -- trying to tie external pin to irq.0

 

that just locks up the core! haha

 

also tried enabling the custom user core and tried tying the input_sig to porta(2) and the output_sig to the core_irqline(0); didn't work that way either lol..

 

I just don't have enough time with that core to have a good mental model of what that it looks like. Today i'm going to do some more simulations to see what went wrong with my custom user core, but it looks like i'm barking up the wrong tree altogether. I had no idea that EXT1 and EXT2? were the signals to use. 

 

can I just do this in the timer/counter port map?

EXT1 => core_irqlines(0);

EXT2 => core_irqlines(1);

 

I'm going to go try after lunch! Will let you know how it goes.

 

Thanks again!

Share this post


Link to post
Share on other sites

ok I tried, 

EXT1 => core_irqlines(0);

 

That didn't work either. I'm not sure I'm doing this correctly though. Should I connect EXT1 to the core_irqlines, or to the pin I want to trigger the interrupt?

 

I guess EXT1 => porta(2); is next.... 

 

crossing my fingers lol!

 

 

EDIT:

Well, EXT1 => porta(2); is no help either. I'm so lost it isn't funny!

Share this post


Link to post
Share on other sites

I haven't given up yet, so here is what I learned (I think).

EXT1 is an input to the timer_counter so trying to do this "EXT1 => core_irqlines(0);", was silly.

I think the signal chain to get the interrupt going should look something like this:

porta(2)->EXT1->???->core_irqlines(0)->irqlines(0)

but i'm not sure and I don't exactly know what goes in place of the ???, though I think in my case I want EXT1FE, so it looks like this:

porta(2)->EXT1->EXT1FE->core_irqlines(0)->irqlines(0)

(I think I have to get EXT1FE back out of the timer_counter, but that's basically it i think)

Is that correct signal path to get an interrupt working when pin 2 changes(falling edge)?

Also, I noticed in your post there was some PWMbits at the bottom of the timer_counter port map. My code (AVR 8 Version 1.6) didn't have that. So, I pulled the source from github, and that did have the PWM stuff as well as the pin swapping code, that I didn't even realize I was missing.

I studied some of the pin swapping code, and it seems pretty straightforward. If I can just picture the correct signal path to get the interrupts going I might be able to get the pin swapping part going also.

Jack, would you mind just pointing me in the right direction with the signal path, pretty please?

Thanks again!

Rob

Share this post


Link to post
Share on other sites

Hello Rob,

 

I've been trying to get to this one. :) I wanted to put together an example for you, but I keep getting slammed from every direction this week... You are on the right track, I think you need to do something like this:

 

porta(2) <- EXT1;

 

But then you also need to ensure that the GPIO is not connecting to porta(2) too. You can manually set the DDR register for that GPIO to disable it or use the generics at the top to disable the whole port.

 

Will try to dig in deeper in a little bit here.

 

Jack.

Share this post


Link to post
Share on other sites

Thanks Jack.

 

There is no rush I was just trying to learn and figure it out on my own, and trying to be a good net citizen and share what little I've figured out :)

 

I'm going to keep trying. I think I'm close, I did disconnect the GPIO by just turning all of port A off(set that Impl flag to false). Also tried the DDR register method. I also freed up the irq line in the unused irq line section (core_irqlines (3 downto 1) instead of (3 downto 0). I think I just have something messed up with the signal path, and the clue is in your post. I just have to figure it out.

 

Rob

Share this post


Link to post
Share on other sites

I've never played with the external interupts so it might be something unexpected. I have some time now and will start trying to get it to work, will be in the chat room.

 

Jack.

Share this post


Link to post
Share on other sites
ok heres the sketch i am using

 

#include <LiquidCrystal.h>

 

#define PIN_ANEMOMETER  A2 

 

#define PIN_LCD_RS      B0

#define PIN_LCD_RW      B1

#define PIN_LCD_EN      B2

#define PIN_LCD_D0      B3

#define PIN_LCD_D1      B4

#define PIN_LCD_D2      B5

#define PIN_LCD_D3      B6

#define PIN_LCD_D4      B7

#define PIN_LCD_D5      B8

#define PIN_LCD_D6      B9

#define PIN_LCD_D7      B10

#define PIN_LCD_CONT    A15 // contrast control.

 

LiquidCrystal  lcd( PIN_LCD_RS, PIN_LCD_RW, PIN_LCD_EN,  PIN_LCD_D0,PIN_LCD_D1,PIN_LCD_D2,PIN_LCD_D3,  PIN_LCD_D4,PIN_LCD_D5,PIN_LCD_D6,PIN_LCD_D7); 

volatile unsigned int numRevsAnemometer = 0;

 

void setup() {

   //initialize the LCD

   pinMode(PIN_LCD_CONT, OUTPUT);

   digitalWrite(PIN_LCD_CONT, LOW);

   lcd.begin(8, 2);

   lcd.clear();

 

   //initialize the anemometer inputs

   pinMode(PIN_ANEMOMETER, INPUT);

   //digitalWrite(PIN_ANEMOMETER, HIGH);

   attachInterrupt(0, countAnemometer, FALLING);

 

}

 

void loop() {

   lcd.setCursor(0,0); 

   lcd.print(numRevsAnemometer);

   

   //numRevsAnemometer++;

}

 

// Interrupt handler for anemometer.

void countAnemometer(void) {

   numRevsAnemometer++;

}

Share this post


Link to post
Share on other sites

Ok, after some digging into the code we have determined that external interrupts are not implemented.

 

There is Extenal Pin T1 and External Pin T2 that can increment Timer 1 and 2, but no full external interrupt support.

 

Jack.

Share this post


Link to post
Share on other sites

Just wanted to finish up with a big thanks to Jack. We did a lot a digging around and he spent quite a bit of time helping out :)

 

Thank you very much Jack!

Share this post


Link to post
Share on other sites

I have another update. I took a break, came back fresh and figured out how to do what I wanted to :)

 

Step 1: Turn off port A

constant CImplPORTA            : boolean := FALSE; 

 

Step 2: Connect EXT2 to  port A in the timer port map

EXT2 => porta(2);

 

Step 3: synth that and copy to custom bit file

 

Step 4: run this sketch

 

 

#define PIN_ANEMOMETER  A2 void setup() {     pinMode(PIN_ANEMOMETER, INPUT);  Serial.begin(9600);  TCNT2 = 0;  TCCR2 = 0;  //EXT2FE and CS22 and CS21 and not CS20  TCCR2 |= _BV(CS22);      TCCR2 |= _BV(CS21);    TCCR2 &= ~_BV(CS20);  }void loop() {  int time = TCNT2;   Serial.print(time);  Serial.print("\r\n");}

 

it has timer 2 count up on every falling edge of A2. Just what I wanted, only without using the external interrupt!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now