Lecture notes on Embedded Systems

how to design embedded systems and how embedded systems work. how to learn embedded systems programming pdf free download
NathanBenett Profile Pic
NathanBenett,Germany,Researcher
Published Date:11-07-2017
Your Website URL(Optional)
Comment
An Introduction to Embedded Systems - Spring 2014 1 Lecture Notes By Jacob Christ An Introduction to Embedded Systems A cross platform approach using the Wiring open-source programming paradigm with practical examples utilizing MPIDE with chipKIT and Arduino hardware. By: Jacob Christ C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 2 Lecture Notes By Jacob Christ Lecture 1 – Embedded Development Tools and Overview Class Goals / Accessing Prior Knowledge This material was developed over several years for a second year Electronics Class at Mt. San Antonio College (affectionately known as Mt. SAC) in Walnut California. The class as listed in the course catalog at the college is such that there are no collegiate prerequisite. Being as such, any student should be able to walk into this class and be able to navigate through the material presented and increase their understanding on of the subject matter. There is a caveat though, nearly every student that comes through the class has at least a year of basic electronics under their belt. In the class if a student doesn't have the prerequisite electronics experience needed for specific understanding the instructor and fellow students can bring them up to speed quickly. Additionally the mastery that can be achieved by studying this material is greatly affected by an individual's prior knowledge before entering the class. This creates a rift between the highest achievers in the class and the lowest achievers and a clear demarcation between the two groups is that the students at the top of the rung have had prior experience writing computer software (in no specific language). Some assumptions are made on my part based on my observation of the state of the common knowledge of the world today. Here is a list of things I suspect you probably know. This list is given so that if there is something you haven't seen or don't understand you can get yourself up to speed quickly so as to not feel overwhelmed by the class. Prior Electronics Experience Almost every student that enters this class has taken classes in DC (ELEC 50A at Mt.SAC) AC (ELEC 50B at Mt.SAC) and Digital Electronics (ELEC 56 at Mt.SAC). Depending on the given year, about 25-50% of the students will have taken a class on electronic devices (ELEC 51 at Mt.SAC). The devices classes covers diodes, rectifiers, regulators, power supply design, transistor and op amp circuits. A few will have taken microwave communications or industrial electronics classes. Again, none of these classes are necessary, but knowing the subject matter frees your mind to think about new concepts rather than having to learn the above necessary material in a compressed time with the topics of this class. Prior Math Experience Most (if not all) prior students have taken algebra but it drops off rapidly as we move from algebra to geometry to intermediate algebra to college algebra to trigonometry to pre-calculus and finally to calculus. Class have had as few as one student that has had calculus and other times more than half the class has had calculus experience. This class uses some concepts from arithmetic and algebra. In lectures I will share some calculus concepts with the class but they should be refreshingly easy for C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 3 Lecture Notes By Jacob Christ anyone with less than a calculus background, in fact the student would probably not even know its calculus if not pointed out. Prior Computer I suspect that everyone reading this material will have at least seen and used a computer sometime in their life. The skill levels are varied among students, but the following are necessary skills that if you are week in you should seek immediate help. Navigating the file system with a GUI tool (such as Explorer) Changing Directories Moving Files Copying Files Deleting Files Internet Using a web browser Sending and Receiving e-mail with file attachments Downloading files from the internet Running (Launching) Programs Installing Programs C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 4 Lecture Notes By Jacob Christ What are we in for? The following is an incomplete list of projects that are in the same vein of what this course is all about. Let's take a look at some videos to get inspiration: RC Servo Control: http://www.youtube.com/watch?v=q2GlwfWwr3w Stepper Motor Control: http://www.youtube.com/watch?v=09ckLqR05zA Stepper Motor Control: http://www.youtube.com/watch?v=wypy1KdI5a8 Super Chase: http://www.youtube.com/watch?v=kiaJECGEtAM Light Cube: http://www.youtube.com/watch?NR=1&v=GUcX41pokZY&feature=endscreen If the light cube intrigues you, then it might be worth noting here that by then end of the second lab you will understand the electronics to complete this project and the astute student will understand this by then end of lab one. Function Generator: http://www.youtube.com/watch?v=gz_gVKWFN8E Bike Computer: http://www.youtube.com/watch?v=O5YYsm_BqJQ LED Clock: http://www.youtube.com/watch?v=q4RwP0UK8gM&feature=endscreen&NR=1 MakerBot: http://www.youtube.com/watch?v=zkppg84hxZg&list=PL16315F3CB6CF8637&index=2 CNC Machine: http://www.youtube.com/watch?v=SzFpiU6OSTQ Spider Robot: http://www.youtube.com/watch?v=7L7oxoZEG-A Arc Reactor: http://www.youtube.com/watch?v=W_Jsu_E0go0 Music Visualizer: http://www.youtube.com/watch?v=___XwMbhV4k Drum Machine: http://www.youtube.com/watch?v=chEg6mAfaNA Sound Generation: http://www.youtube.com/watch?v=nY1eQk3ezjM These videos are for inspiration. In this class we will learn some fundamentals required to build these types of projects but may not actually build anything like these. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 5 Lecture Notes By Jacob Christ Overview of an Embedded System From wikipedia: http://en.wikipedia.org/wiki/Embedded_system An embedded system is a computer system designed for specific control functions within a larger system, often with real-time computing constraints.12 It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs. Embedded systems control many devices in common use today.3 Embedded systems contain processing cores that are either microcontrollers or digital signal processors (DSP).4 A processor is an important unit in the embedded system hardware. It is the heart of the embedded system.5 The key characteristic, however, is being dedicated to handle a particular task. Since the embedded system is dedicated to specific tasks, design engineers can optimize it to reduce the size and cost of the product and increase the reliability and performance. Some embedded systems are mass-produced, benefiting from economies of scale. Physically, embedded systems range from portable devices such as digital watches and MP3 players, to large stationary installations like traffic lights, factory controllers. Complexity varies from low, with a single microcontroller chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or enclosure. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 6 Lecture Notes By Jacob Christ Introduction to Microcontrollers A microcontroller is a monolithic device that contains a CPU (Central Processing Unit), nonvolatile memory (such as flash), volatile memory (such as SRAM) and a variety of peripherals devices. They can be as small or smaller than 5 pin SOT-23 devices and as large or larger than 144 pin BGA and TQFP parts. The reason for choosing to use a microcontroller for a design would be to gain the advantages of a reprogrammable digital circuit in a form factor suited for a specific application when a general purpose computing device is not able to complete the task. Abuse of terminology (CPU acronym) CPU is an acronym for Central Processing Unit and is often used to refer to a computer system, such as “That beige box sitting next to my 24” flat screen monitor is my new CPU.” The “beige box” being referred to in the aforementioned statement is a computer system and not a CPU, the CPU is the chip inside the computer system known specifically as the microprocessor. As technology advances and C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 7 Lecture Notes By Jacob Christ desktop computer become rarer as laptop and tablets take over this abuse of terminology seems to be decreasing. CPU Abstraction as a Microprocessor Prior to the invention of the microprocessor in 1971 by Intel (the 4004) CPU’s were circuits consisting of many chips to make up the function of a programmable information processing and manipulation device. http://www.intel.com/about/companyinfo/museum/exhibits/4004/index.htm Computer System Abstraction as a Microcontroller A microcontroller is a monolithic device that contains a Monolithic Device microprocessor and all the peripherals necessary to make a complete system on a chip. Microcontrollers make building a mono = one, lithic = stone complete system a simple task by adding only a few The term monolithic device refers to additional components to bring a design to fruition. the entire part being built out of a Microprocessor single silicone chip. The implications Information processing unit of the chip often referred to as are such that the manufacturing the CPU. The CPU reads the stored program in program process is simpler. Simplicity implies memory, interprets the instructions that are primarily used reliability (single failure point) and to direct the flow of information into and out of data affordability (single part to purchase). memory and into and out of peripherals. Additionally, program flow control is handled by the microprocessor. In desktop and laptop computers, the microprocessor is typically a standalone chip and all the additional features that make up a microcontroller are relegated to other chips that typically sit on the mother board. The ability to put different technologies onto a single chip is blurring what traditional computer architecture and an embedded architecture look like. Some computers on a chip have existed for quite some time that allow for incredible size reduction of computers allowing the creation of palm top computers. Program Memory Program memory is a non-volatile memory used to hold the application or operating system program for the embedded device. Non-volatile refers to the ability for the memory to retain its value without power applied to the chip. The program stored in the non-volatile memory of a microcontroller program memory is often referred to as firmware as opposed to software that would be loaded off of a hard drive on a PC. Examples of types of non-volatile memory are: C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 8 Lecture Notes By Jacob Christ ROM Read Only Memory, programmed at the factory and not erasable PROM or OTP Programmable Read Only Memory or One Time Programmable memory that cannot be erased once programmed EPROM Erasable Programmable Read Only Memory EEPROM Electronically (byte) Erasable Programmable Read Only Memory Flash Memory Electronically (bank) Erasable Programmable Read Only Memory Data Memory Data memory is volatile memory used to hold program data while the program is running. Volatile memory will not retain its values without power applied. Volatile memory is often called RAM or RWM RAM (Random Access Memory) or RWM (Read Write Memory). The term RAM is quite popular but doesn’t quite tell the whole story since ROM type memory is also random accessible. The better term is RWM since the memory can be altered on the fly while a program is running without special considerations that are necessary to erase a ROM chip. There are at least two common types of RWM; Static and Dynamic. Static RWM is built out of transistors and is very fast and priced accordingly. Dynamic ram is built out of capacitors and is not as fast at static RWM but can be built much denser and at a lower cost. Also the nature of storing values as charges in a capacitor has the added complexity of requiring a dynamic ram controller to keep the correct values refreshed while the memory is not in use. Microcontrollers’ internal data memory is typical static RWM. Dynamic RWM is most commonly used as the main memory of a PC. Side note, the cache of a PC microprocessor is made of static RWM and is on the microprocessor, but this was not always the case. Cache memory of older PC’s was external from the microprocessor. Other Non-Volatile Storage In addition to program and data memory, some microcontrollers have additional non-volatile storage that can be used to store program data that survives power outages. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 9 Lecture Notes By Jacob Christ Peripherals The peripherals of the microcontroller are what really differentiate a microcontroller from a microprocessor. The peripherals are used for the control and sensing of many things on a single chip. Listed below are some common peripherals that can be found on a microcontroller. Do not be discouraged if you do not recognize all, or for that matter any, of the peripherals for that is the purpose of this text. however the list is by no means complete. Parallel Ports Serial Ports UART SPI I2C USB Timers / Counters / PWM Analog Circuitry ADC’s Comparators What can a microcontroller do? What are the limits of your imagination? Advanced Understanding: The Church-Turing Thesis In the 1936's Alan Turing and Alonzo Church independently postulated that not all numbers can be computed. Church using what he called lambda calculus and Turing using a machine (later called a Turing Machine by Church). Turing went further saying that any number that is computable can be computed by his machine. Further, any machine that can emulate a Turing Machine can compute any number that is computable. Microprocessors, and therefore microcontrollers, can emulate Turing Machines and therefore, based on the Church-Turing Thesis, can calculate any number that is computable. There are caveats, such as the limit of the memory connected to the computer limits what is computable. Also, the thesis speaks nothing about the speed of the computation which is dependent on many things (processor speed, architecture of the computers, number of processors and efficiency of algorithm used). Although the thesis states that a Turing Machine can compute any number that is computable it is important to point out that not all numbers are computable. Incomputable numbers cannot be determined with a Turing Machine. There are several things that you should take away from this. The ability to solve a problem (in computation) is not limited by any device that can emulate a turning machine. The embedded computers we use in this class can solve any probablem that any computer can solve. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 10 Lecture Notes By Jacob Christ The PIC32MX440F256H microcontroller The PIC32MX440F256H is an 32-bit PIC microcontroller. The speed of the CPU is 80MHz which roughly translates into 80 million instructions per second (MIPS). It has 32K Kilobytes of RAM and 256 Kilobytes of flash memory. An internal EEPROM: 1024KB. Programmable External Interrupts Input Change Interrupts Capture/Compare/PWM (CCP) modules Master Synchronous Serial Port (MSSP) module ((SPI and I2C) Enhanced Addressable USART module 10-bit Analog Digital Converter Watchdog Timer Brown-out Reset (For details, please check the PIC32 datasheets from www.microchip.com) Microprocessor / Microcontroller Terminology Here are some terms and definitions that might help you when reading other material related to microcontroller technology. CISC - A complex instruction set computer (CISC, pronounced like "sisk") is a microprocessor instruction set architecture (ISA) in which each instruction can execute several low-level operations, such as a load from memory, an arithmetic operation, and a memory store, all in a single instruction. The term was retroactively coined in contrast to reduced instruction set computer (RISC). RISC - The acronym RISC (pronounced risk), for reduced instruction set computing, represents a CPU design strategy emphasizing the insight that simplified instructions which "do less" may still provide for higher performance if this simplicity can be utilized to make instructions execute very quickly. Many proposals for a "precise" definition have been attempted; however, the term is being slowly replaced by the more descriptive load-store architecture (see below). Well known RISC families include Alpha, ARC, ARM, AVR, MIPS, PA-RISC, PIC, Power Architecture (including PowerPC), SuperH, and SPARC. Harvard Architecture – computer architecture with physically separate storage and signal pathways for instructions and data. The Von Neumann Architecture - a processing unit and a single separate storage structure to hold both instructions and data. Phase Lock Loop (PLL) - use as a Frequency Multiplier. For users who wish to use a lower frequency oscillator circuit or to clock the device up to its highest rated frequency from a crystal oscillator. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 11 Lecture Notes By Jacob Christ The Tool Chain What is MPIDE? MPIDE is an acronym for Multi Platform Integrated Development Environment. In a mouthful MPIDE is an cross platform IDE with multiple cross compliers that support multiple targets, whew The technical process (as opposed to the creative process) of creating a program that runs on embedded hardware is as follows: 1. Enter source code in a text editor. 2. Compile source code into object code. 3. Link object code together into executable machine code. 4. Upload machine code to the target platform. 5. Test machine code in target application. MPIDE utilizes gcc open source C++ cross compilers that have similar functionality that you would find in a C++ compiler for writing applications for a PC but utilizes libraries specifically written for embedded hardware. Programming is done utilizing the C++ language but automatically included libraries allow a beginner to ignore (at least in the beginning) the complexity associated with C++ so that they can dive in and get started creating fast. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 12 Lecture Notes By Jacob Christ Concepts in C Programming Comments Good programs will contain comments as necessary to make the code easier to interpret. It is important for other programmers to understand the logic to make modifications to your code, but also for yourself. You may have discovered in your past programming experience that if you go back to make changes to a program that you've written a while back. It may be hard to follow quickly some of the steps in the code. A comment line can be included in C by bracketing all information that you don't want the compiler to translate with slashes and asterisks. Comments / / / Anything between the slash-star star-slash characters is a comment and ignored by the compiler / Comments // // Anything after the slash-slash is a comment until // the end of the line. Comments are ignored by the compiler Brackets (or Braces) Braces mark the beginning and end of a section of code. All code in-between the braces can be taken as at the same level of execution. Braces are often nested within “higher level” braces and these nested braces are used to group a section of code associated with a loop or a decision making code. The concept of braces and how they work will become more clear as the class progress and you see more code examples. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 13 Lecture Notes By Jacob Christ Week 2 – Number Systems, Output and Introduction to C Links Exponent Review http://www.youtube.com/watch?v=joKpSP_-QFs Number Systems http://www.youtube.com/watch?v=NIvZx2zsF1A Conversion Between Number Systems http://www.youtube.com/watch?v=fX61osaZa5w Class Goals (Lecture Name: Bits, Bytes and Data Types) (Functions and Loops) This lecture should be about half review from digital, and half new Counting and Number Systems Review of Exponents Let’s say you’re a mathematician and you spend your days multiplying numbers together, but not any number, you have this particular obsession of multiplying the same number to itself over and over such as 10 10 10 = 1,000 or 10 10 10 10 = 10,000. After awhile of doing this you get tired of writing the same numbers over and over and because you’re a good mathematician (which means your lazy and creative) you come up with a scheme so that you don’t have to write so much. If you multiplying three tens together you decide to just write ten once then raise the number of times you want to multiply ten together in the upper right hand corner of the ten. You ponder this a bit you decide that this system will be really powerful and playing on the this you 3 decide to say that 10 10 10 becomes 10 (ten to the power of three). These are equivalent, and again were lazy so rather than writing equivalent we just write: 3 10 10 10 = 10 After awhile of playing around with this notation we decide we can generalize it in the following way: n b = b b b … b 1 2 3 n And because we love math so much and we want to talk about our new notation with our math friends n we come up with clever names and decide that in b that b will be called the base and n will be called the exponent. So we continue playing with our exponents and bases and find a sticky situation comes up… What if our exponent is zero??? Well if our base is zero this is easy because we know zero times anything is zero: 3 0 = 0 0 0 = 0 C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 14 Lecture Notes By Jacob Christ 0 But what about 10 ? Well this is zero 10’s but should we say this is zero? What if we do the following? 3 0 10 10 ? Isn’t this just three tens multiplied by zero tens? 10 10 10 (and zero more tens?) 0 0 If we decide that 10 is zero then 10 10 10 0 is 0 not 100. It would probably be better to say 10 is n m (n+m) 1 then 10 10 10 1 is 100. And indeed there is a rule that goes something like b b is b . 0 0 And we generalize that b is one where b is any number… Then what about 0 ? Should this be one? Zero times anything is zero??? We’ll leave this as an open questions since its is beyond the scope of this class. Exponents are essentially a short hand notation for multiplying the same number together over and over in succession and you should not be intimidated by them. Counting in Decimal Powers of 10 2 1 0 123 = 100 + 20 + 3 = 1 100 + 2 10 + 3 1 = 1 10 + 2 10 + 3 10 Bits, Bytes and Nibbles Review of a bit Binary digit, has one of two possible values: 0 or 1 Review of a byte 1 byte is 8 bits written out left to right MSB (Most Significant Bit) to LSB (Lease Significant Bit). Example 1001 0001 (base 2) = 145 (base 10) Nibbles (no joke) 1 nibble is 4 bits 1 byte is 2 nibbles, usually referred to as the high nibble and the low nibble. When writing binary numbers, as above, a space is usually placed between nibbles to make the number easier to read by a human. Counting in Binary How many values (not how high can we count) with one bit? Two, 0 or 1. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 15 Lecture Notes By Jacob Christ How many values (not high can we count) with two bits? 1: 0 0 2: 0 1 3: 1 0 4: 1 1 Two values for bit 1 and two values for bit 2. This can be calculated in the following manner: digits This can be generalize as base . The base is the base of the number system, in this case 2 and digits is the number of digits we have. 2 2 = 2 2 = 4 How many values (not high can we count) with eight bits? 8 2 = 2 2 2 2 2 2 2 2 = 256 Hexadecimal (Hex for short) Hexadecimal is the combination of the two words hex (meaning six) and decimal (meaning ten). 6 + 10 = 16 So in hex we have sixteen digits. Count In Hex In hex there are sixteen hexadecimal digits. We borrow the ten decimal digits we need six symbols to represent all sixteen hex values. We use the first six characters from the alphabet for this: A, B, C, D, E and F. Recall when you count in decimal you start at zero and advance to nine using all ten digits before using another column, so a count sequence would look like this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12… The same is true in hexadecimal. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 11, 12… Hex digit / nibble equivalency Recall a nibble is four bits and that four bits can represent sixteen unique values and since a single hex digit can be one of sixteen unique values then a hex digit is a nibble. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 16 Lecture Notes By Jacob Christ Summary of Counting Decimal Hexadecimal Binary Octal (base 10) (base 16) (base 2) (base 8) 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 2 2 0 0 0 1 0 2 3 3 0 0 0 1 1 3 4 4 0 0 1 0 0 4 5 5 0 0 1 0 1 5 6 6 0 0 1 1 0 6 7 7 0 0 1 1 1 7 8 8 0 1 0 0 0 10 9 9 0 1 0 0 1 11 10 A 0 1 0 1 0 12 11 B 0 1 0 1 1 13 12 C 0 1 1 0 0 14 13 D 0 1 1 0 1 15 14 E 0 1 1 1 0 16 15 F 0 1 1 1 1 17 16 10 1 0 0 0 0 20 I/O PORTS Our First Program (Blink) Below is the typical blink example that ships with MPIDE. This program is pretty close to the simplest useful program that will run using the Wiring programming abstraction. The program when run will blink an LED attached to the development board at a rate of 0.5 Hz (one second on and one second off). If we analyze the code we can see it does one other very important thing, in the setup() it sets the pin attached to the LED to an output using the pinMode(). Most pins on a microcontroller have more than one function and almost every pin can be configured as digital input or digital output. This program was originally written for the Arduino Uno and we make this assumption based on PIN 13 being used. On the Arduino Uno (and the chipKIT Uno32) PIN 13 is connected to an LED mounted on the development board. void setup() // initialize the digital pin as an output. // An LED connected on most Arduino boards: pinMode(PIN_LED1, OUTPUT); void loop() digitalWrite(PIN_LED1, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(PIN_LED1, LOW); // set the LED off delay(1000); // wait for a second C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 17 Lecture Notes By Jacob Christ Review from Digital To understand the electronics behind the ability of the I/O pin on a microcontroller to be reprogrammable we first need to review some topics from digital electronic class. The 7400 series of TTL ICs contain AND gates, OR gates, NOT gates, etc. The inputs and output functionality of most of these device pins are fixed (as opposed to microcontrollers in which most of the pins can be programmed to be either digital input or digital output on the fly). D Flip Flops (review from Digital) The D flip flop is a very simple one bit memory circuit that remembers the bit value when upon a clock transition. CLK D Q Q' D Q Non-Rising X Qprev Q'prev 0 0 1 CLK Q' 1 1 0 Buffers (Newish) A buffer is simply a device that re-amplifies a signal and in the case of a digital buffer you get out the same logic level you put in. This circuit provides no enhanced ability to manipulate information, but gives us the ability to transmit a signal over a longer distance or to drive a larger number of inputs than would be possible with a single output. A X A X 0 0 1 1 Tri-State Buffers (New) Tri-state buffers have two inputs and a single output that can be in one of three states: High, Low or Hi-Z (high-Impedance). When the gate is in Hi-Z the gate is acting as if the output has been removed from the circuit. In reality it is still connected, but the drain on the rest of the circuit is so low that it can be neglected in simple cases. B A C 0 X Hi-Z 1 0 0 1 1 1 C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 18 Lecture Notes By Jacob Christ I/O Pin Schematic of a Microcontroller The input output functionality of the microcontroller is achieved by a clever arrangement of logic gates, flip flops and tri-state buffers. Shown below is a simplified diagram for a single bit of a microcontroller I/O port. The DATA BUS is a bi-directional signal buss where data travels to and from the microprocessor sub module of the microcontroller. The data bus connects to one of five locations within the I/O pin control circuit, two are inputs and the other three are outputs. The inputs are the D inputs to the OUT and DIR latches. The three outputs allow reading back the two latches and reading the raw digital value off of the I/O pin itself. Data Direction Register (pinMode) When the pinMode command is issued this causes a value to be written to the DIR latch that chooses if the I/O pin is going to be input or output. In the above diagram a logic 0 on the Q output of the DIR latch causes the port to become an output port, where a logic 1 on the Q output of the DIR latch disconnects the OUT latch from the I/O PIN allowing it to drive the input buffer that goes to the PIN FLIP FLOP. The state of the OUT latch can be read by using the getPinMode() command. I/O Register (digitalWrite / digitalRead) As seen in the blink sketch example from above, once the pinMode() for a specific pin has been set the output state of the pin can be set using the digitalWrite(). Equivalently, if we the pinMod() set the I/O pin to be an input then the digialRead() can be used to read the logic state of the pin. Questions Is the value of a port volatile or non-volatile? Concepts in C Programming The nature of this class In this class we are writing programs. An example of a programs are a word processor or spreadsheet or a web browser. Programs are instructions to make a computer do useful things. Useful has a very broad definition. A web browser lets you browse web pages on the internet and dose many other things. In the first few labs of this class we have written programs to flash LED’s. Flashing an LED is a useful task, it may not seem very useful but have you ever seen an LED flash itself? In this class we will be using the C/C++ programming language to write our useful programs. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 19 Lecture Notes By Jacob Christ Some History Developed by K & R at AT&T Bell Labs for the purpose of developing operating systems. Designed to be a low level language (close to assembly) to harness the power of the machine but simplify the job of programming. (needs source) The syntax used in C/C++ as well as other comes from this lineage of programming languages. Alog60 …. BCPL - B - C - C++, Objective C, Java C Main Function C is a functional language and the first function that gets called is main(). As used with the Wiring / Arduino / chipKIT paradigm the main() function is hidden from the developer and instead replaced with a setup() and a loop(). The setup() is called once at program start and the loop() function is called over and over as long as the device is powered. Keywords or Reserved Words Definition: List of words reserved by the language (C in our case) that have a predefined meaning. auto d entry return void d break enum d short d volatile d case extern d signed d while char d float d sizeof const d for static d continue goto struct default if switch do int d typedef d double d long d union d else register d unsigned d C Reserved Words Variables and Data Types Variables symbols that represent the memory of the computer. An example of a variable definition is: int a; // define a variable called a that is of type int When a variable is defined a constraint is placed upon the variable as to the type of value that can be represented by the variable. In the above example the type is 'int' which means a signed integer value. By signed we mean that is can be either a value that is positive, negative or zero. Besides being signed an integer value could also be unsigned meaning that is can only represent zero and positive values. For review, an integer, is a whole number. That is to say is can be 1 or 2, but now 1.5 or 1 and 1/2. Another type of numerical value is a float which can represent fractional values such as 1.5 or 3.14159. The data type is important does a couple of things for us. It tells the complier how much memory to reserve for the variable being defined. It also allows the compiler to do sanity check such that we do not try to assign a floating point value to an integer value or something much worse. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ An Introduction to Embedded Systems - Spring 2014 20 Lecture Notes By Jacob Christ A question that you should be asking right now is why are there so many different data types to represents a numerical value. The answer is probably most likely originates in the fact that early computer systems had very little memory so to represent a small number such as 15 you would need less memory than would be needed to represent a large number such as 128.25651210242048. Indeed when we are developing with small microcontrollers memory too again is an issue we may be working with kilobytes of RAM compared to gigabytes in a modern computer. For this reason it is important to choose a data type that will hold the largest and smallest number you want to represent but not one larger to consume precious memory. Summary C Language mtsac Bits Min Max bit us1 1 0 1 7 7 signed char s8 8 -128 (-2 ) 127 (2 -1) 8 char us8 8 0 255 (2 -1) 15 15 int s16 16 -32768 (-2 ) 32767 (2 ) 16 unsigned int us16 16 0 65535 (2 -1) 31 31 long s32 32 2,147,483,648 (-2 ) 2,147,483,647 (2 -1) 32 unsigned us32 32 0 4,294,967,295 (2 -1) long 63 63 long long s64 64 9,223,372,036,854,775,808 (-2 ) 9,223,372,036,854,775,807 (2 -1) 64 unsigned us64 64 0 18,446,744,073,709,551,615 (2 -1) long long How to Represent (Some) literals in C Bits 0 or 1 for single bit 0b00001111 as a byte Decimal Numbers 0 to 255 for an unsigned byte Hexadecimal Numbers 0x00, 0xa5 (or 0xA5) or 0xFF Octal Numbers (noted only as a warning) 0777 is not 777 Assignment a = b + 1; Value to the left of = symbol is called lvalue and must be a variable. Values to the right of the = symbol can be variable, constants or literals. C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipKIT\An Introduction to Embedded Systems Using the Wiring Paradigm - Lecture Notes.doc© Copyright 2015 Jacob Christ

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.