<h3> What is a Microcontroller? </h3> <p> <!-- (From <a href='https://openlabpro.com/guide/basics-of-microcontroller/'> OpenLabPro </a>). --> Microcontrollers are small computers integrated in a single chip. They consist of memory (RAM and ROM), peripherals and a processor (CPU), as opposed to microprocessors which contain only a CPU. </p> <img src="./328p.jpg" alt="328p"> <br><br> <ul> <li>Excellent for embedded applications </li> <li>Low cost and low power consumption (ATMEGA328P ~ $1.5)</li> <li>Can work up to tens of MHz as clock frequency</li> <li>Standalone devices; most of them only need power and a clock source to run</li> </ul> <p>Any gadget or equipment that does things like measuring, controlling, displaying and calculating values usually contains a microcontroller. They are present in: </p> <ul> <li>Almost all contemporary home appliances </li> <li>Data acquisition or monitoring systems </li> <li>Toys</li> <li>Modern cars</li> <li>Traffic lights</li> <li>Smartphones</li> <li>Office instruments</li> <li>Satellites & space applications</li> </ul> <p>You may have heard of some of the companies that make microcontrollers: </p> <ul> <li>Microchip</li> <li>Atmel (now part of Microchip) </li> <li>Intel</li> <li>Analog Devices</li> </ul> <h3> Parts of a Microcontroller </h3> <p> <img src="./architecture.jpg" alt="architecture"> <br><br> <ul> <li> CPU: The most important part of a microcontroller is a central processing unit with a word length ranging from 4-bit to 64-bit. The central processing unit fetches, decodes and executes the instructions. It coordinates various activities taking place in the microcontroller.</li> <li> I/O ports: There are several parallel input/output ports in a microcontroller. They are used to interface various peripherals such as printers, external memories, LEDs and LCDs to the microcontroller. Apart from parallel ports, there are serial ports to interface serially connected peripherals with the microcontroller.</li> <li> Memory: Microcontrollers usually contain a certain amount of flash memory to store program source code as well as ROM (EEPROM) for permanent storage and RAM for temporary storage. </li> <li> Timers and counters: Timers and counters are used in operations which include modulation, clock functions, frequency generation and measuring and pulse generation.</li> <li> Analog to digital converters (ADCs): Such converters are useful while converting the output of a sensor which would be in analog form.</li> <li> Digital to analog converter (DAC): The working of a DAC is just the reverse of an analog to digital converter. As it is obvious, the output will be an analog signal which can be used to control the analog peripherals such a motor.</li> </ul> </p> <!-- http://www.nipne.ro/dpp/Collab/LHCb/upgrade/outreach/Introduction%20to%20Microcontroller%20Arduino%20tutorial.pdf --> <h3> Power and Logic </h3> <p> Digital vs. Analog: Most microcontrollers (including Arduino) can input and output analog signals as well as digital signals. </p> <p> An analog signal is one that can take on any number of values, unlike a digital signal which has only two values: HIGH and LOW. To measure the value of analog signals, the Arduino has a built-in analog-to-digital converter (ADC). The ADC turns the analog voltage into a digital value. The function that you use to obtain the value of an analog signal is analogRead(pin). This function converts the value of the voltage on an analog input pin and returns a digital value from 0 to 1023, relative to the reference value. The default reference voltage is 5 V (for 5 V Arduino boards) or 3.3 V (for 3.3 V Arduino boards). It has one parameter which is the pin number. </p> <p>Pulse Width Modulation (or PWM) is a technique for controlling power. We can use it to control the speed of a motor or the brightness of LEDs. The diagram below shows the signal from one of the PWM pins on the Arduino.</p> <img src="./pwm.jpg" alt="pwm"> <br><br> <p> Roughly every 1/500 of a second, the PWM output will produce a pulse. The length of this pulse is controlled by the 'analogWrite' function. So 'analogWrite(0)' will not produce any pulse at all and 'analogWrite(255)' will produce a pulse that lasts all the way until the next pulse is due, so that the output is actually on all the time. </p> <p> If we specify a value in the analogWrite that is somewhere in between 0 and 255 then we will produce a pulse. If the output pulse is only high for 5% of the time then whatever we are driving will only receive 5% of full power. </p> <p> If however the output is at 5V for 90% of the time then the load will get 90% of the power delivered to it. We cannot see the LEDs turning on and off at that speed, so to us, it just looks like the brightness is changing </p> <h3> Memory </h3> <!-- RAM: Stands for random access memory; refers to memory that the microprocessor can read from and write to. When you create something in memory, it’s done in RAM. ROM: Stands for read-only memory. The microprocessor can read from ROM, but it can’t write to it or modify it. ROM is permanent. Often, ROM chips contain special instructions for the computer — important stuff that never changes. The microprocessor can access information stored on a ROM chip whenever it needs to. The instructions are always there because they’re not erasable. Flash memory: A special type of memory that works like both RAM and ROM. You can write information to flash memory, like you can with RAM, but that information isn’t erased when the power is off, like it is with ROM. Sadly, flash memory isn’t as fast as RAM, so don’t expect it to replace standard computer memory any time soon. --> <p>Flash memory:</p> <ul> <li>Remembers data after power is turned off.</li> <li>Slow read/write speeds compared to RAM/ROM</li> <li>Can be manufactured in higher storage capacity than RAM/ROM</li> <li>Used for SSDs, USB drives</li> </ul> <p>RAM (Random Access Memory)</p> <ul> <li>Loses data when powered off.</li> <li>Fast read/write speeds</li> <li>Relatively expensive to manufacture</li> <li>Used for storing program memory while computer is running</li> </ul> <p>ROM (Read Only Memory)</p> <ul> <li>Does not lose data when powered off</li> <li>Hard to write to</li> <li>Speeds vary from very fast to flash memory speed</li> <li>Usually used for storing the software to boot a computer/device nowadays.</li> </ul> <h3> What is Arduino? </h3> <ul> <li>An integrated development environment (IDE).</li> <li>A set of libraries.</li> <li> <a href='./arduino_boards.html'>Arduino Boards.</a></li> </ul> <h3> Microcontroller boards</h3> <ul> <li> <a href='./arduino_boards.html'>Arduino Boards</a></li> <!-- <li> <a href='https://roberthart56.github.io/SCFAB/SC_lab/Electronics/Microcontrollers/Adafruit/index.html'>Adafruit M4 Itsy Bitsy and Adafruit M4 express.</a> </li> <li> <a href='https://roberthart56.github.io/SCFAB/SC_lab/Electronics/Microcontrollers/ATSAMD11/Advanced_circuits_board/index.html'>ATSAMD11 boards.</a></li> --> <li> ESP32 - system on a chip (SoC). Adafruit's Huzzah board is a development board using this chip. </li> </ul>