gen triangle wave

Dependencies:   mbed

Fork of MCP4922_Sinewave by masa miya

Committer:
soulx
Date:
Mon Aug 24 12:36:59 2015 +0000
Revision:
2:2244c8986987
Parent:
1:09b69f38fc73
Child:
3:863a9b7d417a
Child:
5:c4a38038ab44
Triangle wave

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 2:2244c8986987 16 if(i < 0x0FFF)
soulx 2:2244c8986987 17 {
soulx 2:2244c8986987 18 i++;
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 state = ~state;
soulx 2:2244c8986987 25 }
soulx 2:2244c8986987 26
soulx 2:2244c8986987 27 if(state ==0)
soulx 2:2244c8986987 28 {
soulx 2:2244c8986987 29 MCP.writeA(i);
soulx 2:2244c8986987 30 }
soulx 2:2244c8986987 31 else{
soulx 2:2244c8986987 32 MCP.writeA( ((~i)+1)&0x0FFF);
soulx 2:2244c8986987 33 }
soulx 2:2244c8986987 34 wait_us(20);
soulx 2:2244c8986987 35 }
jf1vrr 0:5737b1972549 36 }