LAB 3 DAC

Fork of DACandticker_sample by William Marsh

Revision:
1:18e0f8aef32f
Parent:
0:5307f49cd305
Child:
2:e27fd3b65155
--- a/main.cpp	Wed Feb 01 13:38:02 2017 +0000
+++ b/main.cpp	Wed Feb 01 13:53:26 2017 +0000
@@ -3,7 +3,7 @@
 // Periodically write to the AnalogOut to create a sine wave
 // Alternate between two fixed frequencies every 5 sec
 //
-// THIS VERSION HAS DEBUGGING CODE USING THE SERIAL PORT
+// THIS VERSION HAS NO DEBUGGING CODE
 
 #include "mbed.h"
 #include "rtos.h"
@@ -12,51 +12,24 @@
 Ticker tick ;          // Creates periodic interrupt
 AnalogOut ao(PTE30) ;  // Analog output
 
-// --- following code for debugging ---
-Thread debugT ;
-Serial pc(USBTX, USBRX); // tx, rx, useful for debugging
-
-// Put a simple reprsentation of the sine wave
-//  to the serial output. ONLY at low frequency
-void debug(int index) {
-    int sine4 = sine[index] >> 11 ; // get top 5 bits
-    pc.putc('*') ;
-    while (sine4--) pc.putc('*') ;
-    pc.putc('\n') ;
-    //pc.putc('\r') ;  
-}
-
+// Function called periodically
+// Write new value to AnalogOut 
 volatile int index = 0 ; // this variable is not just for debugging!!
-
-void debugCallback() {
-    while (true) {
-        Thread::signal_wait(0x1) ;
-        debug(index) ;  // there is a race condition here
-    }
-}
-// ---- end of debugging code ---------
-
-// Function called every periodically
-// Write new value to AnalogOut 
 void writeAout() {
     ao.write_u16(sine[index]) ;
-    debugT.signal_set(0x1) ; // DEBUGGING low frequency only
     index = (index + 1) % 64 ;   
 }
 
 // Control the frequency of updates
 //   Alternative between two frequencies      
 int main() {
-    int update_us = 100000 ; // 100ms
-    debugT.start(&debugCallback) ;
+    int update_us = 1000 ; // 1ms
     while (true) {
-        pc.printf("Update at 64 x 100ms giving about 0.15Hz\n");
         tick.attach_us(callback(&writeAout), update_us); // setup ticker to write to AnalogOut
         Thread::wait(30000) ; // wait 30 sec - 30000ms
-        update_us = 150000 ; // 150ms
-        pc.printf("Update at 64 x 150ms giving about 0.1Hz\n");
+        update_us = 2000 ; // 2ms
         tick.attach_us(callback(&writeAout), update_us); // setup ticker to write to AnalogOut
         Thread::wait(30000) ; // wait 30 sec - 30000ms
-        update_us = 100000 ; // 100ms
+        update_us = 1000 ; // 1ms
     }
 }