Page 246 - ARM Based Microcontroller Projects Using MBED
P. 246
232 8. INTERMEDIATE LEVEL PROJECTS
BEGIN
Configure DAC port PA_4 as analog output
DO FOREVER
DO 100 times
Generate a sine waveform step
Wait 100 microseconds
ENDDO
ENDDO
END
FIG. 8.105 Program PDL.
/*************************************************************************
GENERATE SINE WAVEFORM
======================
This program generates a sine waveform with 100 steps, each step 100
microsseconds. The period of the generated waveform is therefore 10ms.
The waveform has the peak amplitude of +3.3V.
Author: Dogan Ibrahim
Date : August 2018
File : SineWave
**************************************************************************/
#include "mbed.h"
Serial MyPC(USBTX, USBRX);
AnalogOut aout(PA_4);
int main()
{
float k, Pi = 3.14159;
while(1) // Do forever
{
for(k = 0.0f; k < 2.0f; k = k + 0.02f) // Do 100 times
{
aout = 0.5f + 0.5f*sin(k*Pi); // Analog out
wait_us(100.0); // Wait 100us
}
}
}
FIG. 8.106 Program listing.