Bob Jeffway / Mbed 2 deprecated MCP4822_SinewaveV2

Dependencies:   MCP4822A mbed

Fork of MCP4822_Sinewave by Bob Jeffway

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // 2.9Khz
00002 
00003 #include "mbed.h"
00004 #include "MCP4822A.h"
00005 
00006 
00007 PinName cspins[] = {(D9)};
00008 MCP4822A MCP(1, D11, D13, cspins, D10);    // NDACs, MOSI, SCLK, nCS-list, nLdac
00009 
00010 int main() {
00011     int i;
00012 
00013 //    printf("\r\n\r\nSetting SPI clock frequency to 10 MHz.\r\n");
00014 //    MCP.frequency(10000000);
00015     printf("\r\n\r\nSetting SPI clock frequency to 20 MHz.\r\n");
00016     MCP.frequency(20000000);
00017     
00018     // Begin by setting all the DACs to 1000 millivolts at gain 2.
00019     printf("Loading all channels with 1000mV at gain 2...\r\n");
00020     MCP.latch_disable();
00021 
00022         MCP.writeA2(0, 2520);
00023         MCP.writeB2(0, 2520);
00024 
00025     wait(4);
00026     printf("Latching now.\n");
00027     MCP.latch_enable();
00028     wait(4);
00029 
00030 
00031 
00032     while (1) {
00033 for (float i = 0; i < 6.28; i=i+.1)  {
00034         MCP.writeA2(0, 1500+sin(i)*1500);
00035 }
00036 
00037     }
00038 }