Unformatted text preview: Lecture #10 - Blimp September 22, 2010 Before Class Begins...
Exam 1 next class – see sample on RPILMS (Note the sample (Note
exam assumes the Keil compiler; sbit syntax is wrong.) Today’s Class
Exam 1 – Part I Coverage – Labs 1 and 2 Two parts
In class – October 4 (sections 1 & 2) or October 5 (sections 3 & 4), 90 minutes Tuesday evening, 7-8:30pm, October 5, 90 minutes, S1- SAGE 4101, 75, S1S2S2- LOW 4050, S3- EATON 214, S4- RCKTTS 203 (unless you are S3S4told otherwise)
Problems & Coding – pencil and paper LMS – in class, 90 minutes, no lab work until everyone done Alternate seating, front and back tabletops Open book, open notes, no sharing, no other apps open book open notes no sharing no other apps open Password: __________ Tuesday evening, 7-8:30pm, October 5, 75, 90 minutes, S1- SAGE 4101, S2- LOW 4050, S3- EATON 214, S1S2S3S4S4- RCKTTS 203 (unless you are told otherwise) Problems & Coding – pencil and paper Conflicts Conflicts – e-mail Mark: [email protected] mail Mark: [email protected] What is the conflict? Can you start late? (There will be a late start group.) Exam 1 – Part II Conflicts – email Mark: [email protected]
What is the conflict? Can you start late? Lecture Topics: PWM, PCA, Programmable Counter Array & Crossbar Homework #8 is due today (sections 3 & 4) Worksheet 6 on PCA & PWM Game report due after first exam, see LITEC Calendar on LMS
9/22/2010 Lecture #10 - Blimp 2 Finish Lab 2, start Worksheet 6 and Lab 3-1 when done – 3may work on just software until everyone is done with exam
9/22/2010 Lecture #10 - Blimp 3 Outline
Pulse Width Modulation, PWM, for motor control control The PCA – Programmable Counter Array Smart Car/ Blimp Representation
Heading Sensor I2C C code Propulsion System
I2C A 16-bit timer/counter 165 Capture/Compare Modules that “look at” or compare to the timer/counter Modules can change output pins Distance Sensor Drive Actuator Steering Actuator Output Port Port Output Port Port Setting the Cross Bar for PCA outputs PCA interrupts
9/22/2010 Lecture #10 - Blimp 4 9/22/2010 Position sensormaybe in the future
Lecture #10 - Blimp 5 1 Lecture #10 - Blimp September 22, 2010 Steering System
We have feedback from electronic th compass, the actual heading. We need to constantly adjust the steering angle of the front wheels to match a desired heading. How can we adjust the wheels? We need How can we adjust the wheels? We need some some type of actuator. Servo Motor
A servo motor is mounted on the front of th the car to adjust the steering. th This is a common type of motor that can move to precise locations and maintain its position. Operating signal is a pulse stream. signal is pulse stream How do we control this type of motor? 9/22/2010 Lecture #10 - Blimp 6 9/22/2010 Lecture #10 - Blimp 7 Controlling a Servo Motor
Changing the pulse stream changes the angular position of the motor position of the motor.
Servo motor Speed Control
On car we want to use the ultrasonic ranger ranger to control the speed. We We will use open loop control. Sending a pulse-width modulated (PWM) signal to the motor can constantly update the steering. Feedback from electronic compass can be used to determine changes to the pulse-width.
9/22/2010 Lecture #10 - Blimp 8 Determine the distance above the car with the ultrasonic unit. Use the distance to create pulse width Use the distance to create a pulse width modulated modulated signal to drive the motor. 9/22/2010 Lecture #10 - Blimp 9 2 Lecture #10 - Blimp September 22, 2010 Controlling the DC drive Motor is similar to the servo, the difference is in the length of the pulses.
We also control a DC motor using a pulse stream.
DC motor DC motor rotating at < rotating at 21 1 Controlling the DC Motor: The car and blimp use a speed control module.
The speed control module Input signal is similar to that used by steering servo, a pulse stream.
1.1ms < input pulsewidth < 1.9ms Signal must be repeated nominally every 20ms Signal must be repeated – nominally every 20ms Output is:
At full battery voltage (12V for car and 7V for blimp) Rated at greater than 20amps, (we need about 0.3A for the car and 2.5A per fan for the blimp.) Has automatic reversal of voltage polarity to allow forward and reverse operation Also is PWM with variable duty cycles. The power applied to a DC motor can be controlled by varying the duty cycle of the applied voltage. Effective voltage = power supply voltage Duty cycle = (on time/period)*100% (pulse on-time/period) on- Result:
Input of 1.1 ms – output is 100% duty cycle with reverse voltage applied, motor runs full speed in reverse motor runs full speed in reverse Input of 1.3 ms – output is about 50% duty cycle with reverse voltage, motor runs about half speed in reverse. Input of 1.5 ms – output is off, motor is off Input of 1.7 ms – output is about 50% duty cycle with forward voltage, motor runs about half speed forward. Input of 1.9 ms – output is 100% duty cycle with reverse voltage applied, motor runs full speed forward. Sending a pulsewidth modulated signal to the motor can control the speed, 0% duty cycle is off, 10% duty cycle is slow, 90% is fast, and 100% is maximum power. We use a speed control module to create the pulse stream.
9/22/2010 Lecture #10 - Blimp 10 9/22/2010 Lecture #10 - Blimp 11 Steering and Speed Steering
Input Actuator Control signal Heading from digital Servo motor PWM – pulse width modulation
~1.5ms is straight, … Repeat pulse every 20ms Speed
Distance above car, read on I2C bus I2C bus Speed Controller to power drive motor PWM – pulse width modulation
1.1 to 1.9ms, 1.5 ms is off, 1.1 full reverse, 1.9 ms full forward Repeat pulse every 20ms
pulse_width = function(height above car) Open loop control Creating Pulse Stream
How can we create a pulse stream to adjust the steering servo motor or drive adjust the steering servo motor or drive motor motor a controlled amount? Need to keep track of time. Need to have status of output pin change automatically. The C8051 microprocessor has a timing system that can do these called the Programmable Counter Array, or PCA Array,
9/22/2010 Lecture #10 - Blimp 13 13 (Lab3, Part2) compass, read on I2C bus Part2) compass read on I2C bus ~0.9ms Pulse width 0.9 to 2.1ms, ~0.9ms is max. left, Control algorithm Interface circuit
9/22/2010 pulse_width = function(actual heading – desired heading) Closed loop control Two wires, buffer, and servo
Lecture #10 - Blimp Two wires, buffer and speed controller
12 12 3 Lecture #10 - Blimp September 22, 2010 Programmable Counter Array (pg 45) (pg
Uses the timing system Can make comparisons in order to perform an action at a specific time Programmable Counter Array
The PCA can count based on the system clock, so it acts as timer so it acts as a timer The PCA has Capture/Compare Modules associated with it 9/22/2010 Each Capture/Compare Module has an associated I/O line which is routed through the Crossbar to the Port I/O When the value stored in the compare module matches the value of the PCA counter, it can set a pin high the PCA counter overflows it can clear this pin When the PCA counter overflows it can clear this pin Each module is associated with an I/O line CEXn (n: 0-4)
The Crossbar will determine which Port I/O pin (if any) will be associated with each CEXn line Can have automatic control of an output pin
Lecture #10 - Blimp 14 9/22/2010 Lecture #10 - Blimp 15 Generating a Pulse Stream
Our goal is to create the pulse stream shown below to control the servo or drive motor: below to control the servo or drive motor:
5V Programmable Counter Array (pg 46)
PCA Modules have various functions. Choose to set a pin at a specific time (when current PCA value is same as value stored in the module) Also has capability to create an interrupt upon overflow of PCA counter fixed time I/O Pin (CEXn)
0 Current PCA value variable time ti We want the PCA to automatically set and clear an output pin through CEXn at specific times Let’s look at how we can do this with the PCA…
9/22/2010 Lecture #10 - Blimp 16 9/22/2010 Choose to increment with system clock
Lecture #10 - Blimp 17 4 Lecture #10 - Blimp September 22, 2010 Programmable Counter Array
The heart of the PCA timer system is a 16-bit 16freefree-running counter
PCA0H and PCA0L
0xFFFF (65,535) PCA, Compare Modules used (page for PWM (page 50)
Compare Modules (there are 5 available) constantly compare value in module to value in counter Can be used to create a pulsewidth modulated signal When values are equal, output is set Later, when counter overflows, output is cleared Changing the value in the compare module will change the width of the pulse
Determine type of action and time of action with these SFRs time of action with these SFRs 0 counter Timer can count: sysclk, sysclk/4,sysclk/12,Timer 0 Overflows, … Count is in PCA0H and PCA0L 16-Bit counting, will overflow every 65536 counts (period) 9/22/2010 Lecture #10 - Blimp 18 9/22/2010 Lecture #10 - Blimp 19 Generating a Pulse Stream (pg 51) (pg
Our desired pulse stream and the PCA counter:
5 Output Voltage on CEXn 0 0xFFFF (65,535) Module value value 0 set output When counter and module match 9/22/2010 reset output when counter overflows
Lecture #10 - Blimp Problem – we need a 20 ms period!
Both speed and steering need a pulse every ~20 ms If the PCA uses SYSCLK one pulse every 3ms If the PCA uses SYSCLK, one pulse every 3ms. If the PCA uses SYSCLK/4, one pulse every 12ms. If the PCA uses SYSCLK/12, one pulse every 36ms. Goldilocks problem, the rates are too fast or too slow. We need one that is just right, so: PCA counter time Make the PCA skip some counts. the PCA skip some counts Use SYSCLK/12 and shorten the count. Use Interrupts to shorten the count – need interrupts.
Each interrupt – jump the PCA count ahead by just enough counts 20 9/22/2010 22, 2010 September Lecture #10 - Blimp 21 5 Lecture #10 - Blimp September 22, 2010 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 Java Applet for PCA
RPILMS 5 Output Voltage on CEXn 0 0xFFFF (65,535) Module value value 0 set output When counter and module match
9/22/2010 course material
section section 11 tools LITEC PCA0 Plotter For some reason it might not load correctly, try more than once. Or http://flitec.rpi.edu/Tools/PCA0Plotter/LitecPCA0Plotter.html time reset output when counter overflows Lecture #10 - Blimp PCA counter without preset PCA counter with preset
22 9/22/2010 22, 2010 September Lecture #10 - Blimp 23 Configuring the PCA
A number of SFRs are associated with the PCA to obtain a PWM signal Configuring the PCA
PCA0CN – PCA Control Register (pg 47) PCA0CN: PCA0CN: Enable/disable the PCA PCA0MD: PCA0MD: Determine what will cause the counter to increment – the PCA mode PCA0CPMn: Determine the operating mode for the Capture/Compare Modules PCA0CPLn, PCA0CPHn: Store a value for the desired pulsewidth desired pulsewidth PCA0L, PCA0H: PCA0L, PCA0H: Store the current value of the PCA counter XBR0: XBR0: Assign the output pins to use with the PCA Enable the counter – bit 6 9/22/2010 Lecture #10 - Blimp 24 9/22/2010 Lecture #10 - Blimp 25 6 Lecture #10 - Blimp September 22, 2010 Configuring the PCA
PCA0MD – PCA0 Counting Mode Configuring the PCA
Page 49 Count SYSCLK – bits 1-3 1- Page 48 PCA0CPMn – PCAn Capture/ Compare Mode Registers (page 49) We will use PCA0CPM0 PCA0CPM0 Set for 16-bit 16PWM, bit 7 Enable compare function bit function, bit 6 Enable Pulse Width Modulation Mode, bit 1 9/22/2010 Lecture #10 - Blimp 26 9/22/2010 Lecture #10 - Blimp 27 Configuring the PCA
PCA0L and PCA0H – Hold the current value of the PCA (pg 262 of SiLabs manual) the PCA (pg 262 of SiLabs manual) Configuring the PCA
PCA0CPL0, PCA0CPL0, PCA0CPH0 – Module 0 compare number
(pg (pg 263 of SiLabs) Used to store the value at which desired action is to take place Two registers Two registers used used for the 8 low bits and the 8 high bits Two registers used for the 8 low bits and the 8 high bits 9/22/2010 Lecture #10 - Blimp 28 9/22/2010 Lecture #10 - Blimp 29 7 Lecture #10 - Blimp September 22, 2010 Need to get the pulses out
There are more signals internal to the C8051 than pins. The Crossbar connects the internal signal to the input/output pins. We need: UART0 SMBus (I2C bus) PCA – 4 modules. modules. To do this, we give up using P0 for digital I/O. You determine which signals are mapped to port pins using SFRs – XBR0, XBR1, XBR2. Once you determine which signals, the microcontroller sets the pins based on the Priority Crossbar Decode Table page 31 Priority Crossbar Decode Table – page 31 of of the manual. SysInit() SysInit() already sets some bits of XBR0 and XBR2. Don’t change them.
Lecture #10 - Blimp 30 9/22/2010 22, 2010 September 9/22/2010 Lecture #10 - Blimp 31 Crossbar pg 31
We need: TX0, RX0 for serial port, (printf and getchar getchar.) Configuring the PCA
XBR0 – Port I/0 Crossbar Register 0
(page 32) I2C bus – SDA, SCL (compass and ultrasonic ranger) We will need to activate CEX0 CEX3 We will need to activate CEX0 – CEX3, bits 3-5 of XBR0. 3Don’t change this bit. PCA – CEX0, CEX1, CEX2, CEX3 (to be able to drive up to four motors.) Warning – this is different than past semesters. Also need to enable the System Management System Management Bus, SMB. This is discussed in lecture 13 and on previous slide. 9/22/2010 Lecture #10 - Blimp 32 32 9/22/2010 Lecture #10 - Blimp 33 8 Lecture #10 - Blimp September 22, 2010 Configure the Crossbar
Your code needs to configure the crossbar as stated stated in the previous 2 slides. Implementing the PWM Signal
The PCA will generate pulsewidth modulated signals on the output pins associated with CEX0, CEX1, … The steering servo motor and the drive speed controller need a signal at a rate of one pulse every ~20 ms The Crossbar is configured using XBR0, XBR1 and XBR2, see pages 32-34 of the LITEC manual. 32(We only need to change XBR0 in this case, page 32 of the manual.) Output pin assignments will change You will have to change your hardware If the PCA uses SYSCLK, one pulse every 3ms. If the PCA uses SYSCLK/4, one pulse every 12ms. If the PCA uses SYSCLK/12, one pulse every 36ms. If you make changes lateryou make changes later Goldilocks problem, the rates are too fast or too slow. We need one that is just right, so: We need one that is just right so: Make the PCA skip some counts. Use SYSCLK/12 and shorten the count. Use Interrupts to shorten the count – need interrupts. Get it correct the first time.
9/22/2010 Lecture #10 - Blimp 34 9/22/2010 Lecture #10 - Blimp 35 PCA Overflow Interrupt
PCA0MD – PCA0 Counting Mode (pg 48) Repeated slide: Getting the correct PWM period.
Write a PCA ISR, (Interrupt service routine) that jumps the count forward a set amount. PCA counter overflow triggers the interrupt A PCA counter overflow triggers the interrupt. Enable PCA0 overflow interrupts – bit 0 (bits 1-3 also used) (bits 1- EIE1 – Extended Interrupt Enable 1 (handout) The code jumps to the PCA ISR on each overflow. The count in the counter is small. An overflow had just occurred. Change the value in the PCA counter in the ISR, to a higher value, and the next ISR will occur sooner than it would with a full count. A shorter count cycle results in less time between pulses. Enable PCA0 interrupt – bit 3 PCA0 Example: Use SYSCLK/12 so 65536 counts takes 35 Example: Use SYSCLK/12, so 65536 counts takes 35.5ms.
In the PCA ISR, the code jumps the count up by 32768 counts. The next over flow will occur only 17.7ms after the last. 32768=65536/2 and 17.7=35.5/2 We need 20ms. One very important point – the PCA ISR must reset the interrupt flag. CF = 0, in the interrupt code– it is not cleared automatically. code–
Lecture #10 - Blimp 37 9/22/2010 Lecture #10 - Blimp 36 9/22/2010 9 Lecture #10 - Blimp September 22, 2010 Repeated slide: 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 Interrupt Number ((C8051 Man. pg. 117) C8051
Use the Priority Number that corresponds to the desired type of interrupt as the Interrupt number in the Interrupt function
Interrupt Source Source Reset External Interrupt 0 (/INT0) Timer 0 Overflow External Interrupt 1 (/INT1) Timer 1 Overflow UART0 Timer 2 Overflow (or RXF2) Serial Peripheral Interface
Interrupt Vector 0x0000 0x0003 0x000B 0x0013 0x001B 0x0023 0x002B 0x0033 0x003B 0x0043 0x004B 5 Output Voltage on CEXn 0 0xFFFF (65,535) Module value value 0 set output When counter and module match
9/22/2010 22, 2010 September Priority Order Top 0 1 2 3 4 5 6 7 8 9 Interrupt Source Source Comparator 0 Falling Edge Comparator 0 Rising Edge Comparator 1 Falling Edge Comparator 1 Rising Edge Timer 3 Overflow ADC0 End of Conversion Timer 4 Overflow ADC1 End of Conversion External Interrupt 6 External Interrupt 7 UART1 External Crystal OSC Ready Interrupt Vector 0x0053 0x005B 0x0063 0x006B 0x0073 0x007B 0x0083 0x008B 0x0093 0x009B 0x00A3 0x00AB Priority Order 10 11 12 13 14 15 16 17 18 19 20 21
39 time reset output when counter overflows SMBus Interface ADC0 Window Comparator Programmable Counter Array Lecture #10 - Blimp PCA counter without preset PCA counter with preset
38 9/22/2010 Lecture #10 - Blimp Summary of Setting Up PCA
Usually need to do once: The output pulses
The servo and speed controller are each driven by a pulse stream. The pulse width controls the wheel position or speed controller output. Pulses must repeat every 20ms.
5V PCA0CN – Enable counter (bit 6) counter (bit 6) PCA0MD – Count SYSCLK (bits1-3) and Enable PCA0 (bits1overflow interrupt (bit 0) PCA0CPM0 – Set for 16 bit PWM (bit 7); Enable compare function (bit 6); Enable Pulse Width Modulation Mode (bit 1) EIE1 – Enable PCA0 interrupt (bit 3) XBR0 – CEX0 and CEX1 (bits 3-5) 3PCA0CPL0, PCA0CPH0 – Set value to (65535 - pulse width) PCA0L and PCA0H – The count in the PCA counter
Lecture #10 - Blimp 40 0 Usually change many times in code: change many times in code: fixed time of 20ms variable time ti 20 ti Change in each PCA ISR variable time = 1900s turn right variable time = 1500s straight variable time = 1100s turn left
9/22/2010 Lecture #10 - Blimp full forward stop full reverse
41 9/22/2010 10 Lecture #10 - Blimp September 22, 2010 The Steering Servo and Drive Power
SYSCLK/12 is 1.8432MHz, Lab 3, Part 1 Servo Hardware
One buffer on the 74F365 chip is used to supply the current required by the servo supply the current required by the servo. The ‘C8051 EVB shouldn’t be used to directly drive the servo.
C8051F020 EVB Connector 74F365
11 12 1.5ms 1.5ms = ~2750 counts (neutral) 1.1ms 1.1ms = ~2000 counts (left/reverse) 1.9ms = ~3500 counts (right/forward) Because of car-to-car variations, your car-toprogram should be able to calibrate the steering servo by adjusting the neutral position, the maximum allowed pulse width, and the minimum allowed pulse width. Servo Input Block Note: The servo can be damaged by using pulsewidths that exceed the capability of the steering linkages.
9/22/2010 Lecture #10 - Blimp 42 42 9/22/2010 Steering Servo Lecture #10 - Blimp 43 Drive Motor Control
+12V Speed Controller Red power Black gnd Thin control wire Programming Note
Remember that the pin associated with CEX is automatically cleared when the CEXn is automatically cleared when the PCA PCA overflows (count of 0) and it is set when the count (PCA0H and PCA0L) matches the values in PCA0CPHn and PCA0CPLn In order to obtain desired pulsewidth In order to obtain a desired pulsewidth, you need to set the values in PCA0CPHn and PCA0CPLn to (0xFFFF – pulsewidth)
44 9/22/2010 Lecture #10 - Blimp 45 C8051 EVBConnector Blue Output + DC Drive Motor Yellow output
74F365 3 2 P1.2
Drive Input Block Circuit within dashed box is prewired on car. You only need to wire the buffer.
9/22/2010 Lecture #10 - Blimp 11 Lecture #10 - Blimp September 22, 2010 Today and Next 2 Classes
Do Worksheet 6 RPILMS exam on October 4 (sections 1 & 2) and October 5 (sections 3 & 4). 90 minutes Paper exam Tuesday evening, 7-8:30pm, 90 minutes, rooms assigned by section #. 8:30pm 90 minutes rooms assigned by section Modify the code given on LMS
Teams with the compass modify compass sample code. Teams with the ultrasonic ranger modify ranger sample code. Allow for four PWM outputs Don’t disable UART0, it is used for printf and getchar Allow for later use of the I2C bus Work on Lab 3, part 1 You will either code and wire for the steering or the speed, but you need to talk to your other team to avoid conflicts: you need to talk to your other team to avoid conflicts: Make code modular – use functions! Don’t use the same variable names Make sure that both teams have set the Crossbar the same Talk to the other team 9/22/2010 Lecture #10 - Blimp 46 12 ...
View Full Document
- Spring '08
- Pulse-width modulation