Bob Jeffway
/
MCP4822_SinewaveV2
Version 2 Sin wav from DAC
Fork of MCP4822_Sinewave by
Diff: main.cpp
- Revision:
- 1:77d25d0f67d6
- Parent:
- 0:723ec6d615c7
- Child:
- 2:e8d2b1992e9f
--- a/main.cpp Tue Feb 22 17:25:26 2011 +0000 +++ b/main.cpp Mon Mar 28 18:58:54 2016 +0000 @@ -29,7 +29,7 @@ * In this example there are 4 DAC chips daisy-chained on the SPI bus, * which together provide 8 channels. */ -const int ndacs = 4; +const int ndacs = 1; const int nchans = ndacs * 2; /* @@ -40,8 +40,8 @@ * p14, p15, p16, p17 - CS pins, each connected to a separate DAC. * p21 - LDAC pin, connected to all DAC chips. */ -PinName cspins[] = {(p14),(p15),(p16),(p17)}; -MCP4822A MCP(ndacs, p11, p13, cspins, p21); // MOSI, SCLK, nCS-list, nLdac +PinName cspins[] = {(D9)}; +MCP4822A MCP(ndacs, D11, D13, cspins, D10); // MOSI, SCLK, nCS-list, nLdac int main() { int i, buffer; @@ -53,37 +53,20 @@ printf("Loading all channels with 1000mV at gain 2...\r\n"); MCP.latch_disable(); for (i=0; i<ndacs; i++) { - MCP.writeA2(i, 1000); - MCP.writeB2(i, 1000); + MCP.writeA2(i, 2520); + MCP.writeB2(i, 2520); } wait(4); printf("Latching now.\n"); MCP.latch_enable(); wait(4); - // Initialise an array of test voltages (in mV). - int test_voltages[nchans]; - for (i=0; i<nchans; i++) { - test_voltages[i] = i * 500; - } + while (1) { +for (float i = 0; i < 6.28; i=i+.1) { + MCP.writeA2(0, 1500+sin(i)*1500); +} - // Write the array of test voltages to the DACs - // (at gain 2 with automatic latching). - printf("Writing: "); - for (i=0; i<nchans; i++) { - printf("%d ", test_voltages[i]); - } - printf("\r\n"); - MCP.write(nchans, test_voltages, 2, 1); - wait(4); - - //Move the values in the array along one place. - buffer = test_voltages[0]; - for (i=0; i<(nchans-1); i++) { - test_voltages[i] = test_voltages[i+1]; - } - test_voltages[nchans-1] = buffer; } } \ No newline at end of file