941 likes | 1.1k Views
Introduction to Microcontrollers. And all that whirrs, clicks, and beeps. Instructors. Ms. Hinterlong Lucas Sturnfield Brian Baker Thomas Houlahan. Sponsors. Houlahan’s Tavern and Grill. Programming Languages. .NET, Java, C++, Python…? Assembly?. what Micros can do. Electronics.
E N D
Introduction to Microcontrollers And all that whirrs, clicks, and beeps
Instructors • Ms. Hinterlong • Lucas Sturnfield • Brian Baker • Thomas Houlahan
Sponsors • Houlahan’s Tavern and Grill
Programming Languages • .NET, Java, C++, Python…? Assembly?
Electronics • Electron juggling and shuffling • (some kinds of shuffling are more impressive than others)
Outline • Today • Basic electronics • Digital electronics • Tuesday • Programming a microcontroller • Start projects • Wednesday • Projects • Thursday • Projects • Friday • Projects and presentations
Circuit Diagrams http://www.fancon.cz/slave-flash-trigger/slave-flash-en.html
Wire and Elements Some elements Elements wired together
Voltage and Current • Voltage • Potential energy per unit charge • Measured in Volts = Joules per Coulomb • Water analog: pressure • Measured between nodes
Voltage and Current • Current • Flow of electrons • Measured in Amperes (Amps) = Coulombs per Second • Water analog: flow rate • Measured through an branch (through an element)
Ohm’s Law: V = I * R • Voltage across the element = Va – Vb • Resistor has resistance R1, measured in Ohms • Current through resistor is i_R1 • Va-Vb = R1 * i_R1
Power: P = V * I • Power used by any branch is equal to the voltage across the branch multiplied by the current through that branch • Units: Joules / Coulomb * Coulomb / Second = Joules / Second = Watts
KVL and KCL • Kirchoff’s Voltage Law • The sum of voltages around any loop equals zero
KVL and KCL • Define a ground node to be zero volts • Now, each node has a voltage
KVL and KCL • Kirchoff’s Current Law • The sum of currents entering a node equals zero • (a lot like mass conservation)
Breadboards • Internal connections • Power rails
Multimeters – Measuring Voltage • Multimeter must connect to circuit differently to measure voltage or current • To measure voltage, set multimeter to Voltage setting, and place leads in parallel with branch of interest
Multimeters – Measuring Current • To measure current, set multimeter to Current setting, and place leads in series with branch of interest
Diodes and LEDs • Water analog: Check valve – only lets current flow one way • Either ON or OFF • On • Anode-cathod voltage is fixed value, no matter what current (0.7 V) • Off • Current is zero, no matter what voltage • LEDs emit light when ON
Recap • Voltage is potential energy (pressure) • Current is flow of electrons (flow rate) • Voltage is measured between nodes, or with respect to ground • Current is measured through branches • V=IR • P=IV
Voltage isn’t always Constant • Speakers are driven by a voltage signal; settings the voltage sets the position of the speaker diaphragm
Sensors and analog out • Some sensors vary an output voltage; the voltage corresponds to a sensor value • Maxbotix ultrasonic sensor outputs voltage corresponding to distance
RF - radio • Radio uses Electromagnetic waves • Voltage on antenna varies • Waveform carries data
Power: DC vs AC DC AC • Direct Current • Batteries, wall warts • Time-constant voltage • Current flows one way • Alternating Current • Electrical outlets • Time-varying voltage • Current flows different ways at different times • Transfers power great distances with low line loss
AC to DC http://hyperphysics.phy-astr.gsu.edu LM7805 Volage regulator - takes ~9V DC, makes 5V DC
Capacitor • Stores energy • Resists change in voltage • Electrolytic are polarized, have stripe on minus end • Capacitance is measured in Farads (typically, micro Farads) Electrolytic capacitor Ceramic capacitor
Transistor • Considered by many to be greatest invention of the 20th century • Transistor as amplifier (radio) • Transistor as switch
Digital Electronics 0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100 (hello world)
1 and 0 • Digital logic doesn’t use analog voltages – only ‘high’ and ‘low’ have meaning • Typically 5V and 0V • Sometimes 3.3V and 0V • Computer processor • High is 1, Low is 0
Microcontroller • Programmable Chip • Same idea as PC, but on much smaller scale
Black Box • Black box does stuff to inputs to get outputs • Typically don’t want to care what happens inside black box; just need to know how to give it input, and what output to expect
Black Box • Need to know where to put toast • Need to know to be careful getting toast; it’s hot • Need to know that ‘ding’ means toast is done • Ding is an output! • Power, timer setting, lever are all inputs
Computer vs Microcontroller Computer Microcontroller • Inputs • Keyboard • Mouse • Microphone • Outputs • Monitor • Speakers • Black box • Program is written on the computer • Inputs • Voltage on pins • Outputs • Voltage on pins • Black box • Program is written on a computer and downloaded to the chip
Why Microcontrollers? • Low cost for a lot of processing • Low power (can run on batteries) • If power is well managed, can run for years on a 9V! • Small • Can communicate with PCs to do complex processing with real world effects
Blinky LED in a Breadboard • Breadboard stuff • PICS are already programmed • Remember: Electrolytic caps are polarized; stripe goes to lower voltage • When you apply power, LED should blink
PCB • Haha! jk jk we have awesome pcb. • Let’s solder: • Soldering irons get HOT: don’t burn yourself • Tinning things: put a little solder on both pieces that you’ll connect, THEN connect them • Sockets are done you get to do caps and 7805 • With sockets, we don’t apply heat to a chip. Also, if the chip gets fried, we can pull it and put a new one in • Test with Blinky LED again
Programming a PIC Making machines Think
Architecture • Memory • Variables – ‘registers’ – all 1 byte big • F register • Declare you own • Special ones, like PORTD and TRISB • Working register – the accumulator – your ‘hands’ • Instructions • Processor only does ONE thing at time – moves from one instruction to the next • Each instruction has an opcode (action) and parameters • i.e., movfw PORTA
Comments prefixed with semilcolons Compiler info Config bits Constants Variables – declared two different ways Config & Variables
ORG declares a place in code memory 0x000 is restart 0x004 is interrupt (ignore interrupt for now) Now every line is a comment, label, or instruction nop – do nothing goto [label] – jumps to a named label Beginning of Code
bcf and bsf – bit modification Special f registers and bank bits Moving through accumulator PORT and TRIS control pins ADCON1 and analog Initialization