First Shot at Sin wav from DAC

Dependencies:   MCP4822A mbed

Fork of MCP4822_demo by Steven Beard

Revision:
2:e8d2b1992e9f
Parent:
1:77d25d0f67d6
--- a/main.cpp	Mon Mar 28 18:58:54 2016 +0000
+++ b/main.cpp	Fri Apr 01 19:16:40 2016 +0000
@@ -1,61 +1,27 @@
-/*
- * MCP4822A DAC array library demonstration program.
- *
- * Copyright (c) 2011 Steven Beard, UK Astronomy Technology Centre.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
+// 2.9Khz
 
 #include "mbed.h"
 #include "MCP4822A.h"
 
-/*
- * In this example there are 4 DAC chips daisy-chained on the SPI bus,
- * which together provide 8 channels.
- */
-const int ndacs = 1;
-const int nchans = ndacs * 2;
 
-/*
- * The following mbed pins are used:
- *
- * p11 - SPI mosi
- * p13 - SPI sclk
- * p14, p15, p16, p17 - CS pins, each connected to a separate DAC.
- * p21 - LDAC pin, connected to all DAC chips.
- */
 PinName cspins[] = {(D9)};
-MCP4822A MCP(ndacs, D11, D13, cspins, D10);    // MOSI, SCLK, nCS-list, nLdac
+MCP4822A MCP(1, D11, D13, cspins, D10);    // NDACs, MOSI, SCLK, nCS-list, nLdac
 
 int main() {
-    int i, buffer;
+    int i;
 
-    printf("\r\n\r\nSetting SPI clock frequency to 10 MHz.\r\n");
-    MCP.frequency(10000000);
+//    printf("\r\n\r\nSetting SPI clock frequency to 10 MHz.\r\n");
+//    MCP.frequency(10000000);
+    printf("\r\n\r\nSetting SPI clock frequency to 20 MHz.\r\n");
+    MCP.frequency(20000000);
     
     // Begin by setting all the DACs to 1000 millivolts at gain 2.
     printf("Loading all channels with 1000mV at gain 2...\r\n");
     MCP.latch_disable();
-    for (i=0; i<ndacs; i++) {
-        MCP.writeA2(i, 2520);
-        MCP.writeB2(i, 2520);
-    }
+
+        MCP.writeA2(0, 2520);
+        MCP.writeB2(0, 2520);
+
     wait(4);
     printf("Latching now.\n");
     MCP.latch_enable();