DOC PREVIEW
SJSU ME 30 - Microcontrollers

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Week 11 Embedded Programming BJ Furman 12APR2010 The Plan for Today Review of analog I O and pulse width modulation Embedded programming patterns structuring larger programs h and c files Demonstrations for this week s lab Learning Objectives Explain what is meant by Pulse Width Modulation PWM Explain how a microcontroller can output a pseudo analog signal using PWM Explain how larger C programs should be structured using h and c files Explain what is coming this week in lab Analog Out PWM Concept No facility exists on most microcontrollers to directly output an analog voltage i e a voltage that varies continuously over the range of 0 to 5V 5V time Use Pulse Width Modulation PWM to approximate Digital outputs are capable of 0V or 5V Over a fraction ton of a time period tcycle keep pin at 5V the rest of the time at 0V Average voltage is proportional to ton tcycle called the Duty Cycle See Lab View PWM demo vi Front Panel 30 duty cycle Block Diagram Arduino analogWrite analogWrite pin value 0 value 255 0 duty cycle 0 V analogWrite pin 0 100 duty cycle 5 V analogWrite pin 255 fade example pde Analog Output Example Fade the red LED in then out duty cycle is incremented then decremented 256 steps 0 to 100 const byte ledPin 3 red RGB LED on Experimenter const byte FADE MAX 255 max value for setting duty cycle const byte FADE INC 5 increment for changing duty cycle void setup pinMode ledPin OUTPUT void loop int fadeValue PWM value fade in from min to max in increments of 5 points for fadeValue 0 fadeValue FADE MAX fadeValue FADE INC analogWrite ledPin fadeValue sets the value range from 0 to 255 fade out from max to min in increments of 5 points for fadeValue FADE MAX fadeValue 0 fadeValue FADE INC analogWrite ledPin fadeValue sets the value range from 0 to 255 fade example pde Learning Objectives Explain what is meant by Pulse Width Modulation PWM Explain how a microcontroller can output a pseudo analog signal using PWM Explain how larger C programs should be structured using h and c files Structuring C Programs Modularization Breaking a program up into smaller pieces Instead of one big program c break into groupings of header files h and source code c files module 1 h module 1 c etc Rationale separates the user interface description h from the nittygritty details of implementation c The Application Programming Interface API the h file is distinct from the implementation the c file which may already be compiled and not readily viewed Example math h from Ch can construct and test modules independently promotes re use of code Example math h used in Ch See C Ch include math h Declaration of constants define M PI 3 14159265358979323846 Declaration of macro subsitutions define isgreater x y x y Declaration of global variables caution Function prototypes extern double sin double x Pertinent comments Learning Objectives Explain what is meant by Pulse Width Modulation PWM Explain how a microcontroller can output a pseudo analog signal using PWM Explain how larger C programs should be structured using h and c files Explain what is coming this week in lab This Week In Lab IR Communication IR Transmitter board IR Receiver board LTE 302 M IR LED TSOP2438 IR Receiver Module IR Communication Demo IR Remote Coding Various coding schemes exist Pulse pattern maps to a particular button being pressed Pulses are bursts of IR LED flashes at a set frequency 38 kHz is common ir h See ME 30 website Source Code Lab Source Code Microcontroller Programming ir h http www engr sjsu edu bjfurman courses ME30 source ir h Review References Modular Programming in C http www icosaedro it c modules html math h http www opengroup org onlinepubs 00790879 9 xsh math h html A Primer on Remote Control Technology http www innotechsystems com primer1 pdf http www remotecentral com cgi bin codes Arduino Home Page 2009 November 21 Retrieved November 21 2009 from http arduino cc Spartronics Experimenter Board TSOP2438 IR Receiver Module 0 2 ms td 0 4 ms http www vishay com docs 82192 tsop24xx pdf Back LTE 302 M IR LED http www datasheetarchive com pdf datasheets Datasheets 305 79950 pdf Back


View Full Document
Download Microcontrollers
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Microcontrollers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Microcontrollers and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?