Page 238 - ARM Based Microcontroller Projects Using MBED
P. 238
224 8. INTERMEDIATE LEVEL PROJECTS
There are two 12-bit DACs on the Nucleo-L476RG development board, available at pins
PA_4 and PA_5. A DAC port is configured using the statement AnalogOut. The following
functions are available with the AnalogOut:
write: This function sends out analog data to the specified analog pin. Valid values are
0.0–1.0 where 0.0 corresponds to 0V and 1.0 corresponds to +3.3V.
write_u16: This function sends out analog data to the specified analog pin. Valid values are
0–65,535, where 0 corresponds to 0V and 65,535 corresponds to +3.3V.
read: This function returns the analog voltage sent to the specified analog pin. Returned
values are 0.0–1.0.
As an example, analog output of 0.5 corresponds to 0.5 3.3V¼1.65V.
8.28 PROJECT 23—GENERATING FIXED VOLTAGE
8.28.1 Description
Perhaps the simplest application of a DAC is to generate fixed voltages. In this project, a
function is created to generate fixed voltages. The main program calls this function to gener-
ate 0, 1, 2, and 3V waveforms with 100ms delay between each output. This process is repeated
forever until stopped by the user.
8.28.2 Aim
The aim of this project is to show how the DAC module can be programmed on a Nucleo-
L476RG development board.
8.28.3 Circuit Diagram
In this project, pin PA_4 (pin 32 on connector CN7) of the Nucleo-L476RG is connected to a
digital oscilloscope so that the waveform can be displayed and recorded. In this project, the
PCSGU250 Velleman PC-based oscilloscope is used.
8.28.4 The PDL
Fig. 8.95 shows the program PDL.
8.28.5 Program Listing
Before compiling the program, you should add the Nucleo-L476RG board to your com-
piler. The program listing (program: FixedV) is shown in Fig. 8.96. At the beginning of the
program, statement AnalogOut is used to assign variable aout to DAC port PA_4. Function
GenerateV receives the voltage to be generated as its argument and generates the required
voltage. Inside the main program, the wile statement is used to create an endless loop. Inside
this loop, 0, 1, 2, and 3V are generated with 100ms delay between each output.