Teerapong Apiraungpituk
/
MCP4922_Sinewave_p
lab sine wave
Fork of MCP4922_Sinewave by
Revision 3:a4a98380e07b, committed 2015-11-16
- Comitter:
- 57340500039
- Date:
- Mon Nov 16 13:51:42 2015 +0000
- Parent:
- 2:2244c8986987
- Commit message:
- test
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2244c8986987 -r a4a98380e07b main.cpp --- a/main.cpp Mon Aug 24 12:36:59 2015 +0000 +++ b/main.cpp Mon Nov 16 13:51:42 2015 +0000 @@ -1,17 +1,15 @@ #include "mbed.h" #include "MCP4922.h" - MCP4922 MCP(SPI_MOSI, SPI_SCK,SPI_CS); // MOSI, SCLK, CS /**** Main Function ***/ int main(void) { - MCP.frequency(20000000); - - uint16_t i=0; - uint8_t state=0; + MCP.frequency(1000000); + + uint16_t i=0,sent=0; while(1) { if(i < 0x0FFF) { @@ -21,16 +19,11 @@ else { i=0; - state = ~state; } + sent = (int) (sin((double)(i)*(3.14/2047.0))*2047); - if(state ==0) - { - MCP.writeA(i); - } - else{ - MCP.writeA( ((~i)+1)&0x0FFF); - } - wait_us(20); + MCP.writeA(2047+sent); + + wait_us(20); } -} \ No newline at end of file +}