Contents
Block Diagram
Rationale for choosing this MCU
Key Features of the design
Design Challenges
Design Shortcomings
Program Code
Breakdown of Tasks
Block Diagram
The following is a block diagram of the schematic diagram of our project.
Major units being used include Pulse Width Modulation (via the internal CCP module),and Analog-to-Digital conversion (Via built in A/D module). The remainder of our project is based on digital output pins built into the chip.
The PulseWidthModulation (PWM) is used to drive our servo motor, on which the distance sensor will be mounted. The PWM is set to have a period of exactly 2.00 milliseconds, which we have verified experimentally. The duty cycle of the PWM is changed at runtime to turn the motor to left, right or center.
The Analog-to-Digital conversion (ADC) module is used in conjunction with a QRD1114 distance sensor to get a digital representation of the distance to an object from the sensor and then enable specific LEDs based on that detected input.
Rationale for choosing this MCU
We chose to use the PIC16F877 microcontroller for several reasons, the primary one being that it supports both PWM and ADC which are the two features that were absolutely required by our project. A further reason for choosing this Microcontroller was due to it being one of the primary Microcontrollers discussed in class.
Key Features of the design
The key features of our design are that it includes actively-changing pulse-width modulation, analog to digital conversion and timed delays. Both the PWM and ADC functions are moderately complex in their implementations and utilizations when using assembly as the coding-language.
Design Challenges
Initially, we had decided to attempt to time our servomotor signal at runtime, without using a PWM module, by setting a pin high, running operations and delaying N microseconds, setting the control pin low, and delaying the rest of the required clock cycles until 2milliseconds had passed. This was incredibly difficult due to the delay requirements of sensing and motor control, and was overcome by the initialization of an Pulse Width Modulation module on the chip.
The second design challenge for this project was the implementation and utuilization of the Analog to Digital conversion module. This was overcome by reading the datasheet for the pic16f877 microcontroller and following example code found online.
Design Shortcomings
Due to problems during testing, our distance sensor (4-30cm) burned out and had to be replaced with a much shorter range one (qrd1114) with a range of roughly 2cm to 0.1cm. Due to this last-minute change, we were unable to mount our distance sensor on top of the servo motor, as it is ineffective at such a short distance range.
During the testing process, it became apparent that our servo motor created noise in the analog input signal from our sensor due to back-EMF created by the motion of the motor. This has been partially isolated by adding a diode between the +5v and GND pins of the servo motor connection, but some EMF still enters the circuit from this motion.
1