next up previous
Next: What you should have Up: Micro-controller Learning Module Output Previous: How to generate a

Learning Module Exercise

In this learning module you'll build a system that generates a PWM wave that drives the capacitive DAC we discussed earlier. You can use a Hyperterm shell to enter the duty cycle for the PWM wave. The principles behind the hardware and software for this project were discussed above. Figure 11 shows the schematic diagram for your system.

Figure 11: Schematic for Output Compare Learning Module
\begin{figure}\epsfxsize =4.in \epsfclipon \centerline{\epsffile{fig/module-schematic-1.eps}} \end{figure}

Note that this circuit uses an LM660 op-amp. The LM660 IC has 4 operational amplifiers on it. You'll only need to use one of them. The pinout for the device is shown in figure 12. Note that you'll need to connect a +15 volt supply voltage to $V_{cc}$ and you'll need to connect GND to ground.

Figure 12: pinout for LM660 op-amp
\begin{figure}\epsfxsize =2.in \epsfclipon \centerline{\epsffile{fig/lmc660.eps}} \end{figure}

The software side of this project is shown in the following listing.

 #include"kernel.c"

 void main(void){
   unsigned int duty_cycle;
   init();
   while(1){
     OutChar("enter duty cycle:");
     duty_cycle=InUDec();
     set_pwm(duty_cycle);
   }
 }
 #include"vectors.c"

This deceptively simple program does nothing more than wait for the user to input the duty cycle for the pwm wave. The program then uses this input value to set the duty cycle of the pwm. Note that because the duty cycle is always executed by the output compare interrupt, that this periodic signal is generated on pin OC4 even though the program is blocked in the while loop until the user enters a new duty cycle number. This simple program shows how interrupts such as the OC4 interrupt can be used to make the micro-controller appear to do two things at once. In this case, those two things are waiting for the user to supply an input and generating the PWM signal.


next up previous
Next: What you should have Up: Micro-controller Learning Module Output Previous: How to generate a
Bill Goodwine 2001-09-04