CE-2800 Embedded Systems Software
Lab 8: Cruise Control

Objectives

Assignment

In this lab you will write a program that periodically injects a charge pulse into an RC circuit (shown below), and measures the resulting voltage within the circuit. By adjusting the injection interval, a near-constant voltage in the range 0-5V can be maintained within the circuit. Holding the voltage at a desired "set point" emulates the behavior of an automobile cruise control that holds the speed of a car constant.

You will use two timers in the program: Timer/Counter0, configured for Fast PWM mode, will be used to periodically inject a variable amount of charge into the RC curcuit. Timer/Counter1 (a 16-bit T/C) will be used in Normal mode to periodically trigger an A/D conversion that measures the voltage within the RC circuit. The two timers run independently of each other.

You will also need to wire the RC circuit shown below on your breadboard. You can obtain the parts from Tech Support.

RC Circuit

Hardware Configuration of the Atmega32

Program Functionality

Your "main" program should be placed in a file named Lab8.asm, and implement subroutines that:

  1. Initialize PortB for digital output
  2. Initialize/enables the ADC subsystem,  ADC interrupts, enables auto-trigger based on Timer/Counter1 overflow.
  3. Initialize the LCD display so that the first line displays "OCR0: " and the second line displays "Voltage: ".
  4. Configure the 8-bit Timer/Counter0 subsystem in Fast PWM mode to produce a PWM signal on OC0. No interrupts are to be generated by this timer. You'll use the INT0 and INT1 keys to control the duty cycle of the waveform generated on OC0, as described below. By varying the duty cycle, you'll control the amount of charge the system injects into the RC circuit, thus affecting the voltage of the circuit.
  5. Handle the interrupts generated on the button-down actions of the INT0 and INT1 switches. When INT0 is pressed, decrement OCR0, print the updated value of OCR0 to the LCD, and illuminate PB0. When INT1 is pressed, increment OCR0, print the updated value to the LCD, and illuminate PB1. Note that neither INT0 nor INT1 initiate any type of A/D conversion (as they did in the previous lab).
  6. Configure the 16-bit Timer/Counter1 subsystem in Normal mode to generate an Overflow interrupt every 0.26214 seconds. This period is achieved by setting appropriate values to the Clock Select settings for Timer/Counter1. Whenever this interrupt occurs, have the corresponding ISR set PB2. Configure the ADC subsystem (via SFIOR) such that whenever the Timer/Counter1 Overflow interrupt occurs, the A/D converter is automatically started and performs one conversion on the appropriate input pin. When the AD conversion completes, an ADC interrupt should be generated.
  7. Whenever the ADC interrupt occurs upon AD conversion completion, have the ADC ISR update the second line of the LCD with the current voltage, and turn off PB0, PB1 and PB2. For example, if the value contained in OCR0 is 255, and the ADC measures 5v, the LCD should display the following “OCR0: 0x00FF", "Voltage: 0x03FF V”, where the top line displays the OCR0 value and the second is the ADC measurement value.
  8. After initializing the various subsystems, your main program should enter an endless loop as it did in the previous lab.

Demonstration

You are required to demonstrate your program to your instructor in phases. Start by observing the LEDs of PortB. This will provide you with a visual indication (via PB0, PB1, and PB3) that your program is somewhat functional. As you use the INT0 and INT1 switches to vary the duty cycle of OC0, you should observe a correspondingly varying degree of brightness on the LED connected to PB3 as it gets rapidly switched on and off. If this LED is completely off, it should correspond to a OCR0 value of 255; completely on corresponds to an OCR0 value of 0. (Neither the automatic activation of the ADC by the T/C1 interrupt, nor the LCD display are required to be finished by the end of lab.) However, this will count towards 20% of your overall grade for this lab.

For the second phase, which must be demonstrated by the end of the second lab, replace the LED board with the breadboard containing the RC circuitry. Connect the ADC input pin to the capacitor lead. Simultaneously connect the capacitor to the oscilloscope and display the voltage signal there. Complete the implementation of both the automatic initiation of the AD conversion as well as the LCD display logic, so that the LCD displays both the value contained within the OCR0 register as well as the voltage measured by the AD converter.

Lab Submission (due 11:00pm, Wednesday, February 8, 2012)

For your submission, you need only supply your working, fully commented Lab8.asm.

Upload your submission through Blackboard (assignment "Lab 8").

Be sure to keep copies of all your files, in case something gets lost.

Grading

Your lab grade will be determined by the following factors:

Program - comments and formatting are important aspects of assembly language programming! And it has to work correctly.

Timeliness of submission as stated in the course policies.