I'm new to the Nano and hardware engineering in general. I am trying to understand the datasheet for this product which I believe is a SAMD21G18 variant. In any case, the datasheet table (7.2) which explains the pin/port function mapping is, frankly, a little hard to understand for me. So it's probably my error. In any case I wrote some code to use phase correct PWM using pin D6 and it seems to work. However, I am not sure if I just got lucky - or what. I used code that I found on this forum, but upon closer examination - am lost. In looking at the datasheet for pin6 - it does not seem to exist in the SAMD21G variant. In using the 33 iot pinout - it clearly indicates this pin is PA04, which is connected to various other pins in the models listed and Pin 9 under the SAMD21G datasheet. So I am not sure why the code works at all. Furthermore, when looking at the pinout diagrams in the datasheet, they all indicate, regardless of model, that PA04 is an analog pin. So this is really confusing because the arduino pinout clearly indicates a digital pin with PWM. Maybe I have the wrong datasheet? Or maybe I just don't know how to decipher them...
The first thing to understand is that Arduino pin numbers are only arbitrary identifiers used to reference IO pins on the microcontroller in Arduino code. Any correlation to the physical pin number on the microcontroller IC package is purely coincidental. So the physical pin number on the microcontroller chip is only of interest if you are designing a circuit around that bare chip.
It is not necessary to understand, but if you are interested in the technical details, the Arduino pin number is the index of an array in the core variant for the board. In the case of Arduino Nano 33 IoT, the relevant code is here:
https://github.com/arduino/ArduinoCore-samd/blob/1.8.12/variants/nano_33_iot/variant.cpp#L63
Note that is element 6 of the g_APinDescription
array.
OK, fair enough; that's good to keep in mind. To make sure I understand - I think you are saying that the source should always be the variant file and other Arduino documentation. But similarly, if Arduino identifies a PA04 pin -- this pin does not necessarily identify the same PA04 pin found in the documentation provided by the manufacturer? If that is true, then, I can deal with that too, but just wanted to be clear what you were saying. (Especially since the ATMEL datasheet indicates that PA04 is an analog pin, not a digital pin that supports PWM.) If that is true, then Arduino has simply renamed the pins - hence my confusion. And that one should be careful w/ relying upon datasheets from the chip manufacturer. (To be clear - not accusing ATMEL of poor documentation - just that Arduino might have renamed some things in non-obvious ways in order to ease development.)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.