CPTR-215 Assembly Language Programming
HW#18. Due Monday.
Write a program that will control the left motor on one of
the class "vehicles" as follows:
Pressing the center button of the joystick will cause
the motor to turn on with the first press and then off
with a second press. I.e. a toggle function.
Pressing the joystick UP will select forward motion of the
motor. Pressing the joystick DOWN will
select reverse motion. If
the motor is on when the joy stick is pressed UP or DOWN
it will not immediately change direction but the desired
direction will be stored until the motor is stopped and
again started.
If the motor is stopped when the joystick is pressed UP or
DOWN the direction will be remembered so that when the
center button is again pressed it will turn in the specified
direction. You can follow the supplied
flowchart for hw18
The motors for this homework use pulse width modulation (PWM).
A 1.5ms (1500us) pulse length is the nominal value needed for the
motor to be "stopped" (stopping the motor is to be done by
selecting the proper pulse length rather than stopping all
pulsing). Each motor may need a slightly different value
to achieve no motion. You can try values a little above
or below 1500us to find the best "stop" value. And you can
experiment to find values above and below 1500 for the
forward and reverse directions (try 1350 and 1650).
Pulse repetition rate is 20,000 (20 Khz).
Resources to help you:
- A new shell named shell_2148b.s that has the PWM register equates in it.
- A file named pwm_setup.txt that describes how to set up and use the PWM.
- Subroutines pwm_init and pwm_update that can be copied into your program from here
Your program will start with the main and then subroutines should be placed
below but before the data area declaration >
- The NXP users manual for the LPC-2148 (chapter 16, page 253 onward for the PWM)
- A flowchart for hw18
Run your program on the ARM embedded boards. The boards to which I have attached
a vehicle also have a 9v power module plugged into them to provide adequate current
to run the motors. When you arrive in the lab the 9v power will not be plugged in.
When you are ready to try running the motors plug it in. Please unplug the 9v supply before
you leave. The motors will last longer if we don't run them when not needed.
NOTES ON USING THE DEBUGGER (you likely know this stuff already). After downloading the program, start
the debugger. The program counter will be set to zero and the yellow pointer will be
set to the first instruction (a LDR to load an interupt vector). Don't single step
the program. Rather, scroll down until you see the first instruction in the main of
your program. Double click over the line number (likely about 165) to set a break
point (bright red marker). Then click run. Execution should stop at the break point.
At this point you can single step or set additional break points as needed. You can
only have two active break points set at one time with this processor. Note that there
is a single step "into" and a single step "over". The "over" version will run
through a subroutine and stop at the first instruction after the subroutine. "into"
single steps into the subroutine and you can execute one instruction at a time in the
subroutine.
Print out hardcopy of your source code to turn in. Write on your hardcopy the
results, i.e. did the program work? Any problems? Also email me a copy of your .s file.
Larry Aamodt PhD, PE
Professor of Engineering and Computer Science
Walla Walla College
Contact:
via email: AamoLa (at) wallawalla.edu
via phone: x2058