I've just spent several hours trying to find out how the Arduino deals with different device packages having different physical pin numbers for the same signals. Hopefully this post might save someone else that time...
According to the Arduino Language Reference, the analogWrite() function "Writes an analog value (PWM wave) to a pin." This appears to imply that analogWrite(3,128); should produce a PWM output on pin 3.
What it actually means is that the PWM output will appear on the pin which carries the Arduino SignalD3. This signal is expressed on Atmel ATmega portPD3, which is connected to TQFP32 PackagePin 1 - but to PDIP28 PackagePin 5.
Therefore: programme using the Arduino signal numbers; the board will be tracked to connect to the signal on the correct pin according to the ATmega package.
How can the software tell which package its in? The silicon die is exactly the same. This
is a universal issue for IC packaging and the reason you use symbolic names for signal
pins in general.
About the only time you need to know is if you are adding a part to a CAD library or
writing test code for a ZIF socket test station, or clipping test-probes onto the part.
Arduino pin numbers are the numbers printed next to the pin-headers, they were never
meant to relate to the internals of the board.
I needed to know physical connections in order to check hardware configuration. Being new to this device I didn't know how it deals with different packages. The sample code appeared to address a physical pin number ("3") rather than a symbolic name and I couldn't find any references to eg a pin map for different devices or a device package header/ini.
On the device I have here (Wild Thumper Robot Controller), the headers are labelled A1, A2... D0, D1, etc (not 1,2,3, etc) and the PWM outputs that I'm interested in appear to be tracked direct, not to headers.
Us hardware guys are a bit literal - if the Language reference said "Writes an analog value (PWM wave) to a port pin", or if the analogWrite() function took the form "analogWrite(_D_3, 128)" I'd have got there a bit quicker
Yep; the "pin numbers" used by the arduino function are what programmers call an "abstraction." They happen to match up with pin numbers labeled on the BOARD LEVEL PRODUCTS, and it's up to the board designer to ensure that supposedly compatible boards using different chip pinouts still behave the same at the "board" level. The core software has the ability to map the "pin numbers" to arbitrary port/bit combinations, so this continues to "work" even when you use s drastically different chip like the 32u4 on a Leonard or the 2560 on a MEGA.