Page 239 - ARM Based Microcontroller Projects Using MBED
P. 239
BEGIN/MAIN
Configure PortA_4 as DAC
CALL GenerateV with 0V
Wait 100ms
CALL GenerateV with 1V
Wait 100ms
CALL GenerateV with 2V
Wait 100ms
CALL GenerateV with 3V
Wait 100ms
END/MAIN
BEGIN/GenerateV (V)
Generate output voltage with amplitude V
END/GenerateV
FIG. 8.95 Program PDL.
/*************************************************************************
GENERATE FIXED VOLTAGE
======================
This is an example DAC program. In thsi program fixed voltages of 0V, 1V,
2V, and 3V are generated with 100ms delay between each output
Author: Dogan Ibrahim
Date : August 2018
File : FixedV
**************************************************************************/
#include "mbed.h"
Serial MyPC(USBTX, USBRX);
AnalogOut aout(PA_4);
//
// This function generates V voltage at the DAC port
//
void GenerateV(float V)
{
aout = V / 3.3f;
}
int main()
{
while(1) // Do forever
{
GenerateV(0.0); // Generate 0V
wait(0.1); // Wait 100ms
GenerateV(1.0); // Generate 1V
wait(0.1); // Wait 1000ms
GenerateV(2.0); // Genearte 2V
wait(0.1); // Wait 100ms
GenerateV(3.0); // Generate 3V
wait(0.1); // Wait 100ms
}
}
FIG. 8.96 Program listing.