labSPI
Dependencies: mbed
Fork of MCP4922_Sinewave by
Diff: main.cpp
- Revision:
- 4:1a2a74472be9
- Parent:
- 3:863a9b7d417a
--- a/main.cpp Thu Nov 05 07:29:03 2015 +0000 +++ b/main.cpp Thu Nov 05 08:02:26 2015 +0000 @@ -1,4 +1,3 @@ - #include "mbed.h" #include "MCP4922.h" @@ -8,18 +7,29 @@ /**** Main Function ***/ int main(void) { - MCP.frequency(1000000); - int i; - float a,y; + MCP.frequency(20000000); + + uint16_t i=0; + uint8_t state=0; while(1) { - - - for(a=1;a<=360;a++) - { - y= sin(a*(6.28/360)); - MCP.writeA((y+1)*2000); - } - - + if(i < 0x0FFF) + { + i++; + + } + else + { + i=0; + state = ~state; + } + + if(state ==0) + { + MCP.writeA(i); + } + else{ + MCP.writeA( ((~i)+1)&0x0FFF); + } + wait_us(20); } } \ No newline at end of file