Lecture07 - Lecture#7 Today’s Class Homework#6 due today...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture #7 August 26, 2010 Today’s Class Homework #6 due today Quiz 2 Open book, Open notes, Calculators OK No sharing, no copies of past quizzes Alternate seating, front & back tabletops 30 minutes PW: _________ No talking or lab work until everyone is done Coverage: Don’t forget to submit a soft copy forget to submit soft copy Quiz 2 – alternate front & back tabletop seating Introduce Analog to Digital Conversion If you haven’t been checked off on Lab 1, part 2, do so Worksheet #5 Work on Lab 2 Timers Interrupts Pick up ADC handout on center table August 26, 2010 Lecture #7 1 August 26, 2010 Lecture #7 2 Lab Lab 2 LITEC Memory Memory Based on Simon Game Flash a random sequence of one color at a time. Player remembers the sequence and plays it back. Round ends on 1st error or completion. Speed in our game is controlled by turning a potentiometer. 3 color LEDs, 5 flashes in a sequence color Some details left to the designer (you.) August 26, 2010 Lecture #7 3 Lab 2 LITEC Memory Memory Flash time is based on “Speed” potentiometer potentiometer. Colors Colors can be repeated So LED is flashed on for a period of time Followed by all LEDs off for half as long Enhancements are encouraged, but only a few points given on the lab report points given on the lab report. Simon was launched in 1978 at Studio 54 (Wikipedia) August 26, 2010 Lecture #7 4 1 Lecture #7 August 26, 2010 Lab 2 A/D analog to digital conversion Use a potentiometer (pot) to create a variable voltage voltage. That voltage will control the game speed. A/D converter will be used to convert the analog voltage signal from the pot to a digital number. There are two A/D converters on our version of th C8051 ADC1 Di the C8051. We will use ADC1, Analog to Digital Converter #1. A/D Input Signals We’ve been using digital input signals from the pushbuttons Other types of signals exist, such voltage signals from different types of sensors, or the battery voltage. We need to know how to read voltage signals with the microcontroller This type of input functions on a continuous scale Temperature from a thermocouple Oxygen level sensors in a car 8-bit A/D conversion Connected to Port 1 Lecture #7 5 This type of signal is called an analog signal analog Microcontrollers can read analog voltages, but they need to be converted to a digital value August 26, 2010 Lecture #7 6 August 26, 2010 Analog-toAnalog-to-Digital Conversion What is Analog-to-Digital (A/D) conversion? Analog-toA/D A/D conversion is the process by which a th continuous continuous signal (generally a voltage) is mapped mapped at a particular point in time to a digital value. Generic example of mapping: 0.0 2.5 5.0 August 26, 2010 A/D Conversion on the C8051 Different microprocessors conduct A/D Conversion in different ways diff The C8051F020 has two sets of A/D converters 1212-bit conversion on ADC0 8-bit conversion on ADC1 conversion on ADC1 100 ? 200 300 inp x inp L ans x ref L inp H inp L ref H ref L Lecture #7 7 See C8051 manual pages 75 to 82 We will look at ADC1 August 26, 2010 Lecture #7 8 2 Lecture #7 August 26, 2010 C8051F020 Block Diagram (pg 18) (pg A/D Conversion on the C8051 The A/D converter will map the analog input voltage (range: to Vref) to digital input voltage (range: 0 to Vref) to a digital number number in the range of 0x00 to 0xFF ADC1, 8-bit A/D 8connected to P1 0V maps to 0x00 (or 0) Vref maps to 0xFF (or 255) Inputs between 0V and Vref map to integer values proportionally between 0 and 255 values proportionally between and 255 Inputs below 0V map to 0x00 – avoid this Inputs above Vref map to 0xFF – avoid this Lecture #7 10 ADC0, 12-bit A/D 12connected to AIN0 August 26, 2010 Lecture #7 9 August 26, 2010 A/D Conversion on the C8051 ADC1 is connected to Port 1 The C8051 A/D Converter Function (C8051 Block Diagram (C8051 manual pg. 75) Analog voltages on the pins of P1 can be converted Analog voltages on the pins of P1 can be converted to to a digital representation An internal system reference exists for Vref with a value of 2.4V 0V maps to 0x00 (0) 1.2V maps to 0x80 (128) maps to 0x80 (128) 2.4V maps to 0xFF (255) An external reference may also be chosen, but we will use the internal reference. Lecture #7 11 August 26, 2010 Lecture #7 12 August 26, 2010 3 Lecture #7 August 26, 2010 Successive Approximation The C8051 uses an A/D method called successive approximation successive approximation. How does it work? A Sample 4-Bit A/D Conversion 4with Successive Approximation 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 August 26, 2010 Too high Previous best comparator S/H logic n bits numerical result 13 digital approximations 1010 1001 1000 1000 1000 1001 1100 analog digital August 26, 2010 D/A converter Vref Lecture #7 Too low analog input voltage Previous best Uses a D/A converter in a feedback loop input signal Too high Check Good iterations Lecture #7 14 A/D Conversion Timing Note: The A/D conversion process takes a certain amount of time to execute certain amount of time to execute Configuring the C8051 for A/D Conversion A number of SFRs need to be set and accessed to conduct an A/D conversion to conduct an A/D conversion Correct result not available until it is complete Some need to be initialized once to configure the system Setting the port to read analog input signals Determining the voltage reference Some need to be called in the code when an A/D conversion is necessary Determining which input pin to read Starting an A/D conversion Determining when the conversion is complete Reading the results August 26, 2010 Lecture #7 15 August 26, 2010 Lecture #7 16 4 Lecture #7 August 26, 2010 SFRs associated with ADC1 P1MDIN – Port 1 Analog Input (LITEC manual pg 55, C8051 manual pg 165, 174) The C8051 A/D Converter Page 56 of manual Board is hardwired to connect VREF to VREF1 VREF1 Code must: Set pin(s) of P1 to be analog input by writing Set pin(s) of P1 to be analog input by writing a “0” to to them them in this register A “1” sets them for digital input Also, the pins of P1 to be set to “open drain” in P1MDOUT (“0”s) and write a “1” to them in P1 Enable Bias Enable REFBE amp Set ADC1 to use VREF1 Capacitors take time to charge. Readings will be wrong for 2ms after enabling. Note caps in circuit caps in circuit August 26, 2010 Lecture #7 17 August 26, 2010 Lecture #7 18 SFRs SFRs associated with ADC1 REF0CN – Reference Control Register (LITEC manual pg 57, C8051 manual page 92) C8051 SFRs associated with ADC1 ADC1CF – ADC1 Configuration Register (LITEC manual pg 56, C8051 manual pg 79) manual pg 56 C8051 manual pg 79) Turn on 2.4V internal reference Uses jumper on circuit board to VREF pin to VREF1 pin (already configured on board.) Set gain of internal amplification to 1 August 26, 2010 Lecture #7 19 August 26, 2010 Lecture #7 20 5 Lecture #7 August 26, 2010 SFRs associated with ADC1 AMX1SL – AMUX1 Channel Select Register manual pg 58 C8051 manual pg 79) (LITEC manual pg 58, C8051 manual pg 79) SFRs associated with ADC1 ADC1CN – ADC1 Control Register (LITEC manual pg 58, C8051 C8051 manual pg 80) Select which pin of P1 to use for conversion Enable ADC1 Set “Start of conversion mode” Start conversion Flag to say conversion is done 22 22 August 26, 2010 Lecture #7 21 August 26, 2010 Lecture #7 SFRs associated with ADC1 ADC1 – ADC1 Data Word Register (C8051 manual pg 81) manual pg 81) A/D Conversion SFR Summary In program initialization: Configure analog input pins – set desired A/D pins in P1MDOUT to “0” and P1 to “1” and PIMDIN to “0” “0” P1 “1” PIMDIN “0” Configure Reference – set internal reference by clearing REF0CN pin 3: REF0CN = 0x03; REF0CN Configure A/D converter gain – set to gain of 1: ADC1CF |= 0x01; ADC1CF Enable converter: ADC1CN = 0x80; ADC1CN Conduct A/D conversion: = bbb; //bbb: 000-111 bbb; //bbb: 000 Set pin to convert with AMX1SL: AMX1SL = X; AMX1SL //X: 0-7 0 Clear conversion complete bit: ADC1CN &= ~0x20; Start conversion: ADC1CN |= 0x10; ADC1CN Wait for conversion complete: while((ADC1CN & 0x20) == 0x00); while((ADC1CN The result after an A/D conversion Code can use the value found in this register after the conversion is complete Read Results: Access results register: ADresult = ADC1; ADresult Lecture #7 24 August 26, 2010 Lecture #7 23 23 August 26, 2010 6 Lecture #7 August 26, 2010 Circuits - A Few Definitions “V” represents voltage, “I” represents current, “R” represents resistance. Current “flows” through components. Voltage (often referred to as “potential”) is “dropped” across “d components. iR + vR – Basic Circuit Laws Ohm’s Law: v R R i – v2 + R Ri v R R R Kirchhoff’s Voltage Law (KVL): + v1 – + v4 – – v3 + v j Lecture #7 j 0 August 26, 2010 Lecture #7 25 August 26, 2010 26 Basic Circuit Laws Kirchhoff’s Current Law (KCL): i4 i3 i1 i2 Analog Circuits Voltage Dividers By KCL, the current through R1 = the current through R2 = i Vcc By KVL: i j j 0 vcc v1 v2 + By Ohm’s Law: v1 R1i v2 R2i v1 – R1 i R2 Combine the above: v R i 1 1 2 2 R V R R R v R i V RR 1 1 2 2 1 2 Lecture #7 + v2 – cc cc August 26, 2010 Lecture #7 27 August 26, 2010 28 7 Lecture #7 August 26, 2010 A/D worksheet Do the worksheet, (it is in section 6 of the Course Material on LMS LMS Today’s Class If you haven’t been check on Lab 1, part 2, do so. Must do as part of Lab2 – Pinout form Do it before doing Lab 2 Include in your lab notebook Do it, have it checked and keep with Lab Notebook Note: we will talk about the potentiometer next class. Write the answers on the work sheet or in your lab notebook. Put the work sheet in the lab notebook. A/D Worksheet Good prac ice for Quiz 3 Good act Qu Work on Lab 2 Leave your lab notebook with your grading TA – after you have been checked-off for Lab 1, part 2. checked- Next Class – More A/D Conversion August 26, 2010 Lecture #7 29 29 August 26, 2010 Lecture #7 30 8 ...
View Full Document

This note was uploaded on 04/08/2011 for the course ENGR 2350 taught by Professor Fukanari during the Spring '08 term at Rensselaer Polytechnic Institute.

Ask a homework question - tutors are online