Page 251 - ARM Based Microcontroller Projects Using MBED
P. 251

8.33  PROJECT 28—WAVEFORM GENERATOR                 237






























            FIG. 8.111  Generated waveform.






            8.33.5 Program Listing
              Fig. 8.113 shows the program listing (program: Waveform). The program is MENU based
            and consists of a number of functions. The MENU has five options and enables users to
            choose the type of waveform required. After the MENU choice, a switch statement is used
            to read the required parameters for each waveform. Option 1 generates a fixed voltage at
            the DAC port. Calling function GenerateFixed generates the required fixed voltage at the
            DAC port. Option 2 generates a sawtooth waveform. The number of steps required in the
            waveform, the period of the waveform, and its amplitude are all read from the keyboard. Call-
            ing function GenerateSawtooth generates the required sawtooth waveform. Option 3 gener-
            ates a triangular waveform with same parameters as the sawtooth waveform. Calling
            function GenerateTriangular generates the required triangular waveform. Option 4 gener-
            ates a sine wave with the required peak-to-peak amplitude, number of points, and the period.
            Calling function GenerateSine generates the required sine waveform. Finally, option 5 gen-
            erates any kind of waveforms where the sample time (in ms) and the sample points (in volts)
            are entered by the user. Calling function GenerateArbitrary generates the required wave-
            form. After a waveform is generated, the program remains at the requested function. Pressing
            the Reset button on the development board will restart the program so that a new waveform
            can be generated if desired.
   246   247   248   249   250   251   252   253   254   255   256