v
Dependencies: mbed
Fork of MCP4922_Sinewave by
main.cpp@3:0ff7b96f04b8, 2015-11-02 (annotated)
- Committer:
- Peeraya
- Date:
- Mon Nov 02 08:21:02 2015 +0000
- Revision:
- 3:0ff7b96f04b8
- Parent:
- 2:2244c8986987
FINISH
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
soulx | 2:2244c8986987 | 1 | |
jf1vrr | 0:5737b1972549 | 2 | #include "mbed.h" |
jf1vrr | 0:5737b1972549 | 3 | #include "MCP4922.h" |
jf1vrr | 0:5737b1972549 | 4 | |
soulx | 2:2244c8986987 | 5 | MCP4922 MCP(SPI_MOSI, SPI_SCK,SPI_CS); // MOSI, SCLK, CS |
jf1vrr | 0:5737b1972549 | 6 | |
jf1vrr | 0:5737b1972549 | 7 | |
jf1vrr | 0:5737b1972549 | 8 | /**** Main Function ***/ |
soulx | 2:2244c8986987 | 9 | int main(void) |
soulx | 2:2244c8986987 | 10 | { |
Peeraya | 3:0ff7b96f04b8 | 11 | MCP.frequency(10000000); |
jf1vrr | 0:5737b1972549 | 12 | |
Peeraya | 3:0ff7b96f04b8 | 13 | double i= 0; |
Peeraya | 3:0ff7b96f04b8 | 14 | |
soulx | 2:2244c8986987 | 15 | while(1) { |
Peeraya | 3:0ff7b96f04b8 | 16 | if(i < 3.14*2) |
soulx | 2:2244c8986987 | 17 | { |
Peeraya | 3:0ff7b96f04b8 | 18 | i+=0.001; |
soulx | 2:2244c8986987 | 19 | |
jf1vrr | 0:5737b1972549 | 20 | } |
soulx | 2:2244c8986987 | 21 | else |
soulx | 2:2244c8986987 | 22 | { |
soulx | 2:2244c8986987 | 23 | i=0; |
soulx | 2:2244c8986987 | 24 | } |
soulx | 2:2244c8986987 | 25 | |
Peeraya | 3:0ff7b96f04b8 | 26 | MCP.writeA(((sin(i)+1)/2.0*4095)); |
Peeraya | 3:0ff7b96f04b8 | 27 | |
soulx | 2:2244c8986987 | 28 | wait_us(20); |
soulx | 2:2244c8986987 | 29 | } |
jf1vrr | 0:5737b1972549 | 30 | } |