next up previous
Next: About this document ... Up: lab12 Previous: Input Capture Interrupts

What you need to do to finish this lab

The only "construction" you'll need to do is connect the output of the PN4601 module to the IC1 pin. The real challenge lies in the program because it requires you to coordinate the operation of the input capture and output compare interrupts.

To give you a good starting place, we've modified the kernel for lab 10 to take care of the time-tick and transmission functions. In particular, the global variable _Time is now incremented by the interrupt handler OC2han. The OC2 output compare is enabled by init() and remains enabled forever. It increments the global variable _Time once every 256 hardware time ticks.

The OC4 interrupt handler has been rewritten to transmit a single frame containing the character stored in the global variable sdata. The frame is configured as indicated above in figure 1. In the kernel, we've assumed that the start bit lasts $1000$ hardware time ticks, the data bit lasts $2000$ hardware time ticks, and that there is a stop-bit of duration $4000$ hardware time ticks. The OC4 output compare interrupt is enabled from a new kernel function xmit_data_pa7(). The handler disables itself once it has completed transmitting a single frame of data. The handler assumes that the data to be transmitted is held in global variable sdata.

The kernel function called xmit_data_pa7() is used to initiate transmission of a single frame. This function has the prototype

    void xmit_data_pa7(void);
The function takes the value in global variable sdata and enables the OC4 interrupt which is then used to control the transmission of a single frame from output pin PA7. You would use the function as shown in the following code.
  void main(void){
    int istep;

    init();
    sdata=0;
    rdata=0;
    while(1){
      istep=butcontrol();
      sdata=(sdata+istep)%8;
      display(sdata,rdata);
      xmit_data_pa7();
    }
  }
This is a particularly simple program. The global variable sdata contains the data to be transmitted and the global variable rdata contains the data to be received. The program consists of a single while loop that repeatedly checks the state of the buttons, increment or decrements the data to be transmitted, displays the received and transmitted data to the dual digit LED display, and then enables the OC4 interrupt. The interrupt handler OC4han() then transmits what's in sdata out of pin PA7. You should be able to use this simple program, along with the kernel we've provided you to start your system.

In order to finish this program, you'll need to write a pair of interrupt handlers. You will first need to write an input capture interrupt that detects the start bit of a frame. Upon detecting the start bit, your input capture interrupt should then disable itself and then begin an output compare interrupt that periodically reads the state of the input data pin. This output compare interrupt will decode the frame and should store the result in a global variable, rdata. This variable represents the received data and can be displayed. Since you know that each frame of data consists of exactly eight bits, you know exactly when to stop looking for data bits in the frame. Once your output compare interrupt has finished reading the data bits, it should disarm itself and it should re-arm the input capture interrupt to allow the system to begin looking for start bits again.

A more specific guideline to writing these two interrupt handlers is given below.

The only code you need to write will be these two interrupt handlers. Your original main program probably needs little (if any) modification because all of the work associated with decoding a received data frame is done by the interrupt handlers.

In order to finish this lab, you'll need to demonstrate that your system transmits and receives the requested data. You should be able to demonstrate that if the data link is broken that you link will stop working. You should also be able to transmit information to other people across the room.


next up previous
Next: About this document ... Up: lab12 Previous: Input Capture Interrupts
Michael Lemmon 2009-02-01