Microcontrollers – Part 3: How They Work

   In the Previous Part 2, we started discussing to microcontroller’s memory arrays – these fundamentally necessary and important modules.

   For clearness in a description, we decided to use the CPU Monkey association, not only as a joke.

 

cpu-1-hardware-pro

   We learned the Ports types, Clocking circuitry – taking the rhythm of work on the low-level instruction set (remember Schiffer of the Leonardo).

   Let imagine the system as a whole:

   The CPU Monkey is sitting on the chair near the table. The Monkey’s hands are very long and the Table is enough to take the following set of things…

   On the table, there are so many switches, as configurable I/O Ports have the imaginary Microcontroller. They are united in eights – Which represents а Byte ideology:

   This is only for your awareness: The Byte representation has its own benefits. If you want to construct the running LED light, for example, the software will be simpler – just using shift instructions and move one leading bit. 

   Here on the table also there is a measuring tool – ADC (in our Monkey’s project it is a simple multimeter).

   Here is a discrete Comparing tool – (in our case it is а primitive, tilting scales).

   We said the RAM memory is structured –  In this part are situated the SFR Registers. At that exactly moment we could lose many of Our readers.

   We would not have admitted it at any price. We only mention the SFR – Special Function Registers. You can see the text below, what we exactly have on mind.

   Imagine that the RAM Memory is a Cabinet, and the SFR are its drawers – there is a lot of drawers!

   Following the instruction, written on Monkey’s notebook, synchronous with the clock by the metronome we start to Debug… to Work as a CPU Monkey.

    The Little Monkey starts reading the instructions or “The Program code” from the Begin (Reset Vector pointing Address  0000h) of its NOTEBOOK – It represents address  0000h  from the CODE or Program (ROM) Memory.

Configuring The MCU Pins:   

   On The second address stays next instruction:

   Example: Set Port-A, bit 0 as Digital Output.  The Monkey Switch-On the necessary Switch on the table associated with DDRA – Data Direction of Register A  to enable the output capability of PORT-A.1  = Output. 

   Example: Set Port-A, bit 1 as Digital Onput.

   Example: Set Port-A, bit 2 as Digital Output.

   Example: Set Port-A, bit 3 as Digital Output.

   Example: Set Port-A, bit 4 as Digital Input.

   Example: Set Port-A, bit 5 as Digital Input.

   Example: Set Port-A, bit 6 as Digital Input.

   Example: Set Port-A, bit 7 as Digital Intput.

 

byte-bit-1-hardware-pro

   By this manner are “Configured” all pins of the described Microcontroller – For convenience in the explanation all other pins we will set as inputs – The Monkey Switch The DDRB, DDRC….. DDRx related Switches to state, allowing configuring of the pins as Pull-Up Inputs. 

   It is important to know: By Hardware Point of view, you must never leave the flying input pins.  Always set them in a stable state – With External Resistor, or with internal configurable Pull-Up Option. In opposite case, can become many side effects – From irregular work manner to additional transients based power consumption of MCU and Power interferences.     

Until Now We have configured only The Ports.

  Need To Configure: ADC Reference Source, ADC, ANALOG Comparator, Timers, Interrupts, UART Interface, SPI Interface, I2C Interface, One-Wire Interface, USB Interface, Ethernet Interface, Wi-Fi Interface, etc.

  But our idealized Microcontroller, for now,  doesn’t need to be configured so complicated – It doesn’t have such interfaces Enabled – for now. 

     cpu-monkey-1-hardware-pro

 

   The CPU Monkey read written instructions one by one and set the related  switches in their necessary states.

   It first Program is not too difficult – The design is simple – on the Pins associated as Outputs we have connected the light indicators – LED Diodes.

   Bit – 0 is following the state of Input Bit-4, the same manner :

   Bit – 1 is following  Input Bit-5  

   Bit – 2 is following  Input Bit-6

   Bit – 3 is following  Input Bit-7

   On Pin A-Bit. [4 .. 7]  Monkey is connected 4 Buttons. (With Debounce Function – smoothing and hiding the false pulses)  

   The Monkey continuously measuring with the multimeter, the state of each one of the inputs (Port-A.4, Port-A.5 ,Port-6.0, Port-A.7 ), synchronous in time with the Clock – Generated by the Metronome. After measuring of state – related with pressed button , that is the moment, monkey Switched-ON the related Output , and Associated In-to-Out  Path is constructed – OUTPUT LED is lit when the input button is pressed.

Power Consumption and System Clock:

   Our CPU Monkey Hardware Experiment Works on a level of seconds. If We need to quick its work then we need to manage the metronome – Down the Load. The Frequency is increasing. 

   But The CPU Monkey will sweat.  Quicker done activities need more energy and generate more heat.

   For Comparison:  More Fast MCUs Need more Power for proper Work.

   In The real Microcontroller, you need to set or adjust (if Calibration of the internal RC generator is used) the Frequency of the Quartz resonator and Clock engine settings/dividers/ PLL multipliers, etc.  

   In the real MCU described CPU Monkey Work has made a million times in a second – depressing, right!

 

Don’t Stop to Reinvent Yourself, Dear Explorers!

To Be Continued !

Leave a Reply