Generate a sine wave on the Analog Output using DMA alone.
Dependencies: DMAFuncGen MODDMA mbed
Revision 0:697cc11ace92, committed 2013-12-29
- Comitter:
- Mischa
- Date:
- Sun Dec 29 01:13:41 2013 +0000
- Commit message:
- Demonstration program for the DMAFuncGen library
Changed in this revision
diff -r 000000000000 -r 697cc11ace92 DMAFuncGen.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DMAFuncGen.lib Sun Dec 29 01:13:41 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Mischa/code/DMAFuncGen/#337ad0fe7734
diff -r 000000000000 -r 697cc11ace92 MODDMA.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODDMA.lib Sun Dec 29 01:13:41 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AjK/code/MODDMA/#97a16bf2ff43
diff -r 000000000000 -r 697cc11ace92 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Dec 29 01:13:41 2013 +0000 @@ -0,0 +1,46 @@ +/* + * Demonstrates sending a buffer repeatedly to the DAC using DMA. + * Connect an oscilloscope to Mbed pin 18. + */ + +#include "mbed.h" +#include "DMAFuncGen.h" + +AnalogIn ain(p17); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +MODDMA dma; +DMAFuncGen fg(dma, MODDMA::Channel_0); + +int main() { + wait(0.5); + + // Create waveform. + fg.buffer_size=400; + fg.buffer = new uint32_t[fg.buffer_size]; + const float PI = 3.1415927; + for (int i=0; i<fg.buffer_size; i++) { + int x = (511*sin(2*PI*i/fg.buffer_size)) +512; + fg.set(i,x << 6); + } + + fg.Connect(); + fg.Setup(); + fg.SetFrequency(0.5); + printf("Frequency: %f\r\n",fg.Frequency()); + fg.Start(); + + // Simple oscilloscope, using the LEDs - + // Connect pin 18 (DAC) to p17 (ADC) for it to work. + float z; + while (1){ + z=ain.read(); + led1 = (z > 0.2) ? 1 : 0; + led2 = (z > 0.4) ? 1 : 0; + led3 = (z > 0.6) ? 1 : 0; + led4 = (z > 0.8) ? 1 : 0; + } +}
diff -r 000000000000 -r 697cc11ace92 mbed.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.lib Sun Dec 29 01:13:41 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/#dc225afb6914