Page 255 - ARM Based Microcontroller Projects Using MBED
P. 255
8.33 PROJECT 28—WAVEFORM GENERATOR 241
amplitude = Amp / 3.3f / 2; // Required amplitude
inc = 2.0 / Steps;
dly = Period / Steps;
dly = dly / 1000.0f; // in seconds
while(1) // Do forever
{
for(k = 0.0f; k < 2.0f; k = k + inc)
{
aout = amplitude + amplitude*sin(k*Pi); // Analog out
wait(dly); // Wait dly sec
}
}
}
//
// This function generates a arbitray waveform. The time interval,
// number of points and the waveform array are the arguments
//
void GenerateArbitrary(float T, int P, float W[])
{
float Tim = T / 1000.0f; // In seconds
while(1) // Do forever
{
for(int k = 0; k <= P; k++) // Get waveform samples
{
GenerateFixed(W[k]); // Generate waveform
wait(Tim); // Wait in secs
}
}
}
//
// Start of MAIN program. The main program displays a MENU for the user
// to choose what type of waveform is required. Then the parameters of
// teh chosen waveform are read from the keyboard
//
int main()
{
int choice, RequiredSteps, Points;
float RequiredVoltage, Amplitude, Period, TimeInterval;
float Waveform[50];
//
// Display MENU of options
//
clrscr();
homescr();
MyPC.printf("\n\rWAVEFORM GENERATOR");
MyPC.printf("\n\r==================");
MyPC.printf("\n\r");
MyPC.printf("\n\r1. Generate Fixed Voltage");
FIG. 8.113, CONT’D
(Continued)