generating constant voltage using DAC0_OUT

Files at this revision

API Documentation at this revision

Comitter:
namcheol
Date:
Wed Apr 15 07:29:40 2020 +0000
Parent:
0:f31836d48420
Commit message:
lab02-constant-voltage

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f31836d48420 -r 7cb2bf6babe2 main.cpp
--- a/main.cpp	Sun Mar 29 19:41:28 2020 +0000
+++ b/main.cpp	Wed Apr 15 07:29:40 2020 +0000
@@ -1,18 +1,15 @@
 #include "mbed.h"
 
-// https://os.mbed.com/docs/mbed-os/v5.15/tools/creating-a-new-program.html
 
-Serial pc(USBTX, USBRX, 115200);    // baud rate 115200
-DigitalOut led(LED1);               // led = LED1
+AnalogOut vout(DAC0_OUT);  //vout = DAC0_OUT
 
 int main()
 {
+    unsigned short v;
+    
     while (true) {
-        led = 0;
-        printf("LED1 is ON\r\n");
-        thread_sleep_for(500);
-        led = 1;
-        printf("LED1 is OFF\r\n");
-        thread_sleep_for(500);
+        v = 0xFFFF * (1.5 / 3.3);  //1.5 V when VDD = 3.3V
+        vout.write_u16(v);
+        thread_sleep_for(1000);
     }
 }
\ No newline at end of file