PIC Microcontrollers Course Home Page <\/strong><\/span>????<\/a><\/td>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n In this tutorial, you’ll get to know what are microcontrollers? What’s inside a typical MCU chip? How do PIC microcontrollers operate? Set everything up, and become familiar with the development environment or the Microchip PIC microcontrollers ecosystem which we’ll be using through this series of tutorials. Using MPLAB X IDE, XC8 Compiler, and PICkit2 or 3.<\/span><\/p>\n[toc]<\/p>\n \n\u00a0 \u00a0Introduction To Microcontrollers\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n <\/p>\n As we stated earlier, an embedded system is a computerized system that in most cases will not look like a computer. We’ve also mentioned numerous examples of embedded devices applications. The computers being embedded in these devices are small microcontrollers (MCUs) or also abbreviated as\u00a0\u00b5C. You should also know that microcontrollers are not the only option out there for embedded solutions\/devices, but MCUs are our main interest in this series of tutorials.<\/span><\/p>\nNow, we’ll consider one of the previous embedded devices examples to have a closer look at its main components. Let’s consider the Drone for example.<\/span><\/p>\n<\/p>\n A typical drone will have an internal structure as shown in the diagram below.<\/span><\/p>\n<\/p>\n Well, this aerial robot consists of some mechanical & electrical parts. We’re only concerned with the electronic embedded system which has the following components<\/span><\/p>\n\n\n\nSensors<\/span><\/strong><\/span><\/td>\nCamera<\/span><\/strong><\/span><\/td>\nElectronic sensor used for imaging and video recording.<\/span><\/td>\n<\/tr>\n\nGPS<\/span><\/strong><\/span><\/td>\nThis sensor is used to get the coordinates information of the vehicle at any instance of time. Widely used for locomotion tasks.<\/span><\/td>\n<\/tr>\n\nIMU<\/span><\/strong><\/span><\/td>\nAn IMU is an inertial measurement unit. It’s typically used to get information about the static\/dynamic properties of the vehicle. Such as angular rates, tilt angle, and acceleration in 3 axes. In order to keep its balance and plan for smooth maneuvering.<\/span><\/td>\n<\/tr>\n\nCompass<\/span><\/strong><\/span><\/td>\nThis sensor is used to measure the heading angle of the vehicle which is very helpful for controlling its orientational motion.<\/span><\/td>\n<\/tr>\n\nModules<\/span><\/strong><\/span><\/td>\nWiFi<\/span><\/strong><\/span><\/td>\nThis modules adds a WiFi internet connectivity to the vehicle. Used for control or data transfer<\/span><\/td>\n<\/tr>\n\nRF<\/span><\/strong><\/span><\/td>\nThis modules adds a Radio Frequency connectivity to the vehicle. Used for communicating with the control station.<\/span><\/td>\n<\/tr>\n\nExternal Memory<\/span><\/strong><\/span><\/td>\nOn-Board additional memory for data & settings storage<\/span><\/td>\n<\/tr>\n\nDrivers Circuitry<\/span><\/strong><\/span><\/td>\nESCs<\/span><\/strong><\/span><\/td>\nElectronic Speed Controllers. These electronic circuits are pre-built and packaged devices that are being sold as an electronic driver solution used for brushless motors.<\/span><\/td>\n<\/tr>\n\nActuators<\/span><\/strong><\/span><\/td>\n4 x Brushless Motors<\/span><\/strong><\/span><\/td>\nThese are the actuators that cause motion for this vehicle.<\/span><\/td>\n<\/tr>\n\nDC Power Source<\/span><\/strong><\/span><\/td>\nBatteries<\/span><\/strong><\/span><\/td>\nThe rechargeable power source used for drones. It’s the bottleneck of the whole system which can definitely tell for how long can this machine fly in the air.<\/span><\/td>\n<\/tr>\n\nCentral Computer<\/span><\/strong><\/span><\/td>\nMicrocontroller<\/span><\/strong><\/span><\/td>\nThis is the brain of the system that handles all computations implemented in the control system mathematical model. It also interfaces all sensors to collect all the needed data for a robust controlled behavior and also communicates with the operator (you<\/strong>) via the RF module to pass your commands to the vehicle which will follow them.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n There is no doubt that the\u00a0\u00b5C or the embedded computer is the most important part of these components as it handles almost everything. A typical sensor or actuator may possibly have a datasheet associated with it that can take no longer than 10 pages. On the other hand, a very simple microcontroller will typically have a datasheet that is no less than 100 pages long. In fact, most MCUs chips have datasheets that are between 200-2000 pages long! Each module within these small chips can have a documentation that is 25 pages long on average.<\/span><\/p>\nThat’s why in the following tutorials we’ll be more focused on the microcontroller programming and we’ll discuss each of the modules in detail to understand the underlying mechanics. However, we’ll also be interfacing many of the common modules & sensors on our way through. We’ll do our best to balance between understanding all the MCU’s modules in detail, and practically interface some sensors\/actuators to create small projects. So stick with me! It’s gonna be tough indeed but it’s really worth it and definitely rewarding!\u00a0<\/span><\/p>\n \n\u00a0 \u00a0What is a Microcontroller?\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n <\/p>\n A Microcontroller<\/strong> is a single-chip, self-contained computer which incorporates all the basic components of a personal computer on a much smaller scale. Microcontrollers are typically used as embedded controllers that control some parts of a larger system such as mobile robots, computer peripherals, etc.<\/span><\/p>\nA microcontroller is fundamentally a smaller version of your personal computers. It has the same exact component but with limited capabilities and resources. An arbitrarily-made comparison between X-Computer and Y-MCU may result in a table that looks like the one below.<\/span><\/p>\n\n\n\n<\/td>\n | Computer<\/span><\/strong><\/span><\/td>\nMicrocontroller<\/span><\/strong><\/span><\/td>\n<\/tr>\n\nRAM<\/strong><\/span><\/td>\n1 – 8 GB<\/span><\/td>\n | 128byte – 512Kbyte<\/span><\/td>\n<\/tr>\n\nROM<\/strong><\/span><\/td>\nfew MBs<\/span><\/td>\n | 4 – 46Kbyte<\/span><\/td>\n<\/tr>\n\nClock Rate<\/strong><\/span><\/td>\n1 – 4GHz<\/span><\/td>\n | 32KHz – 20MHz<\/span><\/td>\n<\/tr>\n\nCPU Cores<\/strong><\/span><\/td>\nup to 16<\/span><\/td>\n | 1<\/span><\/td>\n<\/tr>\n\nSerial Ports<\/strong><\/span><\/td>\nUSB, RS422 & RS232<\/span><\/td>\n | UART, SPI, I2C & USB<\/span><\/td>\n<\/tr>\n\nCurrent Drain<\/strong><\/span><\/td>\n1.5Amps<\/span><\/td>\n | 50mA<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n\nNote<\/span><\/strong><\/td>\n<\/td>\n | <\/td>\n | <\/td>\n<\/tr>\n | \n\n A microcontroller is not the same as a microprocessor. A microprocessor is a single-chip CPU used within other computer systems. While a microcontroller is itself a single-chip full computer system!<\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\nWe use microcontrollers extensively in embedded systems design. You can spot its existence in a tremendous number of applications and devices around you. A microcontroller can possibly show a higher efficiency and performance in some sort of applications than any computer we use.<\/span><\/p>\nWhen it comes to low-end devices and minimal power utilization, there is nothing comparable with microcontrollers. It drains a few milli-amperes that will result in a substantial increase in the device’s battery life!<\/span><\/p>\n \n\u00a0 \u00a0Variants Of Microcontrollers\u00a0 \u00a0<\/span><\/strong><\/span><\/h3>\n <\/p>\n Microcontrollers can be categorized in many different ways depending on numerous metrics. They could be categorized based on their memory architecture, bus width, CPU architecture, manufacturer and so on. Here I will list down some of these categories and finally will tell you which MCU chips we’ll be using in these tutorials and why.<\/span><\/p>\n\u00a0 Bus Width\u00a0\u00a0<\/span><\/h4>\nThe bus width (number of wires) determines the capability of the computer to handle data words of a specific length. An X-Bits microcontroller can manipulate data up to X bits in size. However, there are many MCUs that have a full instruction set that handles 8-Bit data alongside with a few ones for handling 16-Bit words. In this case, it should be called an 8-Bit machine! A specific microcontroller is considered as an X-Bit Computer if it has an instruction set that most of its instructions are designed to manipulate data words of X-Bits size.<\/span><\/p>\nThe 8-Bit microcontrollers are the most common with highest shipping volume in the market. However, there are 16-Bit and 32-Bits microcontrollers that are used for high-performance applications that require excessive computational power. In conclusion, the microcontrollers’ market standards in bus widths are the 3 ones listed down below.<\/span><\/p>\n\n\n\n8-Bit\u00a0\u00b5Cs<\/strong><\/span><\/td>\n16-Bit\u00a0\u00b5Cs<\/strong><\/span><\/td>\n32-Bit\u00a0\u00b5Cs<\/strong><\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\u00a0 Memory Type\u00a0\u00a0<\/span><\/h4>\nMicrocontrollers’ memory may be embedded within the chip itself or the chip could be designed to operate using an external memory hooked to the\u00a0\u00b5C chip externally.<\/span><\/p>\n\n\n\nInternal Memory MCUs<\/strong><\/span><\/td>\nExternal Memory MCUs<\/strong><\/span><\/td>\n<\/tr>\n\nThese devices are designed with all needed RAM and ROM memories built-in. There is no need for any external connections for memory.<\/span><\/p>\n This represents the majority of the MCUs being manufactured nowadays.<\/span><\/td>\n | In the past, some chips had no program memory built-in and they had to connect it externally. That’s what happened with Intel’s 4004 MPUs back in the late 60’s.<\/span><\/p>\n This type of MCUs had to disappear with the emergence of internal memory designs only 5 years later back in 1975.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\u00a0 Instruction Set\u00a0\u00a0<\/span><\/h4>\nEvery single microprocessor has its own instruction set which defines the basic function it only can handles. Some sophisticated functions could be achieved using the basic instructions available in the instruction set of a microprocessor. Here is an example of a set of assembly instructions that could be found in any device out there.<\/span><\/p>\n\n\n\nInstruction Name<\/strong><\/span><\/td>\nThe Function It Performs<\/strong><\/span><\/td>\n<\/tr>\n\n | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |