Looking at my Arduino
An Arduino Board is a "single-board microcontroller" - it's a small, simple computer, made cheap and open source. Hopefully this examination will be close to just looking at a computer, but it seems useful to focus on a particular instance of "computer", and so I chose one that at it's core is not modular, and again, is intentionally simple - I'll specifically be referring to the Arduino Mega 2560.
At the core of all computers is a microcontroller - the "single-board microcontroller" description of an Arduino board is not technically correct - the board has lots of components, one of those being the processor. The definitions of computer, processor, microcontroller etc are all quite fuzzy, though - depending on the level of abstraction being used, a laptop could be refered to as anything from the usual 1 computer, to hundreds, maybe more, stacked in a henchcoat, if you want to atomize each piece of hardware and get annoying... but, the ATmega2560 is the name of the microcontroller that this board uses.
- The microcontroller is where all of the logic is done, and, to be annoying, is a complete computer! It has a processor (CPU), memory in the form of flash memory, which is immutable at run time and hosts the user-uploaded program, and RAM, which can be used by the program freely. The specs of the CPU are: 8-bit AVR 16Mhz - 8 bit refers to the bandwidth, so this CPU can process 8 bits per operation. AVR is the architecture of the CPU, some other popular designs are x86 or ARM. As the name would suggest, the architecture of a machine is very important! Different architectures are, intuitivley, built completely differently, and so what might take 1 cycle for CPU A could take 3 for CPU B. The result of this is that when a complier designed to take some code and make it readable by CPU A, it does so in a way that CPU B often cannot interpret - so with high level languages like C, the human readable code can be used regardless of the architecture of your system, but when this code gets translated, it does so in a way unique to your system. 16 MHz is the clock speed, MHz being Megahertz, hertz being a unit of frequency meaning one event / second, and Mega denoting 106, 16 MHz means that the CPU cycles 16 million times per second! Not bad for 40$!
- The Flash memory is non-volatile, meaning that it maintains its data with no power! This is a very common thing, but take a second and think about how crazy it is, especially when you try to consider the magnitude of the data being stored.. my USB flash drive holds 64 GB, which is 549,755,813,888 bits -- half a trillion. There are 9 billion human beings on Earth. And it weighs a few grams, is smaller than half my thumb, and cost me all of 20$. What the hell? How's this work!!? Amazingly, it seems as though there are multiple ways to accomplish this? At it's base, there is the bit. All of these systems, at their core, monitor and manipulate (read and write) from something with 2 discernible states, over and over - RRAM uses a filament - breaking and destroying it to represent 0 and 1. PCM "changes material between crystalline and amorphous states", MRAM manipulates magnetic states, F-RAM changes a materials polarization, Flash (which the Arduino's ATmega uses) manipulates the charge in a transistor. These all make their own trade off along costs, read efficiency, write efficiency, and undoubtedly many more dimensions obscured to the end user, but in the end Flash is far and away the most common, but that such an insane feat can be accomplished by so many seemingly unrelated sects of Science is crazy! So, back to the board: this CPU has a 256KB capacity, KB being K(1000) bytes(B)(8 bits), that's 1000*256=256,000 bytes *8=2,048,000 bits - as evidenced by the following message I get when interfacing with the board: "Sketch uses 1974 bytes (0%) of program storage space. Maximum is 253952 bytes." (a sketch is the Arduino term for program) - 256000-253952=1048 = 210, that being the space allocated for the bootloader which facilitates the writing of user programs to the Flash - that logic needs to be held somewhere and there's only 1 option! The information here is refered to with an address, (from here I will be using hexadecimal) 0x0A12F - the 0x indicating hexadecimal notation, the following 5 characters being hexadecimal for the address of the byte being addressed, so 0x00000 is the "first" byte in memory, up to ~ 0x4000 which would be byte number 262144. An eg representation of storage could be: 0x00000 - 0x0003: A8 1C 34 10 , where the 'data' here is just random. (Because each character is hexadecimal has 24states, it only takes 2 of them to represent a byte and so 0 is 0000, B is 0110, 0B is 00000110 - just a way to represent bytes that people seem to prefer.)
- RAM - the mega2560 uses SRAM, but only a measly 8KB, as RAM is more expensive both in terms of $, and cm2. This is the information that a program edits while running, and all this information is lost when energy is lost. SRAM stands for static random-access memory - static because the information it stores is permanent, given power, random access because all bytes are equally accessible, all are equally easy to access. So, SRAM needs to: be quickly readable, quickly writable, and consistent - to accomplish this, each bit in SRAM uses 6 transistors, versus the 1 in Flash. The use case of this is that the CPU can make a request to the SRAM via a bus with an address (I should explain this later), which will then go and poll or modify the bits needed - all in a few clock cycles - multiple orders of magnitude faster than Flash memory.
- The system in place for these systems to communicate with each other is, of course, invaluable to the success of the board - one of the more fetching parts of a PCB are the visible etchings of wires connecting each piece. If done right (stylistically, I mean), the end product is reminiscent of a signature NYC subway map, but far more elaborate, weaving about the occasional led or chip. It's really a marvel. This system is again, a bunch wires connecting components to each other, with the centerpiece, the ATMega2560, hogging ~100 endpoints of wire, by my count. Once the system like that is in place, the difficultly is coordination - a shared protocol, such that each component knows what it needs to do, is vital - the more obvious form of this is encoding meaning > bits, but a protocol for timings is vital, too, as is a hierarchy of command in case of either of these failing. When a program references a variable, it's easy to say that that is stored in memory and referenced - what's really happening, as if in a children's storybook, is the CPU sending off a request in the form of energy to, say, the RAM, which interprets the nature of the request and the address, fulfills the request, sends back a message, which the CPU reads--all in one clock cycle - many of these transfers of information are happening near the speed of light.
While I am criminally simplifying the systems in place, the interfacing with the ports and pins actually does not seem that far off this level of communication - the brilliant design of the Arduino as a modable computer, asking to be played with have payed off. The Arduino board is truly beautiful
So, to summarize: the ATmega2560 hosts the CPU, the RAM and the Flash memory. The highly choreographed interplay between these three is far and away the important part of the computer. Any external data, be it from the input/ output pins, or a less common mode of interaction - USB, wifi, ethernet, each rely on the CPU interpreting their data in order for it to be meaningful to The User, and so between, eg, the pin and the CPU is a protocol designed to make sure that the information being fed to the CPU is done so at a rate that cannot jeopardize any of the countless other vital operations it may be performing, in a manner that accommodates this tension and the ATmega2560's single core.\
The crystal oscillator is what the CPU leans on to keep a time. I always figured that each component on a board that sends or receives information is getting a signal from this timing mechanism, but in fact the oscillator communicates strictly with the microcontroller, although it's signal reaches every component internal to the ATmega2560, whether directly or indirectly. That agreement on a standard time is needed for high quality communication is relativley intuitive, and so, in 1929, using similar ideas to today, the US National Bureau of Standards and Technology (NIST) actually maintained some huge, 100 kHZ crystal oscillators (if you can't see the image, it's 4 elaborate setups, each of some large bell like instruments encased in a temperature controlled oven). These timings would be broadcast for radio stations needing a reference for their own frequencies or scientists attempting to calibrate a tool/ measure a frequency. Now, I can go out and buy a 16Mhz clock, the same as on this board, which is 160x faster, has an accuracy 10% as large as its senior (accuracy is measured in ppm! which I will explain..), is almost incomparably smaller, is far less picky with inputs concerning power and temperature, and costs you like a dollar. Just what 100 years of economic forces can do!
How the crystal oscillator actually works relies, on the properties of a crystal. If an object is vibrating, be it a guitar string being played, a leaf swaying in the wind, or a human bobbing in the ocean, the object has a 'natural frequency', which is pretty much how frequent that object will oscillate - a beach ball bobbing with the waves will bob accoring to the waves - assume constant waves and the bobbing will be the natural frequency of the beach ball in that exact system -- if i come and push the ball under, it will bob up quickly, then down, up etc, but would eventually return to this natural frequency if left alone. It's not like an object has an inherent natural frequency, it's a product of the environment causing the vibrating - that crystals have a natural frequency is not unique, however the way in which they vibrate when excited by energy is - the natural frequency is much more consistent that other materials, and so can be polled more accurately. The oscillator will store this crystal in a hermetic (air-tight) container - the system then applies a small voltage to the crystal, which it partly absorbs, causing it to vibrate at a frequency very close to its natural frequency (because the voltage is so small), and the rest is sent back, which the system amplifies and send back. So the loop is made, and each repetition is easily measurable. Just squint a bit and accept that the cut of the crystal can predictably effect its natural frequency if the system it will exist in is known, and then squint some more, or just uncritically accept that this process has been engineered such that the crystal will oscillate 10s of millions of times a second, in a measurable and remarkably predictable manner.