Author Topic: Standard Interrupts (Rising Edge, Hardware)  (Read 5077 times)

AbeFM

  • Newbie
  • *
  • Posts: 3
Standard Interrupts (Rising Edge, Hardware)
« on: July 19, 2016, 03:48:33 pm »
Howdy!!! I've got a program running on an UNO, but would like to make it a bit harder for automotive applications, and found a selection of Attiny's which are rated for such. I'm only using 2 pins so it seems like an all around win for me.

But now I'm trying to port my code from the 328P and I'm not sure what I can and can't use.

I really want to have a fast, reliable interrupt to gather my timing information - I want to be in the ballpark of +/- 1ms. I tried using:
   attachInterrupt(digitalPinToInterrupt(Int0Pin), IgnISR, RISING);  //dPTI for compatibility across devices, triggers on rising edge
but it wouldn't compile due to "digitalPinToInterrupt()", when I took that out it compiles but nothing's working yet. The forums/internet shows a lot of people using TinyPinChange, but I don't need the "change" functionality, so perhaps it's not a good fit?

EDIT: Looks like PCINT0 != INT0. INT0 resides on pin 7, sharing the pin with PCINT2.

Can anyone tell me if I'm headed in the right direction?



Lastly, am I being reasonable that this is in fact a superior chip for what I'm doing? I have timing/accuracy/oscillator questions but will save them for another thread. Thanks in advance for any help!!
« Last Edit: July 19, 2016, 05:38:09 pm by AbeFM »

AbeFM

  • Newbie
  • *
  • Posts: 3
Re: Standard Interrupts (Rising Edge, Hardware)
« Reply #1 on: July 19, 2016, 06:00:13 pm »
Well, that's fun. So I find out I'm using the wrong pin, even though I seem to be able to trigger the interrupt with P2, I thought I should make the code match.

Only when I try to upload, the Digispark "adds" to windows (USB add device sound) over and over - about every 1-2 seconds.

Also, my code seems to be running straight away - the 5 second delay doesn't seem to be there? I've little idea how I managed to accomplish this - does anyone know how to make it behave? I thought it was just windows7 being persnickety, but I shouldn't get flashing lights for a few seconds!

The code I believe to be loaded on the chip:

Code: [Select]
#define DEBUG 1  // Set to 1 to enable, 0 to disable
 
#if DEBUG
#define DebugPin 1  // Digispark model A onboard LED
#define DebugBlink 75
#define DebugPause 300
#define debugDelay(ms) delay(ms)  // Change if you need a special delay function (e.g. if you use libraries that need regular refresh calls)

  const byte Int0Pin = 0;   //I want to change this to 2, but I'm not sure I need it at all?
 
void _debugBlink(int n) {
  for ( int i = 0 ; i < n ; i++ ) {
    digitalWrite(DebugPin, HIGH);
    debugDelay(DebugBlink);
    digitalWrite(DebugPin, LOW);
    debugDelay(DebugBlink);
  }
  debugDelay(DebugPause);
}

void Blink() {
  for ( int i = 0 ; i < 3 ; i++ ) {
    digitalWrite(DebugPin, HIGH);
    debugDelay(DebugBlink * 3);
    digitalWrite(DebugPin, LOW);
    debugDelay(DebugBlink * 3);
  }
  debugDelay(DebugPause);
}

 
void _debugSetup() {
  pinMode(DebugPin, OUTPUT);
}
 
#define debugBlink(n) _debugBlink(n)  // Do the blink when DEBUG is set
#define debugSetup() _debugSetup()
#else
#define debugBlink(n)  // Make the calls disappear when DEBUG is 0
#define debugSetup()
#endif

void setup() {
     // Interrupts
    //I could later swap out for enableInterrupt() function, supposed to be cleaner.
   pinMode(Int0Pin, INPUT);                   //Define interrupt pin as INPUT, no pull-up.
   attachInterrupt(Int0Pin, Blink, RISING);  //dPTI for compatibility across devices, triggers on rising edge
 
  }
 
void loop(){
  debugBlink(10);
  delay(5000);
}

Sorry it's kinda choppy, I grabbed a blink code online as a reality check and built from there.

AbeFM

  • Newbie
  • *
  • Posts: 3
Re: Standard Interrupts (Rising Edge, Hardware)
« Reply #2 on: July 20, 2016, 11:40:08 am »
Interesting behavior on one of my boards - it seems that if I leave the inputs floating (on the 328 I couldn't use a pull up on the interrupt pin), either pin 2 or 3 will trigger an interrupt.

If I ground P2 strongly P3 stops triggering interrupts, though if I ground it weakly (470 ohm pulldown) P3 can still trigger the interrupt. Pulling P2 high seems to prevent this cross talk. I only have one Tiny, so I can't tell if this is a function of the chip or not - would anyone else be willing to load the code (or their own) and see if Pin P3 triggers interrupts?

I wonder if the issue I was having on the other board was related to USB triggering interrupts, preventing communication? I want to set the fuses but I end up in a rabit hole of errors:

Quote
"Arduino: 1.6.8 (Windows 7), Board: "Digispark (Default - 16.5mhz)"

Error while burning bootloader: missing 'bootloader.tool' configuration parameter