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

8.33  PROJECT 28—WAVEFORM GENERATOR                 239
               /*************************************************************************

                                           WAVEFORM GENERATOR
                                           ==================
               This program generates fixed voltage, sawtooth waveform, triangular
               waveform, sine waveform, and arbitrary waveform. The parameters of
               each type of waveform are entered from the keyboard
               Author: Dogan Ibrahim
               Date  : August 2018
               File  : Waveform
               **************************************************************************/
               #include "mbed.h"
               Serial MyPC(USBTX, USBRX);
               AnalogOut aout(PA_4);

               //
               // Clear the screen
               //
               void clrscr()
               {
                   char clrscr[] = {0x1B, '[', '2' , 'J',0};
                   MyPC.printf(clrscr);
               }

               //
               // Home the cursor
               //
               void homescr()
               {
                   char homescr[] = {0x1B, '[' , 'H' , 0};
                   MyPC.printf(homescr);
               }


               //
               // This function generates fixed voltage at the DAC port
               //
               void GenerateFixed(float V)
               {
                   aout = V / 3.3f;
               }
               //
               // This function generates a Sawtooth waveform. The required number
               // of staps and the period are arguments of the function
               //
               void GenerateSawtooth(float Amp, int Steps, float Period)
               {
                  float k, amplitude, inc, dly;

                  amplitude = Amp / 3.3f;                          // Required amplitude
            FIG. 8.113  Program listing.
                                                                                     (Continued)
   248   249   250   251   252   253   254   255   256   257   258