ATtiny84: Chip core and pinout chart mismatch?

In the effort to understand building projects around the ATtiny84, I started first with the Arduino Uno and followed the steps to "Shrinkify" it onto the ATtiny85. From there, assuming I understand the terminology and pins for the ATtiny85, I can progress to the ATtiny84 and take advantage of more I/O pins. I've been reading both datasheets and consulting as many online references and forum posts as I could find. The core I'm using is from Google Code Archive - Long-term storage for Google Code Project Hosting..

My pilot project for learning has been a simple TMP36 temp sensor & RGB fading blink program that uses four analog pins, three for output and one for input. Very straightforward on the Uno. For the ATtiny85, I use the following pin assignments which works well:

const int inPin = 3;    // analog in,  to ADC3 for temp sensor, pin 2 on ATtiny85
const int redPin = 0;   // analog out, to PB0 for red LED, pin 5 on ATtiny85
const int bluePin = 1;  // analog out, to PB1 for blue LED, pin 6 on ATtiny85
const int greenPin = 4; // analog out, to PB4 for green LED, pin 3 on ATtiny85

My understanding is that when I assign "1" to variable bluePin on analog output, I'm really referring to "PB1" and from the ATtiny85 datasheet, that corresponds to physical pin 6. A similar definition on an analog input refers to the ADC pin, so you look up what pin that corresponds to. Also understood is that on the datasheet, OC refers to Output Compare, a bar over the label refers to inverted output (Coding Badly says don't concern myself with those), and ADC is the analog-to-digital cerverter pins.

Now, following this logic doesn't seem to work on the ATtiny84, and I'm uncertain why. My questions will be based on the following code, which only runs the blink part of it (omitting the temp sensor for now) using these assignments (plus some trial & error):

const int redPin = 2;   // analog out, to PB2 for red LED, pin 5 on ATtiny84
const int bluePin = 3;  // analog out, to PA7 for blue LED, pin 6 on ATtiny84 <== why does this work?
const int greenPin = 5; // analog out, to PA5 for green LED, pin 8 on ATtiny84
 
void setup() {
  pinMode(bluePin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
}
void loop() {
  GlowLightOnce(bluePin);
  GlowLightOnce(greenPin);
  GlowLightOnce(redPin);
  delay(2000);
}

void GlowLightOnce(int bulb) {
  int brightness = 0;
  int fadeAmount = 5;
  int totalcount = 0;
  do {
    analogWrite(bulb, brightness);
    brightness += fadeAmount;
    totalcount++;
    if (brightness = 255) {
      fadeAmount = -fadeAmount;
    }
    delay(35);
  }
  while (totalcount < 103);
  delay(500);
}

References I used besides the datasheets:

QUESTIONS:

  1. While the redPin and greenPin assignments make sense, I honestly don't know why setting bluePin = 3 sends the signal out physical pin 6. Yet it works! Are my pinout diagrams inaccurate?
  2. If I were to call pinMode(0,OUTPUT), does that refer to PA0 or PB0? I'm unclear on what physical pin I'd use.
  3. Is PA0 through PA7 strictly for analog I/O, and PB0 through PB3 for digital I/O? What goes into choosing PA# over PB#?

Thanks,
Tom

I should add that the code for the ATtiny84 I posted works - I just don't know why in the case of my bluePin definition. It makes me doubt my understanding of the datasheet pin map, which kind of hinders future design :slight_smile:

tlharv:
References I used besides the datasheets:

I can't find PighiXXX's diagrams for the ATtiny processors.

Something about a "bad panda".

(Crude and not always accurate) diagrams for the pin mappings are embedded in the source file...
http://code.google.com/p/arduino-tiny/source/browse/trunk/hardware/tiny/cores/tiny/pins_arduino.c#162

Now, following this logic doesn't seem to work on the ATtiny84, and I'm uncertain why.

The pin mapping for the ATtiny84 processor follows the same pattern used for the ATmega328: starting at the top-level working in a U-shape towards the top-right, number each "usable" pin sequentially.

The ADC mapping is the same. The number after the "ADC" is the analog input.

Pins marked with "OC" in the datasheet are capable of PWM (analogWrite).

tlharv:

  1. While the redPin and greenPin assignments make sense, I honestly don't know why setting bluePin = 3 sends the signal out physical pin 6. Yet it works!

Looks correct. (line #173 in the source file)

Are my pinout diagrams inaccurate?

Don't know. Can't see them.

  1. If I were to call pinMode(0,OUTPUT), does that refer to PA0 or PB0? I'm unclear on what physical pin I'd use.

That would be the first "usable" pin starting at the top-left which coincidentally is PB0 / physical pin 2 (VCC is pin 1).

  1. Is PA0 through PA7 strictly for analog I/O,

Not strictly. Atmel typically makes all pins digital I/O capable and some pins analog input capable.

and PB0 through PB3 for digital I/O?

Probably. Atmel is fairly consistent when they assign port letters to hardware and port B is usual digital I/O plus the crystal driver.

What goes into choosing PA# over PB#?

The port letters? You'd have to ask the folks at Atmel. From our perspective it's just a letter they attached to a chunk of hardware.

Pighixxx's diagram for the T84/44 are not correct for the Attiny-core. I don't know which core he is referencing, but his number is backwards. I would not use that.

Check out this one instead. http://www.akafugu.jp/images/microcontroller-reference-sheet.png
This should work correctly with Attiny-core.

Thanks all for the info, and sorry about the bad links.

The first lesson learned here is that not all microprocessor pin configuration diagrams are the same; it depends on the core you're using. The MIT core is different from the one at code.google, and it's important to get the right diagram in front of you before you begin designing. In this case, the number I assign to my pin name refers to the D# in the pinout diagram, and it's straightforward to get the correct physical pin off the chart. Thanks for clearing that up for me.

The 2nd part of my 3rd question wasn't about Atmel's choice of lettering, but rather about whether we as end users of the chip have reason to use the PA pins over the PB pins... from what I hear people saying, it doesn't really matter. It's a label and the PA# pins are no different from the PB# pins, but some are capable of analog write and some aren't. Makes sense to me.

hiduino:
Pighixxx's diagram for the T84/44 are not correct for the Attiny-core. I don't know which core he is referencing, but his number is backwards.

He may have been referencing the HLT core, it numbers the pins the other way 'round as compared to Arduino-Tiny. But they both do the t85 the same. Wouldn't say that pighixxx is wrong, but he should note which core his diagram applies to. Better, diagram the chip for both cores.

The MIT core is different from the one at code.google...
He may have been referencing the HLT core, it numbers the pins the other way 'round as compared to Arduino-Tiny.

Huh. I wonder why?

Yeah, dunno. EEs do it counter-clockwise XD

Right-hand rule. No longer just for EEs. :wink:

I haven't seen that thing in... well... let's go with "more than a year". :smiley:

[quote author=Coding Badly link=topic=168090.msg1251239#msg1251239 date=1369371051]
starting at the top-level working in a U-shape towards the top-right, number each "usable" pin sequentially.[/quote]

oh lordy... all these years i thought portd was pins 1-7, portb 8-15, etc.. now i see that was coincident and the real method was far more ridiculous than i imagined. who are these guys and what are they trying to do to me?