Produces 2 cycles of a sine wave. Use to demonstrate data export to Excel and/or Matlab.

Dependencies:   mbed

Fork of AnalogSine by Charles Tritt

Revision:
1:f2da7082966e
Parent:
0:076821894a5d
--- a/main.cpp	Thu Oct 26 19:25:24 2017 +0000
+++ b/main.cpp	Wed Nov 08 17:36:36 2017 +0000
@@ -1,14 +1,24 @@
 /*
-  Project: AnalogSine (based on Nucleo_sinwave_output example)
+  Project: AnalogSineFinite (based on Nucleo_sinwave_output example)
   File: main.cpp
   Modified by by: Dr. C. S. Tritt
   Last revision on: 9/26/17 (v. 1.0)
 
+  Finite duration version. Use to generate CSV file for import into Excel or 
+  Matlab.
+
   Generates sine and cosine wave forms to demonstrate D to A operation. Use a
   data buffer for maximum speed (not necessary for 4 mS samples & 1.0 Hz 
   signal). Output clips at a bit 0 and 3.3 V, so use AMPLITUDE <= 0.4 and 
   OFFSET = 1.1. Zoom Horizontal scale out on MSOX2012A scopes and wait for 
   refresh. Without wait, max. freq. (with both channels) is about 2 kHz.
+  
+  Possible improvements/modifications:
+  
+    Reduce number of points/cycle to 18 or 24 (more or less).
+    Change design to use 2 buffers.
+    Change design to use a TimeOut.
+    Use pots to adjust freq. and phase to produce Lissajous patterns.
 */
 #include "mbed.h"
 
@@ -30,15 +40,15 @@
     
     int main()
     {
-        printf("Sinewave example\n");
+        printf("Finite sine wave example\n");
         calculate_sinewave();
-        while(true) {
+        for (int j = 0; j < 2; j++) { // Output 2 cycles and stop.
             // sinewave output
             for (int i = 0; i < BUFFER_SIZE; i++) {
                 my_Sin.write(buffer[i]); // Output a point.
+                printf("%f, ", buffer[i]); // Send point to PC.
                 // Generate Cosine by shifting sine by 1/4 cycle.
                 my_Cos.write(buffer[(i + BUFFER_SIZE/4) % BUFFER_SIZE]);
-                wait_ms(4); // Was wait_us(10); Remove for max. freq.
             }
         }
     }