0
votes

I am making a basic computer and the chip that syncs everything together is an Attiny85. This chip tells others when they can do things on the data bus.

The principle of how it works is that whenever pin PB0(labeled 11 in IDE or intPin in the code) is set HIGH, the ATtiny85 set all pins LOW then the corresponding pin of the next chip HIGH.

The problem is in the attachPinToInterrupt() statement.

I get this error message when I try to compile the code: Arduino: 1.8.9 (Mac OS X), Board: "ATtiny25/45/85, ATtiny85, Internal 8 MHz"

/Users/alexandrebergeron/Documents/Arduino/computer/computerClock/computerClock.ino: In function 'void setup()':
computerClock:11:47: error: 'digitalPinToInterrupt' was not declared in this scope
   attachInterrupt(digitalPinToInterrupt(intPin), procDone(), RISING);
                                           ^
exit status 1
'digitalPinToInterrupt' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Here's my code:

//common vars
volatile int priority = 0;

//pin numbers
const int intPin = 11;
const int cpuPin = 6;
const int videoPin = 13;

void setup() {
  pinMode(intPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(intPin), procDone(), RISING);
  pinMode(cpuPin, OUTPUT);
  pinMode(videoPin, OUTPUT);
}

void procDone() {
    digitalWrite(cpuPin, LOW);
    digitalWrite(videoPin, LOW);
    switch(priority) {
        case 0:
            digitalWrite(cpuPin, HIGH);
            break;
        case 1:
            digitalWrite(videoPin, HIGH);
            break;
    }
}

void loop() {
  // put your main code here, to run repeatedly:

}

I anybody could help me it would be very appreciated.

Because the chip is only doing that, can it be possible to do something like this?

bool clock = true;

void loop() {
  if (digitalRead(intPin)==LOW) {
    if (clock==true) {
      procDone();
    }
  }
}
2

2 Answers

0
votes

This function is not supported for given boards.

You can enable external interrupts of each pin by setting a correct bit in PCMSK register to 1. You also have to enable this kind of interrupts in GIMSK register (bit 5 and/or 6). I've found a nice example here.

The code:

#include "avr/interrupt.h" 
volatile int value=0;

void setup() {
    GIMSK = 0b00100000;    // turns on pin change interrupts
    PCMSK = 0b00010011;    // turn on interrupts on pins PB0, PB1, & PB4
    sei();                 // enables interrupts
}

void loop() {
}

ISR(PCINT0_vect) {
    value = 1;             // Increment volatile variable
}
0
votes

Spyro!

Your code is most correct, but unfortunately not all pins are available for the External Interrupt function. The digital pin 11 is not an external interrupt pin.

For the arduino pins, you would need to check the following link: https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

For the ATTiny, you only have the external interrupt option on the pin entitled PB2: 1

Try changing the physical connection of your intPin from 11 to 2, for instance, in an arduino Uno, and run the code again:

//common vars
volatile int priority = 0;

//pin numbers
const int intPin = 2;
const int cpuPin = 6;
const int videoPin = 13;

void setup() {
  pinMode(intPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(intPin), procDone(), RISING);
  pinMode(cpuPin, OUTPUT);
  pinMode(videoPin, OUTPUT);
}

void procDone() {
    digitalWrite(cpuPin, LOW);
    digitalWrite(videoPin, LOW);
    switch(priority) {
        case 0:
            digitalWrite(cpuPin, HIGH);
            break;
        case 1:
            digitalWrite(videoPin, HIGH);
            break;
    }
}

void loop() {
  // put your main code here, to run repeatedly:

}

Or change the ATTiny connection from pin PB0 to PB2 and use the snippet JSC has provided, I believe it will work the same.

Let me know if this helps, I think it will solve the issue you're facing.

**Edit: If there is nothing else that your arduino code does, and it's processing time is not long, why not just check the raising edge of your signal?

//common vars
volatile int priority = 0;
uint8_t btn_prev = HIGH;

//pin numbers
const int intPin = 2;
const int cpuPin = 6;
const int videoPin = 13;

void setup() {
  pinMode(intPin, INPUT_PULLUP);
  pinMode(cpuPin, OUTPUT);
  pinMode(videoPin, OUTPUT);
}

void loop() {
  uint8_t btn_state = digitalRead(intPin);

  if ( (btn_state == LOW) && (btn_prev == HIGH) {
     procDone();
  }
  btn_prev = btn_state;

}

void procDone() {
    if(priority == 0) {
       priority = 1;}
    else {
       priority = 0;}  
    digitalWrite(cpuPin, LOW);
    digitalWrite(videoPin, LOW);
    switch(priority) {
        case 0:
            digitalWrite(cpuPin, HIGH);
            break;
        case 1:
            digitalWrite(videoPin, HIGH);
            break;
    }
}