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

236                          8. INTERMEDIATE LEVEL PROJECTS

                      /*************************************************************************

                                                  ARBITRARY PERIODIC WAVEFORM
                                                  ===========================
                      In this program an arbitrary periodic waveform is generated with a period
                      of 20ms. The details of teh waveform are given in the text.

                      Author: Dogan Ibrahim
                      Date  : August 2018
                      File  : Arbitrary
                      **************************************************************************/
                      #include "mbed.h"
                      Serial MyPC(USBTX, USBRX);
                      AnalogOut aout(PA_4);

                      float Waveform[] = {0.0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.6,1.6,1.6,1.6,
                                          1.4,1.2,1.0,0.8,0.6,0.4,0.2,0.0};
                      //
                      // This function generates V voltage at the DAC port
                      //
                      void GenerateV(float V)
                      {
                          aout = V / 3.3f;
                      }


                      int main()
                      {
                         int k;

                         while(1)                                 // Do forever
                         {
                             for(k = 0; k <= 20; k++)             // Get waveform samples
                             {
                                  GenerateV(Waveform[k]);         // Generate waveform
                                  wait_ms(1.0);                   // Wait 1ms
                             }
                         }
                      }
                 FIG. 8.110  Program listing.



                 8.33.3 Circuit Diagram
                   In this project, analog input PA_4 is used as in the previous project.




                 8.33.4 The PDL
                   Fig. 8.112 shows the PDL of the program.
   245   246   247   248   249   250   251   252   253   254   255