UNIVERSITY OF VICTORIA FACULTY OF ENGINEERING. SENG 466 Software for Embedded and Mechatronic Systems. Project 1 Report. May 25, 2006.

Similar documents
ECE 511: FINAL PROJECT REPORT GROUP 7 MSP430 TANK

νµθωερτψυιοπασδφγηϕκλζξχϖβνµθωερτ ψυιοπασδφγηϕκλζξχϖβνµθωερτψυιοπα σδφγηϕκλζξχϖβνµθωερτψυιοπασδφγηϕκ χϖβνµθωερτψυιοπασδφγηϕκλζξχϖβνµθ

PIC Functionality. General I/O Dedicated Interrupt Change State Interrupt Input Capture Output Compare PWM ADC RS232

Using Magnetic Sensors for Absolute Position Detection and Feedback. Kevin Claycomb University of Evansville

MICROCONTROLLER TUTORIAL II TIMERS

Project Final Report: Directional Remote Control

Lab 5: Inverted Pendulum PID Control

Ocean Controls KT-5198 Dual Bidirectional DC Motor Speed Controller

EVDP610 IXDP610 Digital PWM Controller IC Evaluation Board

EE445L Fall 2012 Final Version B Page 1 of 7

Lab 5 Timer Module PWM ReadMeFirst

UNIVERSAL-DDS-VFO UDV ( 1 Hz to 10 MHz)

ESE 350 Microcontroller Laboratory Lab 5: Sensor-Actuator Lab

EE 308 Spring S12 SUBSYSTEMS: PULSE WIDTH MODULATION, A/D CONVERTER, AND SYNCHRONOUS SERIAN INTERFACE

ME 461 Laboratory #5 Characterization and Control of PMDC Motors

EE 308 Lab Spring 2009

Autonomous Robot Control Circuit

Lock Cracker S. Lust, E. Skjel, R. LeBlanc, C. Kim

Exercise 5: PWM and Control Theory

Jaguar Motor Controller (Stellaris Brushed DC Motor Control Module with CAN)

RC Filters and Basic Timer Functionality

Castle Creations, INC.

Mechatronics Laboratory Assignment 3 Introduction to I/O with the F28335 Motor Control Processor

Temperature Monitoring and Fan Control with Platform Manager 2

Combinational logic: Breadboard adders

Test Bench Timing V3.1

CHAPTER-5 DESIGN OF DIRECT TORQUE CONTROLLED INDUCTION MOTOR DRIVE

Timer 0 Modes of Operation. Normal Mode Clear Timer on Compare Match (CTC) Fast PWM Mode Phase Corrected PWM Mode

LM4: The timer unit of the MC9S12DP256B/C

Understanding the Arduino to LabVIEW Interface

EE 314 Spring 2003 Microprocessor Systems

Graphical Control Panel User Manual

Experiment #3: Micro-controlled Movement

Detrum GAVIN-8C Transmitter

Embedded Test System. Design and Implementation of Digital to Analog Converter. TEAM BIG HERO 3 John Sopczynski Karim Shik-Khahil Yanzhe Zhao

Measuring Distance Using Sound

Portland State University MICROCONTROLLERS

HIGH LOW Astable multivibrators HIGH LOW 1:1

EE283 Electrical Measurement Laboratory Laboratory Exercise #7: Digital Counter

Hashemite University Faculty of Engineering Mechatronics Engineering Department. Microprocessors and Microcontrollers Laboratory

Temperature Monitoring and Fan Control with Platform Manager 2

HOMANN DESIGNS. DigiSpeed. Instruction manual. Version 1.0. Copyright 2004 Homann Designs.

Chapter 6 PROGRAMMING THE TIMERS

EXERCISE 4: A Simple Hi-Fi

For more information on these functions and others please refer to the PRONET-E User s Manual.

Brushed DC Motor Microcontroller PWM Speed Control with Optical Encoder and H-Bridge

CSCI1600 Lab 4: Sound

Sampling and Reconstruction

Sweep / Function Generator User Guide

ENGR 1110: Introduction to Engineering Lab 7 Pulse Width Modulation (PWM)

OVEN INDUSTRIES, INC. Model 5C7-362

Lab 5: Control and Feedback. Lab 5: Controls and feedback. Lab 5: Controls and Feedback

Electronics Design Laboratory Lecture #9. ECEN 2270 Electronics Design Laboratory

CSE 3215 Embedded Systems Laboratory Lab 5 Digital Control System

Iowa State University Electrical and Computer Engineering. E E 452. Electric Machines and Power Electronic Drives

Analog-to-Digital Converter. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

Master Op-Doc/Test Plan

Figure 1. DMC 60 components.

Direct Digital Synthesis System

Product Family: 05, 06, 105, 205, 405, WinPLC, Number: AN-MISC-021 Terminator IO Subject: High speed input/output device

ME 333 Assignment 7 and 8 PI Control of LED/Phototransistor Pair. Overview

Brushed DC Motor Control. Module with CAN (MDL-BDC24)

Precision Voltage Control System

2.017 DESIGN OF ELECTROMECHANICAL ROBOTIC SYSTEMS Fall 2009 Lab 4: Motor Control. October 5, 2009 Dr. Harrison H. Chin

An Arduino-based DCC Accessory Decoder for Model Railroad Turnouts. Eric Thorstenson 11/1/17

Pololu TReX Jr Firmware Version 1.2: Configuration Parameter Documentation

AC phase. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

Quiz 2A EID Page 1. First: Last: (5) Question 1. Put your answer A, B, C, D, E, or F in the box. (7) Question 2. Design a circuit

Lab Exercise 9: Stepper and Servo Motors

MicroToys Guide: Motors N. Pinckney April 2005

Micro Controller Based Ac Power Controller

UNIVERSAL INPUT TO PULSE CONVERTER MODULE

Analog to Digital Conversion

Timing System. Timing & PWM System. Timing System components. Usage of Timing System

LABORATORY EXPERIMENT. Infrared Transmitter/Receiver

AN4507 Application note

Job Sheet 2 Servo Control

Linear vs. PWM/ Digital Drives

Robotic Swing Drive as Exploit of Stiffness Control Implementation

Preliminary Design Report. Project Title: Search and Destroy

CprE 288 Introduction to Embedded Systems (Output Compare and PWM) Instructors: Dr. Phillip Jones

LAB #10: Analog Interfacing

Dallastat TM Electronic Digital Rheostat

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

ECE 203 LAB 6: INVERTED PENDULUM

Timer A (0 and 1) and PWM EE3376

Grundlagen Microcontroller Counter/Timer. Günther Gridling Bettina Weiss

Handheld Gaussmeter. Robert Ito Michael Wong Faculty Advisor Professor Henry Lee Graduate Student Mentor Owen Finch

Programmable Control Introduction

ARDUINO / GENUINO. start as professional. short course in a book. faculty of engineering technology

Analog I/O. ECE 153B Sensor & Peripheral Interface Design Winter 2016

Frequency Synthesizer Project ECE145B Winter 2011

Introduction to the Analog Discovery

School of Engineering Mechatronics Engineering Department. Experim. ment no. 1

ATmega16A Microcontroller

EE445L Fall 2015 Quiz 2 Page 1 of 5

Figure 4.1 Vector representation of magnetic field.

Lazy Clock Electronics and Software

TAPR TICC Timestamping Counter Operation Manual. Introduction

DAC A (VCO) Buffer (write) DAC B (AGC) Buffer (write) Pulse Code Buffer (write) Parameter Buffer (write) Figure A.1. Receiver Controller Registers

Transcription:

UNIVERSITY OF VICTORIA FACULTY OF ENGINEERING SENG 466 Software for Embedded and Mechatronic Systems Project 1 Report May 25, 2006 Group 3 Carl Spani Abe Friesen Lianne Cheng 03-24523 01-27747 01-28963 Electrical Engineering Computer Engineering Computer Engineering

Table of Contents List of Figures... ii List of Tables... ii Summary... iii 1. Problem Description... 1 1.1 Project Objective... 1 1.2 Analysis of the Problem... 1 2. Discussion... 2 2.1 Wiring the Handheld Radio Controller... 2 2.2 Initial Motor Control Testing... 4 2.3 Analog Gaming Joystick... 8 2.3.1 Hardware Configuration... 8 2.3.2 Transfer Function... 11 2.4 Joystick Motor Control... 13 2.5 Visual Feedback... 16 3. Conclusion... 17 Appendix A Source Code... 1 Page i

List of Figures FIGURE 1: MODIFIED REMOTE CONTROL CIRCUIT SCHEMATIC...2 FIGURE 2: REMOTE CONTROL WITH BACK PLATE REMOVED SHOWING CONNECTION POINTS...3 FIGURE 3: COMPLETED REMOTE CONTROL UNIT...3 FIGURE 4: PIN LAYOUT FOR REMOTE CONTROL CABLE...3 FIGURE 5: MODIFICATION OF THE LIGHT EFFECTS SWITCH...4 FIGURE 6: MODIFIED JOYSTICK SCHEMATIC...9 FIGURE 7: JOYSTICK OUTPUT MAPPING...9 FIGURE 8: JOYSTICK HANDLE BEFORE MODIFICATION... 10 FIGURE 9: JOYSTICK HANDLE AFTER MODIFICATION... 10 FIGURE 10: JOYSTICK BASE BEFORE MODIFICATION... 10 FIGURE 11: JOYSTICK BASE AFTER MODIFICATION... 10 FIGURE 12: PIN OUT FOR THE JOYSTICK... 10 FIGURE 13: JOYSTICK POSITION TO MOTOR POWER TRANSFER FUNCTION... 12 FIGURE 14: CONNECTIONS TO BLT-11... 14 FIGURE 15: PULSE WIDTH MODULATION WHEN DUTY CYCLE IS 60... 15 List of Tables TABLE 1: INITIAL PWM CONTROL WITH PORT A...5 TABLE 2: INITIAL MOTOR CONTROL TEST RESULTS...5 Page ii

Summary This report documents the major design decisions made during the first phase of the autonomous blimp project. During the course of this stage of the project an analog joystick, an HC11 and an Area 51 blimp were interfaced to allow the blimp to be controlled with the joystick. The new control system allows the user to proportionally control the speed of the motors using the joystick. To accomplish this, the remote control of the blimp was modified to allow the outputs of the HC11 to control the motor speed using pulse width modulation. Bipolar junction transistors were used to activate the switches in the controller. The outputs of the joystick were measured using the onboard ADC of the HC11 and using a transfer function turned into motor speeds. To improve the accuracy of the A to D conversion the joystick was modified to produce a 0 to 5 V signal. To control the duty cycle of the PWM signal the output compare timers were used. The power levels being output to the motors as well as the motor directions were displayed on the LCD panel. The conversion was successful and the blimp is easily controlled and flown using the joystick. Page iii

1. Problem Description 1.1 Project Objective The main objective of this project was to get familiar with the maneuverability of an airship and to understand the interfacing issues of A-to-D and D-to-A in an embedded system. 1.2 Analysis of the Problem To achieve this objective, certain design decisions had to be made. The task of maneuvering the blimp using an analog joystick can be broken down into smaller and more manageable tasks. The first is to create a method to control the speed of the motors so that different positions of the joystick have different effects on the motion of the blimp. This can be achieved using pulse width modulation (PWM) which simulates a variable voltage level to the motor (even though the actual voltage level stays at 0V or 5V). The second task is to physically connect the joystick to the blimp so that the blimp s motion can be controlled (there will actually be a wireless link between the joystick and the blimp but this link is transparent and a wired link would have the same effect but is not as desirable). This will be accomplished using a Motorola 68HC11 microcontroller with analogto-digital (A/D) converters to read the joystick position values. The third task is to translate the position of the joystick into different power levels for the motors so that the blimp can be flown by a user. This will be accomplished by a transfer function which will map the position into a power level and direction for the left motor and for the right motor. The trick is to design the transfer function so that the blimp can be flown easily and intuitively. Page 1

2. Discussion 2.1 Wiring the Handheld Radio Controller In order to allow the blimp to be controlled with the HC11, the radio controller had to be modified to provide external connections to the internals of the controller. With the back plate of the controller removed it was found that the controls for the blimp were activated by simply closing switches or contacts. By closing the contacts the control lines are pulled low and the appropriate signals are sent via the radio link to the blimp. To allow this same function to be performed by the HC11 it was decided to bring the control lines outside the controller and place an NPN transistor switch in parallel with the existing switch as shown in the schematic below. Existing Circuit Circuit Modification +5V 10K Vout Manual Switch 4K7 2N3904 10K Control Signal from HC11 Figure 1: Modified remote control circuit schematic When a high logic level (+5V) is applied to the control line, the transistor is driven into saturation which pulls the Vout line to a logic low which sends the signal to the blimp. The 4.7 K! resistor was added to the circuit to provide protection for the circuit in the event that a voltage is accidentally connected to the input. Page 2

To fully control the flight of the blimp, 6 control lines and 1 common line were needed. The connection points on the controller are shown by the red arrows in the left figure below while the completed controller is shown on the right. Figure 2: Remote control with back plate removed showing connection points Figure 3: Completed remote control unit The resistors were covered with heat shrink in order to prevent possible shorting with other components. The following diagram shows the pin connections of the ribbon cable. 10 8 6 4 2 9 7 5 3 1 R E D 1-Right Forward 2-Right Reverse 3-NC 4-Left Forward 5-Common 6-Left Reverse 7-NC 8-Vertical Up 9-NC 10-Vertical Down Figure 4: Pin layout for remote control cable After testing the blimp it was found that if the pulse width modulation (PWM) frequency was higher than 2-4 Hz the blimp receiver only sporadically received Page 3

the signal. It was found that this frequency was able to be increased to approximately 10 Hz by holding down another button on the controller causing the remote control to continuously transmit. To take advantage of this, the light effects button of the blimp was permanently tied to common to cause it to transmit. A photo of the modification is shown below. Figure 5: Modification of the light effects switch 2.2 Initial Motor Control Testing Six wires were connected to the radio controller (as described in Section 2.1) to control the three blimp motors. With these wires each motor can be turned on or off in forward and reverse. However, this project required these motors to be controlled by the position of a joystick and this entails speed control, not just on/off control. Initially, test code was written to work out the control of motor speed using the microcontroller. Since the motors can only turn on and off, different speeds are generated using pulse width modulation. Short pulses will turn on the motors for different durations to achieve different speeds. The output compare timers were used to time the intervals when the motor would be on and off. OC1 was used to turn on bits 6-3 of Port A, and OC2, OC3, OC4 and OC5 were used to turn them off at different time intervals. Page 4

sets bit OC1 OC1 OC1 OC1 clears bit OC2 OC3 OC4 OC5 PORT A 7 6 5 4 3 2 1 0 Table 1: Initial PWM Control with Port A The period of each timer was set to the same number of cycles (20000) but OC2-OC5 were delayed to regulate when each signal was turned off (see Code Fragment 1). TOC1 = TCNT + 40000; TOC2 = TOC1 + 20000; TOC3 = TOC1 + 10000; TOC4 = TOC1 + 5000; TOC5 = TOC1 + 30000; Code Fragment 1: Output compare timer offsets The voltages at the Port A pins were measured and the results were as expected. The voltages decreased as the duty cycles were decreased. However, when the output pins were connected to the motor control wires of the radio controller, not all the motors turned on. The initial results are summarized in Table 2. Port A Pin Output Compare OC Delay Measured Voltage Motor Turned On PA6 OC2 20,000 2.47 V Yes PA5 OC3 10,000 1.23 V No PA4 OC4 5,000 0.61 V No PA3 OC5 30,000 3.72 V Yes Table 2: Initial Motor Control Test Results It appeared that the radio was not transmitting if the signal was not high for long enough. Different delays and periods were tested and confirmed this suspicion. Page 5

The delays for the output compare interrupts were limited to 2 16 cycles because of the size of the registers storing the timer values. A loop was added to the output interrupt service routines so that the delay could be significantly increased. The output compare interrupts were set to do nothing when their timers were up and the Port A bits were set manually within the interrupt service routine (and only after the ISR had been called a specified number of times). The output voltages were measured again and all of the output pin readings were the same. They were all very low and none of the motors turned on. Status codes were output to the LCD in the interrupt service routines to check that they were being called properly. The results were correct and as expected. It appeared as though Port A could not be used for general output and therefore could not be used to control speed in this project. The motor speed control (pulse width modulation) was then moved to Port D another output port available on the BLT11 board. Port D only had 6 output pins and after initial tests, bits PD0 and PD1 appeared to always be high. This could be resolved later. At this time, the main concern was speed control. A single output compare (OC1) was used to toggle all of the PORT D bits. A MOTOR_PERIOD constant was set to 20,000. With the processor running at 2MHz, this would correspond to a delay of 10ms. An outer loop variable in the OC1 ISR could adjust the number of times the ISR was called before the Port D pins were toggled. A duty_cycle variable could hold values from 0 to 100 (in intervals of 10) for ten distinct speeds. Page 6

oc1_loop_count--; if (oc1_loop_count == 0) { if ( PORTD & 0x04 ) { /* port D was high so set it to low */ PORTD &= 0x00; TOC1 += (100 - duty_cycle) * MOTOR_PERIOD / 200; } else { /* port D was low so set it to high */ PORTD = 0xFF; TOC1 += duty_cycle * MOTOR_PERIOD / 200; } } oc1_loop_count = OC1_LOOP_MAX; Code Fragment 2: Original OC1 ISR Code The duty_cycle variable was adjusted by connecting two of the buttons on the board to the input capture pins of Port A (because the joystick interface had not been completed yet). Pressing the buttons increased or decreased the duty cycle in intervals of 10. The duty cycle was output to the LCD and it was being changed according to the buttons. However, when a motor was connected to a Port D output pin, the motor was off when the duty cycle was 0 and fully on for the rest of the values. The output was then viewed with an oscilloscope and it was evident that the duty cycle was not changing. The duty cycle was being printed correctly to the LCD so this was not the problem. The timer offsets (time to next interrupt) were then output to the LCD and they were always negative. The Timer Output Compare Register for OC1 (TOC1) is only 16 bits long so multiplying the MOTOR_PERIOD (set to 20,000) by the duty cycle (10-100) was overflowing it. This was quickly fixed by incorporating the division by 200 into the constant (see Code Fragment 3). Page 7

Old Code #define MOTOR_PERIOD 20000 #define INT_PERIOD MOTOR_PERIOD / 10 TOC1 += duty_cycle * MOTOR_PERIOD / 200; New Code #define MOTOR_PERIOD 20000 #define INT_PERIOD MOTOR_PERIOD / 200 TOC1 += duty_cycle * INT_PERIOD; Code Fragment 3: Overflow Fix The oscilloscope showed the duty cycle of the output signal actually varying according to the variable being set. It was also found that using OC2 and OC3 produced much steadier pulses than OC1. This could possibly be a result of the extra functions of OC1 (ability to turn on all the port a bits) taking more time. At this time there still weren t 10 distinct speeds as at lower duty cycles the motor did not turn on at all. This will have to be tweaked and a longer motor period may be needed. However, a limited form of speed control has been achieved. 2.3 Analog Gaming Joystick 2.3.1 Hardware Configuration The first joystick considered for this project was the Microsoft 3D Pro. The 3D Pro uses an optical sensor to measure the position of the joystick and can output the result as a digital pulse train or can emulate an analog joystick. After looking at the range of the output signal in analog mode it was decided that the span of signal was not sufficient. Due to the use of optical sensors, modification of the joystick to produce a larger signal was not possible. Digital mode was then considered but the clock frequency of the joystick was between 100 and 500 KHz which could be too fast for the HC11 to handle. For this reason a new joystick, the Logitech Wingman, which uses potentiometers to produce an output was selected. The Wingman has 3 analog outputs which include the X-axis, Y- axis, and throttle wheel (used for Up/Down power) and 2 digital buttons. Page 8

To increase the accuracy of the A to D conversion on the HC11, the internal circuitry of the Wingman was modified to provide 0 to 5V signals for each of the analog outputs. The following schematic shows the new configuration. +5V X-axis 100K Y-axis 100K Throttle 100K Button 1 Button 2 Figure 6: Modified joystick schematic While the output for the X-axis, Y-axis, and Throttle are powered by 5V and produce a continuous 0 to 5 V signal, the two button lines are simply connected to push button switches. To convert these connections to useful output signals, pull-up resistors (10K) were needed to allow the signals to be read by the HC11. The joystick outputs a 0V signal on the X-axis and Y-axis if the joystick is pulled back and to the left, and 5V on both if the joystick is pushed forward and to the right. The throttle wheel also produced a 0 to 5 V signal and was to be used for the vertical thrust power. After some testing, however, it was determined that the output from the wheel went from 0 to 5 V before the throttle wheel had reached its extremes. While this was tolerable, it meant that the vertical motor will be much more sensitive than the left and right motors. Figure 7 relates the voltage output and joystick position. 5V Y-Axis 5V X-Axis 0V 0V Figure 7: Joystick output mapping Page 9

The pictures below show the conversion of the joystick. Figure 8: Joystick handle before modification Figure 9: Joystick handle after modification Figure 10: Joystick base before modification Figure 11: Joystick base after modification The pin out for the joystick is shown below. 8 7 6 5 4 3 2 15 14 13 12 11 10 9 Male Connector 1 1-+5V 2-Button 1 3-X-Axis 4-Common 5-NC 6-Y-Axis 7-Button 2 8-NC 9-NC 10-NC 11-NC 12-NC 13-Throttle 14-NC 15-NC Figure 12: Pin out for the joystick Page 10

2.3.2 Transfer Function After much careful deliberation and many rejected ideas, a simple but effective transfer function (the best kind) was chosen for the left and right motors. The power for each horizontal motor is determined by mapping the joystick s x and y positions (as returned by the A/D converter) into a plane in which the z-value corresponds to the motor s duty cycle or power. The duty cycle/power can, in reality, only be positive; however, a negative value in this case represents that same percentage but in the opposite direction. The A/D converter outputs an 8-bit representation (0-255) of the 0-5 Volt input it receives. Thus, the joystick, when centered and calibrated, outputs 2.5V on the x and y axes and the 68HC11 reads this as 128. Accordingly, the plane of the transfer function exists from x = [0, 255] and y = [0, 255] with (x, y) = (128, 128) when the joystick is centered and (x, y) = (128, 255) when the joystick is pushed straight forward. Obviously the left and right motor must use different planes to determine their power (otherwise the blimp would not be able to turn); however, these planes intersect and even share a common axis. This axis of intersection is perpendicular to the x-axis and parallel to the y-axis (but not perpendicular to the z-axis) and runs from (128, 0, -100) to (128, 255, 100). The equations of the planes for the left and right motors were determined by choosing three points that were required to have specific power values (joystick centered is zero power for both motors, joystick full forward or full back is full forward or full reverse for both motors, and joystick full right is 50% for the left motor and -50% for the right motor). From these requirements, the three points for the left motor are (128, 128, 0), (128, 255, 100), and (255, 128, 50) and the three points for the right motor are (128, 128, 0), (128, 255, 100), and (255, 128, -50). From these points, the equation of the z-coordinate of the plane for the left motor was calculated as shown: Page 11

Create 2 vectors on the plane b = (128,128,0)! (128,255,50) = (0,! 127,! 100) c = (128,128,0)! (255,128,59) = (! 127,0,! 50) Find the normal to the plane n = b # c = (6350,12700,! 16129) The equation of the plane is given by (6350,12700,! 16129) " (( x, y, x)! (128,128,0)) = 6350( x! 128) + 12700( y! 128)! 16129z = 0! The equation of the z-coordinate of the plane for the left motor is: P L = 295.5 * (X - 128) + 591 * (Y - 128) 750.6 And the equation of the z-coordinate of the plane for the right motor is: P R = -295.5 * (X - 128) + 591 * (Y - 128) 750.6 These two planes can be seen in the Matlab figure below. Figure 13: Joystick Position to Motor Power Transfer Function Page 12

As seen in Figure 13, the planes are not true planes in that they flatten out at the top and bottom. This is because it is impossible and meaningless to apply a duty cycle that is greater than 100% to the motors; thus the range is restricted to [-100, 100]. This, however, does not create deadzones at the corners because while one motor is maxed out, the other is not, and thus the motion of the blimp will change with joystick motion in the corners (although there will be less sensitivity because only one motor is changing power). Another issue is that both planes pass through zero power areas which will turn off the associated motor and the blimp, being completely circular and with only one motor functioning, will just spin instead of moving. This functionality is implemented when the joystick is pushed hard left or right (P L = -50, P R = +50 or P L = +50, P R = -50 respectively) but is not desirable outside of these two specific instances. To ensure that the motors never shut off completely, the motors can never have a duty cycle below 10% (unless they re in the center deadzone and are specifically turned off). The transfer function for the vertical motor is even simpler. The vertical motor input is a throttle on the side of the joystick that a user can position to provide a constant amount of vertical thrust (positive or negative). This throttle sends a 0-5 Volt signal to the 68HC11 which the A/D interprets as between 0 and 255 (centered at 128). The transfer function is then just a mapping of [0, 255] into [-100, 100] which was accomplished by multiplying by 10 and dividing by 125 (i.e. dividing by 12.5 without floating point) 2.4 Joystick Motor Control A state variable and a duty cycle variable are associated with each of the three motors to indicate the desired motor direction and speed. To control the motor speeds, the output compare timer OC2 was used. The motor control code was modified slightly from the earlier test versions to accommodate 6 different motor speed outputs. Page 13

Port D was used as the output port. Port D has 6 pins but from earlier tests, it was found that bits 0 and 1 of Port D were always high. After some research, the SCI was disabled by clearing the Transmit Enable and Receive Enable bits of SCCR2 register. When these bits are enabled, the data direction register control for Port D bits 0 and 1 is ignored and they are forced to be outputs. This allowed Port D to be used for all 6 of the motor control outputs as shown in the following diagram. BLT-11 PD 0 PD 1 PD 2 PD 3 PD 4 PD 5 PE 0 PE 1 PE 2 Vertical Up Vertical Down Left Forward Left Reverse Right Forward Right Reverse Y-axis from Joystick X-axis from Joystick Throttle from Joystick Figure 14: Connections to BLT-11 There are 10 possible speeds (plus the off state) which are designated by a duty cycle value. The duty cycle refers to the percentage of the motor period that the output is high. Since there are 10 speeds, the OC2 ISR runs 10 times per motor period. The loop counter starts at 0 and increments by 10 every iteration until it reaches 90. It then restarts at 0. During the first iteration when the loop count is 0 (at the start of the motor period), the motors are turned on according to their motor states (see Code Fragment 4). /* turn on motors*/ if (oc2_loop_count == 0) { /* start the left motor in the appropriate direction */ PORTD = left_mtr_state == MOTOR_FWD? PORTD LEFT_FWD_ON : PORTD & LEFT_FWD_OFF; PORTD = left_mtr_state == MOTOR_REV? PORTD LEFT_REV_ON : PORTD & LEFT_REV_OFF; } /* start the right motor in the appropriate direction */... Code Fragment 4: Turn motors on at start of motor period Page 14

At each subsequent loop iteration, if the loop count equals the duty cycle of a motor, it is turned off (see Code Fragment 5). The loop count corresponds to the percentage of the motor period for which the motor control output has been high for. Therefore, when the prescribed duty cycle has been met, the motor is turned off. if (oc2_loop_count == left_mtr_dc) { /* turn off left motor */ PORTD &= (LEFT_FWD_OFF & LEFT_REV_OFF); } Code Fragment 5: Turn motor off when loop count equals duty cycle LOOP COUNTER 0 10 20 30 40 50 60 70 80 90 0 10 V MOTOR PERIOD / 10 60% duty cycle t MOTOR PERIOD Figure 15: Pulse Width Modulation when duty cycle is 60 When the loop restarts at 0, the motors are turned on again. If the duty cycle is 100, the motor should be on for 100% of the motor period. Since the loop count never reaches 100, the motor is never turned off. Page 15

2.5 Visual Feedback To provide some visual feedback to the user, the motor states and power/duty cycle were output to the LCD. This allowed the user to have an idea of the expected motion of the blimp. After each setting of the motor duty cycle and motor state variables, the LCD was updated. The code is shown below (see Code Fragment 6). The LCD sample code provided was used to output characters to the LCD on the board. /* display the horizontal motor powers and states (o = off, f = fwd, r = rev) */ lcd_clr(); printf("l:%c/%d R:%c/%d", left_mtr_state, left_mtr_dc, right_mtr_state, right_mtr_dc); /* display the vertical motor's power and state (o = off, u = up, d = down) */ if ( vert_mtr_state!= MOTOR_OFF ) vert_char = ( vert_mtr_state == MOTOR_FWD? 'u' : 'd' ); lcd_cursor(0x40); printf( "V:%c/%d", vert_char, vert_mtr_dc ); Code Fragment 6: Display motor speeds and states on the LCD Page 16

3. Conclusion The radio controller, the Motorola 68HC11 microcontroller, and the analog gaming joystick were successfully interfaced to allow smooth control of the speed and direction of the blimp using the joystick. This was accomplished by breaking down the project into smaller tasks. After modifying the internal circuitry of the Logitech Wingman joystick so it produced the 0 to 5 Volt output signals desired, a transfer function was designed to map the joystick s x-axis and y-axis values to motor speeds/duty cycles and directions/states. The following equations were used to calculate the power for the left and right motors: P L = 295.5 * (X - 128) + 591 * (Y - 128) 750.6 P R = -295.5 * (X - 128) + 591 * (Y - 128) 750.6 Six wires were attached to the blimp radio controller to allow the microcontroller to control the three motors in forward and reverse directions. Pulse width modulation was used to produce different motor speeds because the motors could only be turned on and off. An output compare timer interrupt (OC2) was used to turn on the motors and turn them off after their duty cycle. Ten duty cycle intervals could be set (10 to 100), which gives the blimp 10 different speeds. The frequency at which the motors could be switched on and off was able to be increased significantly by permanently tying the light effects button to common, causing the radio to continuously transmit. The current speed and state for each motor was output to the LCD panel after each A/D reading. After some fine-tuning, the blimp flew smoothly under the control of the joystick. Page 17

Appendix A Source Code Page A