gen triangle wave

Dependencies:   mbed

Fork of MCP4922_Sinewave by masa miya

Committer:
soulx
Date:
Wed Dec 23 12:19:03 2015 +0000
Revision:
5:c4a38038ab44
Parent:
2:2244c8986987
-

Who changed what in which revision?

UserRevisionLine numberNew 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 {
soulx 2:2244c8986987 11 MCP.frequency(20000000);
jf1vrr 0:5737b1972549 12
soulx 2:2244c8986987 13 uint16_t i=0;
soulx 2:2244c8986987 14 uint8_t state=0;
soulx 2:2244c8986987 15 while(1) {
soulx 5:c4a38038ab44 16 if(i < 0x0FFE) {
soulx 2:2244c8986987 17 i++;
soulx 5:c4a38038ab44 18
soulx 5:c4a38038ab44 19 } else {
soulx 2:2244c8986987 20 i=0;
soulx 2:2244c8986987 21 state = ~state;
soulx 2:2244c8986987 22 }
soulx 5:c4a38038ab44 23
soulx 5:c4a38038ab44 24 if(state ==0) {
soulx 2:2244c8986987 25 MCP.writeA(i);
soulx 5:c4a38038ab44 26 } else {
soulx 5:c4a38038ab44 27 MCP.writeA( ((~i)+1)&0x0FFF);
soulx 5:c4a38038ab44 28 }
soulx 5:c4a38038ab44 29 wait_us(1);
soulx 2:2244c8986987 30 }
jf1vrr 0:5737b1972549 31 }