gen triangle wave

Dependencies:   mbed

Fork of MCP4922_Sinewave by masa miya

main.cpp

Committer:
PKnevermind
Date:
2015-11-05
Revision:
4:bf75b2a7d8b5
Parent:
3:863a9b7d417a

File content as of revision 4:bf75b2a7d8b5:


#include "mbed.h"
#include "MCP4922.h"

MCP4922 MCP(SPI_MOSI, SPI_SCK,SPI_CS);  // MOSI, SCLK, CS


/**** Main Function  ***/
int main(void)
{
    MCP.frequency(10000000);

    uint16_t i=0;
    uint8_t state=0;
    while(1) {
        if(i < 0x0FFF)
        {
            i++;
            
        }
        else
        {
            i=0;
            state = ~state;
        }
        
        if(state ==0)
        {
            MCP.writeA(i);
            }
            else{
           MCP.writeA( ((~i)+1)&0x0FFF);
          }
            wait_us(20);
    }
}