top of page
Anchor 1

10

Microcontrollers

Today is the day!

The day you open up a whole new world to understanding the modern world around you and learn how you can add to it with your own creations.

The key to your new future lies within your knowledge of microcontrollers also referred to as microchips!

 

AKA CPUs.

 

AKA COMPUTERS.

I hope you are as excited as I am for you.

So, grab a cup of caffeine, a pen, some paper and kiss your mom.  Hold onto your butts.

ic-1892838_640_edited.jpg

You have likely seen these black rectangles and squares everywhere from your PC to RC quadcopters to smartphones.

The fact is they are EVERYWHERE.

What do they do?

What is inside?

How do they work?

The answers will surprise you.

 

If you believe they are complex and difficult to manufacture you would be Right!

If you believe you aren't smart enough to learn how to program them to interpret sensor data or move servos you would be WRONG!

While their complexity can be mind numbing at first glance their operation is profoundly simple.

It's all just a matter of learning how to speak your new little micro friends.

NXP-74AHC00D-HD-HQ_edited.jpg

Here is what it looks like inside a typical chip.

Looks complicated right?

Take a look at this and now take a look at this picture of a motherboard for a computer.

technology-1396677_640_edited.jpg

Look familiar?

How about removing all the soldered on components on a similar board and leaving just the printed circuit board itself, or PCB.

printed-circuit-board-570966_960_720_edi

We are cutting away the fat. Turning your understanding into a lean one. See how cool this is?

"As above, so below"

In the microcontroller you will be learning about there are billions of microscopic transistors.

You do remember what a transistor can do, right? If not brush up now!

These transistors are manipulated by and help to manipulate the flow (current) of electricity.

 

There are networks of these that function as timers, which you will use for interrupts and PWM.

There are analog to digital converters on the chips that can interpret raw electrical input for you so you don't have to do the heavy lifting.

 

Instead, this tiny chip does the heavy lifting for you!

We are just telling the chips to turn electricity on or off.

 

We do this through our code in any language we choose which is compiled and translated to the computer chip's native language of 0's and 1's.

 

So, we can type our code in C but when sent to the chip it is sent as 1000101010111011101101010101101010101010101111111010101010101010101011010101011....

 

The computer chip breaks those electricity ONs and electricity OFFs into chunks, in our case 8 bit chunks.

 

Those chunks are the words for the computer chip.

 

Pretty cool huh?

 

It's like Morse Code!

Are you getting excited yet?

Is the fog surrounding this technology starting to dissipate for you?

 

Here is a picture of an example of those tiny groups of transistors within the chips that help us do incredible things!

 

This was taken with an electron microscope, yeah they are TINY!

800px-1886VE10-SEM-HD_edited.jpg

Let us take a moment of silence in memory of all of the tens of millions of dollars $$$$$$$$(USD) it costs to design, develop and produce these chips.

.....

..

.................    ....

..........................................

.....

Ok that's enough! 

There are many flavors and functions within the almost unlimited kinds of microcontrollers and microchips.

The main differences between your microcontroller and a microchip is the speed and computing abilities inside each.  Microchips found in computers are much more expensive and run so hot you need to attach a heat sink to them to disappate the heat.  This is due to the fact that they are running in the GIGAHERTZ range.

 

Think of 1 Hertz as 1 clock tick per second.

 

Giga means 10^9 or 1000000000. Yeah, They are also capable of crunching longer numbers, more data basically. So, next time you rage while playing Fortnite have some respect for you PC, even if it is a potato, ok?

Your microcontroller operates at the MegaHertz level or Mhz.  This is still really fast.  It doesn't have as many bells and whistles or NO2 to boost it across the finish line but it still gets across and faster than you ever will yourself.

The AVR chips we will use tell how much flash memory they contain in kilobytes, kb in their name. There is limited RAM, working memory, in them.

You can increase the speed of your AVR chip and other brands of chips with a crystal oscillator but you don't need that yet. We don't need that kind of precision. This is a large component on Arduino boards that is unnecessary for beginners.

AVR microcontrollers are 8 bit CPUs. Meaning they can handle 8 bit numbers. They are capable of handling 16 bit numbers but that is a more advanced topic not necessary to know for now.

In other words, AVR chips are under a $1 USD and are POWERFUL and FAST.  MORE than you need as a beginner.

Take a moment just to think how cool it is that you can buy this much power and potential, hold it in your hand, throw it against the wall, hook up even cheaper components to it and program it. All of this for VERY cheap.  Compare the value you will be getting with such a small investment with something like VR gaming or drones.

Remember, you will be building skills that equate to salaries with such a small buy in. The greatest investment required is your time and consistency which is where most fail.

 

But you....you're special. I can feel it.

 

You can do it!

Arduino_avr_atmega8-1_edited.jpg

Typical AVR chip on an arudino board.

Ain't she a beauty? (FYI that metal oval is a crystal oscillator)

ATmega328P_edited.jpg

Time to understand what all this means.

This is the pinout of the AVR328P chip which is used on the popular arduino.  Other chips are similar and you may use them too but their pinout may be slightly different. There may be less or more pins and their arrangement may be different so look out for that.

Vcc in the middle left is red. This is where we plug in our positive voltage from a battery or usb programmer.

The left grey GND is our ground, the negative voltage from the battery or usb programmer.

Notice the pins are all labeled as P and then a letter B,C, or D and then a number.

All the Bs are in the same family called a REGISTER.

These pins are what we will use mostly for OUTPUT.

 

Meaning we will write code that will shoot out electricity on the pins that we specify in the code using the appropriate labels seen here like PB1 or PD7.

Easy!

Notice how some of the D pins are placed down with some of the B pins.

 

I'm sure the developers had very good reasons for this.

 

Maybe to prevent electromagnetic interference within the chips.

 

Remember, it costs TENS OF MILLIONS of dollars to produce these.

Ok, now notice that I highlighted some of the special functions of each pin.

 

The top left I highlighted pink is the reset pin, this will connect to your programmer cable as the programmer needs to pull a resistor high or low to place the chip in receiving mode.

 

Cool huh?

The green TX and RX are the Transmit and Receive pins used to communicate with other sensors or other chips and even your PC.

 

OK!

The OC0A and OC0B as well as the other OC1A and OC1B functions are used specifically to output electricity when working with the Timers built into the chip.

 

Think of them as different kinds of clocks that can do different things for you for now.

The green colored SCK pin is the Serial Clock pin.

 

It is used to set the frequency so that the chip can successfully communicate with a sensor at the right time.

 

Remember my analogy about the soldier and his radio?

 

You feel bad when you miss a call right?

Same thing happening here basically.

The blue line is the Master In Slave Out, MISO, pin so if the chip is receiving some data it goes in through here and it responds back through here to the other chip or sensor.  The MOSI stands for.......

That's right! Master Out Slave In.

 

See? Your mom was right, you ARE smart and handsome!

Ok, then we have the Analog Voltage power or AVCC which we need to power analog devices that will talk to the chip as well as the ground or GND for that.

 

More on how to utilize these correctly in the tutorials.

 

Simply put, failure to use these pins with analog devices can result in jumbled data or it not functioning at all.

The yellow bank of pins are the Analog to Digital Converter pins. We can hook up Analog devices to these pins as they are directly linked to the Analog to Digital Converter built into the chip, ADC for short.

WOW! That's it!

Pop Quiz

1. What does Hertz mean and why is it important?

2. What are some of the functions of the pins of the microchip/microcontroller?

3. What does MOSI stand for and what can it be used for?

4.  Draw a schematic connecting a microcontroller to a battery, a pin to an LED, another pin to a motor connected to same ground source as microcontroller (the - on the battery) with a capacitor and diode attached.

5.  Add a potentiometer connected to power and ground onto an ADC type pin

6. Move the LED connected to ground to the potentiometer output as the LED's power source.

Get my favorite books on programming AVR chips I use.

Equip yourself with the most dependable, no hassle, quality usb programmer I use daily.

Make sure you have a basic kit. Arduino is fine, it contains the removable AVR 328p chip we will use.

 

I started with something very similar.

Summary

How do you feel?

I'm feeling pretty good right about now. I hope you are too!

Go get a drink of ice cool water and maybe squeeze some lemon in that glass because this lesson was refreshing.

We pulled back the curtain on the basic operation and composition of the powerful microcontroller and microchips that run our modern world.

You learned all you need to know about the basics of the AVR chips, specifically the popular 328p.

Keep your ideas flowing because we will learn how to program these chips very soon.

bottom of page