Lab Week 11 (Sine Wave)
Dependencies: mbed
Fork of MCP4922_Sinewave by
Revision 3:095b3ca4c0f9, committed 2015-11-16
- Comitter:
- ParinyaT
- Date:
- Mon Nov 16 19:45:38 2015 +0000
- Parent:
- 2:2244c8986987
- Commit message:
- Lab week 11 (sine wave)
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2244c8986987 -r 095b3ca4c0f9 main.cpp --- a/main.cpp Mon Aug 24 12:36:59 2015 +0000 +++ b/main.cpp Mon Nov 16 19:45:38 2015 +0000 @@ -2,35 +2,24 @@ #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); + MCP.frequency(1000000); - uint16_t i=0; - uint8_t state=0; - while(1) { - if(i < 0x0FFF) - { - i++; - - } - else - { - i=0; - state = ~state; - } - - if(state ==0) - { + int16_t i=0; + int T=0; + while(1) + { + i = 0x07FF*sin(0.1*T); + i = i+0x07FF; + T++; + MCP.writeA(i); - } - else{ - MCP.writeA( ((~i)+1)&0x0FFF); - } wait_us(20); } } \ No newline at end of file