ECE 354 - Computer System Lab II

Project 4 - Building an Analog Communications System

Introduction

So far, we have spent most of our time this semester learning how to design digital systems that solve a variety of computing problems. In practice, it is often necessary to understand how to interface to analog systems as well. In this assignment you will learn how to build a primitive analog communication system using D/A and A/D resources embedded within the 16F877. While the hardware development for this assignment is fairly simple (basically just two PICs), software development requires attention to a number of programming details. For this assignment, please pay particular attention to the lab 4 lecture notes, as they give a detailed perspective into what is required for the lab. In general, both the 16F877 and Peatman book give much more information on A/D and D/A conversion than is needed to complete the assignment. The lectures notes will help you isolate the important aspects and tasks of the assignment.

For this assignment your finished project should operate as follows:

1. A keyboard connected to the USART on a 16F877 transmits eight bit characters ('r', 's', 't', 'l', 'e', SPACE) to the PIC. Receive interrupts should be used by the PIC to determine if data has arrived. Remember to initialize the appropriate interrupt enable registers (e.g. PIE1) in order to get interrupts working correctly.
2. The ASCII value is then converted to an eight-bit digital value by the 16F877. As mentioned in lecture these values are (0V, 1V, 2V, 3V, 4V, and 5V, respectively). Other characters besides the six mentioned above (note: SPACE is a character) may be ignored. A corresponding duty cycle value for the pulse-width modulation unit based on this value is then determined and written to 16F877 registers CCPRL1 and CCP1CON. The output analog signal from the PWM unit appears on pin CCP1
3. The square wave generated by the PWM unit is sent to a second, receiving 16F877. During transit, a low-pass filter converts the square wave into a DC value. Note that the transmission of the analog signal will be continuous as long as the PWM is enabled. The received analog signal is attached to I/O pin AN0.
4. The A/D converter on the receiving 16F877 samples the received analog value every 512us. The received value, once converted to digital form, is compared to the value that was just previously received. If the value has changed compared to the value just previously received, the character associated with the new voltage level (0V, 1V, 2V, 3V, 4V, 5V) is sent to the terminal display attached to the receiving 16F877.

The key 16F877 features to understand for this assignment are the PWM unit (including Timer2), the analog-to-digital converter (A/D), the USART, and Timer 0 (to generate 512us notification). Polling can be used for all aspects of this assignment (except for character receive) although you are free to use interrupts for all parts if you wish (you may actually find this easier).

Procedure

In order to be checked off on this assignment the following tasks must be completed. For additional information regarding these tasks, please see the lectures notes for Lab 4. Your PIC should be able to operate as the SENDING or as the RECEIVING 16F877 or as both. For testing purposes, it is fine to operate as both (e.g. PWM output connected to A/D input via low-pass filter).

1. Initialize the USART to receive characters. Baud rate, parity, etc are up to you.
2. Initialize the PWM unit to have a period of 5uS. This can be accomplished by configuring Timer2 appropriately.
3. As new characters ("voltage" levels) are received from the terminal, modify the duty cycle value in CCPRL1 and CCP1CON as discussed in class.
4. At the RECEIVING 16F877, initialize the A/D converter to 10 bits accuracy. Due to noise it may be the case that even though the same analog value is sent from one PIC to the other time after time, the resulting received 10 bit values will vary slightly. To avoid discrepencies, compare received digital values to a RANGE of digital values for each desired voltage (e.g. 0, 1, 2, 3, 4, 5) to determine the "true" voltage that was transmitted.
5. Initialize the USART at the receiver to transmit the associated character if a new voltage value is detected (e.g. the latest detected voltage differs from the one received just previously).
6. Modify the period of the PWM unit and associated duty cycle values to determine the longest PWM period that will still allow for accurate analog data transmission. Be ready to show your experiment during checkoff.

Things to keep in mind

1. After initializing the A/D at the RECEIVING 16F877 it makes sense to wait a while before activiting the A/D. If you immediately activate the A/D the received voltages will likely vary wildly and many messages will be printed to the terminal. I suggest putting in a loop in your code and waiting a few milliseconds before setting the A/D into action (Timer 0 can be used to determine when the few milliseconds have passed). The PWM can be initialized immediately with a duty cycle of 0.
2. As I described in class, come up with a range of 10 bits values that represent each of the 6 received analog voltages. This range can be used after the A/D has obtained data to determine which of the 6 analog voltages has been received.
3. Take a look at the output of the PWM on the oscilloscope both with and without the low-pass filter.

Demonstration

I should be able to type a key on your terminal, have your PIC send a value to a neighbors 16F877, and then have the value I transmitted appear on the neighbors terminal. You have a separate piece of code which shows which PWM "just barely works" with respect to accurate transmission.

Report

Your report should follow the same guidelines as previous reports in terms of sections. Please include detailed discussion of how you chose your "range" of ten bit values for each received voltage level. Include all commented 16F877 code.