Embedded Programming Keeping Time Serial Data and PWM Signals A/D Conversion Data Formats and Constructs Interrupts MAE 156A Ardunio UNO Development Board.

Slides:



Advertisements
Similar presentations
INPUT-OUTPUT ORGANIZATION
Advertisements

EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Review: Interrupts & Timers
5/4/2006BAE Analog to Digital (A/D) Conversion An overview of A/D techniques.
Railway Foundation Electronic, Electrical and Processor Engineering.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
1 ECE 263 Embedded System Design Lessons 2, 3 68HC12 Hardware Overview, Subsystems, and memory System.
Railway Foundation Electronic, Electrical and Processor Engineering.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
BLDC MOTOR SPEED CONTROL USING EMBEDDED PROCESSOR
Engineering 1040: Mechanisms & Electric Circuits Fall 2011 Introduction to Embedded Systems.
Timers and Interrupts Shivendu Bhushan Sonu Agarwal.
INPUT-OUTPUT ORGANIZATION
Input/Output mechanisms
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
The Basic Stamp Instruction Set Architecture. The Microprocessor A microprocessor is a computer that typically has an architecture that is well suited.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This course provides an overview of the CPU architecture.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
Universal Asynchronous Receiver/Transmitter (UART)
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
CCP MODULES  The CCP module (Capture/Compare/PWM) is a peripheral which allows the user to time and control different events.  Capture Mode provides.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
I NTRODUCTION TO PIC PROGRAMMING By : S HERIF H ARHASH.
TIMERS AND INTERRUPTS AVI SINGH KEVIN JOSE PIYUSH AWASTHI.
Microcontrollers, Microcomputers, and Microprocessors
Components of a typical full-featured microcontroller.
Microcontroller basics Embedded systems for mortals.
Electronic instrumentation Digitization of Analog Signal in TD
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Timer modules in PIC 16F877.  The PIC 16F877 basically has three independent timer modules,  denoted by the symbols, TIMER-0, TIMER1,andTIMER2. . These.
Case Study #1 Microcontroller System. What is a microcontroller? A microcontroller can be considered a self-contained system with a processor, memory.
Application Case Study Christmas Lights Controller
IF I ONLY HAD A BRAIN THE MICROCONTROLLER
INTRODUCTION TO ROBOTICS Part 5: Programming
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Invitation to Computer Science, C++ Version, Fourth Edition
Timers and Event Counters
PROGRAMMABLE LOGIC CONTROLLERS SINGLE CHIP COMPUTER
Arduino & its hardware interfacing
Microcontroller basics
Timer and Interrupts.
Digital Fundamentals Floyd Chapter 1 Digital concepts Tenth Edition
UNIT – Microcontroller.
AVR Addressing Modes Subject: Microcontoller & Interfacing
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Chapter 3 Top Level View of Computer Function and Interconnection
Atmega32 Serial Programming Basics
Invitation to Computer Science, Java Version, Third Edition
The Arduino Microcontroller: Atmel AVR Atmega 328
Computer Organization and Design
Introduction to Microprocessors and Microcontrollers
Interrupts, Tasks and Timers
Digital Acquisition of Analog Signals – A Practical Guide
Serial Communication Interface: Using 8251
1 Code
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Programmable Interval timer 8253 / 8254
CSCI1600: Embedded and Real Time Software
Programmable Interval timer 8253 / 8254
8051 Micro Controller.
CSCI1600: Embedded and Real Time Software
Manual Robotics ..
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Wireless Embedded Systems
EXPRESSIONS, PAUSES AND SOUNDS
Introduction to Arduino
Surjo Dutta and David Friedman
Presentation transcript:

Embedded Programming Keeping Time Serial Data and PWM Signals A/D Conversion Data Formats and Constructs Interrupts MAE 156A Ardunio UNO Development Board

MAE 156A 2 What is a microcontroller? A microcontroller (or MCU) is a single-chip computer that contains a processor core, memory, and various input/output peripherals. Programmable memory might be flash (re-writeable) or OTP (one-time programmable) UV erasable devices have largely been replaced by flash Peripherals may include: General-purpose digital input and output Analog-to-digital conversion Serial communications Microcontrollers are relatively cheap. The ATmega328 microcontroller costs about $4 McDonald's hamburger costs about $1 Microcontrollers are everywhere. Over 4 billion microcontrollers were sold in 2006 McDonald's sells 1.5 billion hamburgers each year in the US

MAE 156A 3 Clocks Program execution requires a device clock (heartbeat). On PIC16 devices, four (4) clock cycles are required to execute one (1) instruction The clock timing signal may generated in one of several ways: External crystal or ceramic resonator External oscillator circuit Internal oscillator circuit From the digitial output of another microcontroller Maximum clock frequency generally depends on external power Low-power chips (< 3V) may restrict clock frequency to less than 1MHz What's so special about a clock frequency of kHz? The Arduino UNO uses an external 16 MHz crystal

MAE 156A 4 Timers Most microcontrollers have one or more built-in (hardware) timers. Timers are handy because they can run independently from your code. Your program can do something else while waiting for the timer to expire. Timer operation is governed by two registers. A control register defines operation of the timer. Clock signal Enable interrupt Pre-scale options allow for time scaling Timer value is held in a separate read/writeable (possibly multi-byte) data register. Timer can be set to start counting from a value other than zero

MAE 156A 5 Maximum Time The timer data register is typically 8- or 16-bits. How long before the timer overflows? 16 MHz clock, 8-bit timer starting at value 0 16 MHz clock, 16- bit timer starting at value 0 A timer pre-scaler increases the time before an overflow occurs. Atmega328 prescale options include 1:1, 1:8, 1:64, 1:256, 1: bit timer, starting at value 0, 1:256 prescaler

MAE 156A 6 Pulse Width Modulation (PWM) A PWM signal is characterized by frequency and duty cycle Duty cycle is ratio of pulse width to waveform period Arduino environment offers the analogWrite() function for PWM output. 490 Hz frequency → 2 msec period Duty cycle is specified by an input variable ranging from 0 to 255 (100% duty cycle) Commercial servos used for airplane/car models are controlled with a PWM signal 50 Hz frequency → 20 msec period Pulse Width Period

MAE 156A 7 Serial Data Transmission Serial data is typically represented using the 7-bit ASCII character set. Example: letter 'G' is encoded as ASCII 0x47. 0x47 is hexidecimal notation, equivalent to decimal value of 71, or binary BAUD = symbols transmitted per second For old modems, each “symbol” was one bit, so BAUD became identified as the data transmission rate in bits per second. Be careful! Serial data may use different voltage protocols! TTL: logic low = 0 V, logic high = 5 V RS-232: logic low = -12 V, logic high = +12 V Asynchronous transmission of serial data requires start/stop framing bits. 4idle start stop 8N1 = 8-bit data, one stop, no parity bit

MAE 156A 8 Analog/Digital (A/D) Conversion There are many ways to sample an analog signal to yield a digital result. Direct Conversion (bank of comparators) Successive Approximation (ATmega328) Ramp or Slope compare Sigma-Delta And lots more... When using an A/D input pin, be sure to pay attention to: The A/D process takes time The result has a finite resolution 10-bit A/D converter of ATmega328 can only distinguish 2 10 = 1024 different input values The analogRead() function in Arduino returns values between 0 and 1023 Beware of aliasing Use a low-pass filter to remove high frequency signal content 4 kHz signal frequency -> 8 kHz A/D sample rate -> 4 kHz low-pass filter

MAE 156A 9 Data Types The Arduino development environment supports many data types. Data arrays are also available The number of array elements is limited by memory Arrays are zero-indexed (MATLAB and FORTRAN are not) TypeNumber of BitsRange boolean10 (false) to 1 (true) int16-32,768 to 32,767 unsigned int160 to 65,535 long32-2,147,483,648 to 2,147,483,647 unsigned long320 to ginormous float e+38 to e+38 double32same as float int myArray[10]={9,3,2,4,3,2,7,8,9,11}; // myArray[9] contains 11 // myArray[10] is not valid

MAE 156A 10 Integer Math Integer (fixed-width) math requires special handling so that overflow conditions are dealt with properly. What happens if arithmetic operations exceed range of the assigned data type? int x; x = -32,768; x = x - 1; // x now contains 32,767 -> rolls over in neg. direction x = 32,767; x = x + 1; // x now contains -32,768 -> rolls over

MAE 156A 11 Control Flow The for statement is used to repeat a block of statements enclosed in curly braces. int i; for (i = 0; i < 5; i = i + 1) { Serial.println(myPins[i]); // serial output } They are also useful for array operations. for (int i=0; i <= 255; i++) { analogWrite(PWMpin, i); // change PWM duty cycle delay(10); }

MAE 156A 12 Conditional Expressions if statements allow for a change in instruction order. if (pinFiveInput < 500) { // action A } else { // action B } while loops execute continuously until the conditional expression becomes false. var = 0; while(var < 200) { // do something repetitive 200 times var++; } DANGER! Do not use the single equal sign as a conditional test (e.g. if (x = 10) ). Instead use the double equal sign (e.g. if (x == 10) ), which tests whether x is equal to 10 or not.

MAE 156A 13 Interrupts An interrupt is a special process that interrupts normal program execution after a pre- defined event has occurred. An interrupt is handled in software by a special subroutine, usually called an Interrupt Service Routine (ISR) After the interrupt is handled, program execution continues at the point where the interrupt occurred. Here are some events that can cause an interrupt in the ATmega328: External pin change Timer overflow Transmit or receive buffers full A/D conversion complete More advanced microcontrollers allow the programmer to assign a priority to each type of interrupt.

MAE 156A 14 Interrupt Programming The Arduino UNO board has two external pins that can trigger an interrupt. In the following example, the main program loop does nothing useful until an external pin is brought to a logical high state (i.e. rising edge). void setup() { attachInterrupt(0, int0_ISR, RISING); } void loop() { // do nothing } void int0_ISR(void) { // insert useful actions here }

MAE 156A 15 Further Reading Arduino Development Environment Reference Barrett, S.F., Arduino Microcontroller Processing for Everyone!, Morgan & Claypool Publishers, Barrett, S.F., Embedded Systems Design with the Atmel AVR Microcontroller, Morgan & Claypool Publishers,