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

8.29  PROJECT 24—SAWTOOTH WAVEFORM                  227
                      BEGIN
                              Configure DAC port PA_4 as analog output
                              DO FOREVER
                                      Send 10 steps to DAC port with 2ms each
                              ENDDO
                      END
            FIG. 8.98  Program PDL.

            8.29.4 The PDL

              Fig. 8.98 shows the PDL of the program.


            8.29.5 Program Listing

              The program listing (program: Sawtooth) is shown in Fig. 8.99. At the beginning of the
            program, variable aout is configured as analog output and is assigned to DAC port PA_4.

                /*************************************************************************
                                            GENERATE SAWTOOTH WAVEFORM
                                            ==========================

                This program generates a sawtooth waveform with 10 rising steps where
                each step width is 2ms. i.e. the period of the waveform is 20ms.
                Author: Dogan Ibrahim
                Date  : August 2018
                File  : Sawtooth
                **************************************************************************/
                #include "mbed.h"
                Serial MyPC(USBTX, USBRX);
                AnalogOut aout(PA_4);
                int main()
                {
                   float k;

                   while(1)                                     // Do forever
                   {
                        for(k = 0.0f; k < 1.0f; k = k + 0.1f)   // Do 10 times
                        {
                            aout = k;                           // Analog out
                            wait(0.002);                        // Wait 2ms
                        }
                   }
                }
            FIG. 8.99  Program listing.
   236   237   238   239   240   241   242   243   244   245   246