Lecture_Exam_2_review - Exam 2 review lecture 4/19/2010...

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: Exam 2 review lecture 4/19/2010 Review slides Review of second Exam Topics Exam 2 – Open Book, Open Notes, No Sh Sharing Exam Review Be sure to have a good understanding of basics learned in the game labs (review first exam) learned in the game labs (review first exam). RPILMS next class – 90 minutes No other application open on computer Bring paper copies of any PDF you want available Room must remain quiet for first 100 minutes of class. No talking and no lab work during this time. Written part – Tuesday, 7-8:30pm, see class slides for location 90 minutes Conflicts – email Head TA (see LMS main page) (see page) Digital input and output (how to read from or write to a register) Use of bit masking in reading digital input Setting Ports for open drain or push/pull Generating loops, random numbers Wiring switches, buffers, LEDs Setting up and using Timer 0 overflow interrupts A/D conversion Exam 2 review lecture 2 April 19, 2010 Exam 2 review lecture 1 April 19, 2010 Exam Review Understand the hardware used in the game and the blimp Exam Review Know how the circuit operates: LEDs buffers potentiometer Switches, LEDs, buffers, potentiometer Compass and Ranger sensors using I2C Motor Control – Motor speed controller, servo motor Resistor divider to monitor battery voltage How do the sensors connect? What are the two lines needed? Why are the resistors on the SDA and SCL lines? Understand software used in the game and blimp codes Ports reading, writing, setup Ports – reading, writing, setup Timers 0 and 1, SMB0, PCA, Cross-bar, A/D Crossconversion Coding concepts – loops (if/else, while), bit-masking, bitfunctions, etc. Exam 2 review lecture 3 What’s the difference between a servo motor and a DC motor? Why are buffers used? Answers found in lab descriptions, reading assignments, and lecture slides. April 19, 2010 Exam 2 review lecture 4 April 19, 2010 1 Exam 2 review lecture 4/19/2010 Exam Review Setting up SMB0, System Management Bus #0, a.k.a. I2C Bus #0 Exam Exam Review Setting up the PCA, Programmable Counter Array to create PWM control Counter Array to create PWM control signals. signals. What is the function of each register: XBR0, XBR0, SMB0CR, SMB0CN, SMB0DAT What is the function of each register: PCA0CN, PCA0CN, PCA0MD, PCA0CPMn, PCA0CPLn, PCA0CPHn, XBR0, EIE1 What do we mean by Synchronous Serial Communication? What is required to write/read information What is required to write/read information to/from to/from a sensor on the SMBus? How to have the code wait for a step of the communication complete? while (!SI); Exam 2 review lecture 5 What do pulse(s) look like given the register settings? Given desired pulse(s), what register settings are used to create it? Exam 2 review lecture 6 April 19, 2010 April 19, 2010 Exam Review How do you set up and count with Timer 0 Exam Review Analog to Digital conversion – What is the function of each register TMOD, TL0, TH0 How do you set up a Timer 0 overflow interrupt as in the game lab? Only on Port Only on Port 1 P1MDIN, P1MDOUT Enable A/D, enable the voltage reference, set the gain Do a conversion on a specific pin of Port 1 What is the function of: is the function of: CKCON, TMOD, TCON How was this interrupt used? Understand what you are doing to read the Understand what you are doing to read the sensors sensors and to control the motors and be able to apply that knowledge to a different project. April 19, 2010 Exam 2 review lecture 7 April 19, 2010 Exam 2 review lecture 8 2 Exam 2 review lecture 4/19/2010 SFRs Associated with Timers 0 and 1 CKCON – Clock Control Register (page 226) SFRs Associated with SMB0 SMB0CN – SMBus0 Control Register (pg 191 of C8051 manual) Set to count either SYSCLK or SYSCLK/12 TR0 – enable counting TF0 – flag set on overflow Configure Timer to either count clock cycles or external pulses on input pin T0 Select mode for counter – we are interested in Mode 0 (13-bit counting) and (13Mode 1 (16-bit counting) (16- TCON Timer Control Register (pg 231) TCON – Timer Control Register (pg 231) TMOD – Timer Mode Register (pg 232) BUSY – bit to indicate that the SMBus is busy ENSMB enable bit ENSMB – enable bit STA – send start condition STO – send stop condition SI – serial interrupt flag. We don’t enable the interrupts but we do use the flag. AA – Assert Acknowledge Flag Used to set the serial clock rate Used to send (write) or receive (read) data to/from a device on the bus Used to connect SMBus0 internal signals to port pins SMB0CR – SMBus0 Clock Rate Register (pg 192 of C8051 manual) TL0 and TH0 – Timer 0 Low Byte Register and Timer 0 High Byte Register (pg 233) SMB0DAT SMB0DAT – SMBus0 Data Register (pg 193 of C8051 manual) The actual count currently in Timer 0 IE – Interrupt Enable Register (pg 119) only if we need Timer 0 or Timer 1 interrupts. XBR0 Port I/0 Crossbar Register XBR0 - Port I/0 Crossbar Register 0 EA – Enable All, must be set high to allow any interrupts ET0 – Enable Timer 0 Interrupt April 19, 2010 Exam 2 review lecture 9 April 19, 2010 Exam 2 review lecture 10 Example of writing to sensor. printf("Calibrate compass, y or n"); c = getchar(); if (c == 'y') { printf("enter a key stroke after positioning the car"); Data[0] = 255; for (i=0; i<4; i++) { getchar(); i2c_write_data(0xC0,15,Data,1); } } The I2C write data function //Write data to the I2C bus void i2c_write_data(unsigned char addr, unsigned char start_reg, unsigned char *buffer, unsigned char num_bytes) unsigned char buffer unsigned char num { char i=0; //counter variable i2c_start(); //initiate I2C transfer i2c_write(addr); //write the desired address to the bus i2c_write(start_reg); //write the start register to the bus for(i=0; i<num_bytes-1; i++) //write the data to the register(s) i<num_bytesi2c_write(buffer[i]); i2c_stop_and_write(buffer[i]); // Stop transfer } April 19, 2010 Exam 2 review lecture 11 April 19, 2010 Exam 2 review lecture 12 3 Exam 2 review lecture 4/19/2010 Summary of Setting Up PCA Usually need to do once: Generating a Pulse Stream Our desired pulse stream and the PCA counter: Pulsewidth = 65536 – (value in CCMn) PCA0CN – PCA0 Control Register Enable counter Enable counter – bit6 5 Output Voltage on CEXn 0 0xFFFF (65,535) Module value value 0 set output When counter and module April 19,match 2010 reset output when counter overflows Exam 2 review lecture PCA0MD – PCA0 Mode Count SYSCLK/12 or SYSCLK or … – bits1-3 bits1Enable PCA0 overflow – bit0 Enable global interrupts – EA = 1 PCA0CPMn – PCA0 Capture/Compare Mode Registers Set for 16-bit PWM, bit7 16Enable compare function, bit 6 Enable Pulse Width Modulation Mode, bit1 EIE1 EIE1 – Extended Interrupt Enable 1 Interrupt Enable Enable PCA0 interrupt XBR0XBR0- Port I/0 Crossbar Register 0 CEX0, CEX1, CEX2, CEX3 bits3-5 bits3- Usually change many times in code: PCA0CPLn, PCA0CPHn – Module n compare number (n=0,1,2,3,4) Set to 65535 - pulse width Exam 2 review lecture 13 PCA counter time April 19, 2010 14 Using the PCA Overflow Interrupt to change the period 1ST cycle is without preset, next 2 cycles use preset Period without preset Period with preset Practice Exercises Configure Timer 0, enable interrupts, count sysclk/4 cause an interrupt when the count sysclk/4 cause an interrupt when the count equals equals 8192 (13 bit counting.) Configure the crossbar to allow the use of UART0, SPI, SMB0 and/or CEXn. Configure the PCA to create a 16 bit PWM signal using CCM2 signal using CCM2. 5 Output Voltage on CEXn 0 0xFFFF (65,535) Module value value 0 time set output When counter and module April 19,match 2010 reset output when counter overflows The output should have a 25% duty cycle. Determine which pin will have the output Assume that UART0 is being used (P0.0 and P0.1) PCA counter without preset Exam 2 review lecture PCA counter with preset 15 April 19, 2010 Exam 2 review lecture 16 4 Exam 2 review lecture 4/19/2010 Present speed control is open loop There isn’t any sensing of the actual car speed Output from ultrasound sensor range The Steering Servo – this is closed loop proportional control This is on exam 2, even if you did the ranger. Control of the steering servo motor can be based on the following block diagram. Desired heading neutral offset error Control algorithm pulsewidth generation Speed controller and car + kp Algorithm could be: Result is the actual speed of the car. - pulsewidth generation Servo/car actual heading (feedback) Compass PWM = neutral + K*(desired – range) Output changes speed, not range - no feedback Be careful that PWM is always within limits April 19, 2010 Exam 2 review lecture 17 Take: error = (desired heading – actual heading) (d If our proportional control is set correctly, our control loop will automatically try to turn the car until it is traveling in the desired direction. April 19, 2010 Exam 2 review lecture 18 The Steering Servo Steering control can be simple: proportional control works on the car. ti th Lab 5, not on exam Tail or Thrust Motor Control Control of the motors can be based on the following block diagram desired heading (or altitude) actual heading (altitude) Take: error = (desired heading) – (actual heading) PWM = centerpw + Kp* error PD controller PW to speed controller Motor and blimp This is proportional control, the PWM is proportional to the error Pulsewidth the control algorithm sets the pulse width sent to a speed controller in the gondola. (The speed controller also outputs PWM.) Actual heading (altitude) is determined using the sensors. The blimp responds and actual readings change: feedback control. 19 April 19, 2010 Exam 2 review lecture 20 April 19, 2010 Exam 2 review lecture 5 Exam 2 review lecture 4/19/2010 Lab 5 not on exam, but feedback is: PID - What is Proportional Plus Integral Plus Derivative Control? Proportional control yields a pulsewidth that is proportional to the instantaneous value of the error instantaneous value of the error Integral control yields a pulsewidth that is proportional to the timetimeintegral of the error. Today’s Class Finish Lab 4, start Worksheet 9 & Lab 5 Limit your time on a gondola to 30 minutes if another team is waiting We will use timers if it becomes team is waiting. We will use timers if it becomes a problem. problem. Integral control keeps track of the error history. Derivative control yields a pulsewidth that is proportional to the time rate of change in the error Next Class: Exam 2 RPILMS part – in class The time derivative of the error, d/dt(error) For discrete reading, the derivative has the form or (present_error – previous_error) / time_between_readings 90 minutes, no lab work for first 100 minutes of class 7-8:30 (also 90 minutes) See class slides for location Conflicts: contact Head TA (see LMS main page) (see Exam 2 review lecture 22 Proportional plus integral plus derivative (PID) control combines the (PID) th features of proportional control and integral control and derivative control through superposition. Written part – Tuesday evening The proportional part is used to get fast response. The integral part is used to get zero steady-state error. steadyThe derivative part provides damping. Exam 2 review lecture 21 April 19, 2010 April 19, 2010 6 ...
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