with sin wave

Dependencies:   MCP4725 mbed

Fork of test01 by Four Squared

main.cpp

Committer:
xWhitfordx
Date:
2016-11-09
Revision:
2:8fc9f673d972
Parent:
1:c5360811157c

File content as of revision 2:8fc9f673d972:

#include "mbed.h"
#include "mcp4725.h"

/**
 * A test program for the MCP4725 DAC Library. This Test Application requires the following:
 *  * An MCP4725 connected to the I2C bus of the mbed LPC1768.
 *  * The analog out of the MCP1768 connected to Pin15 (analog in) of the mbed LPC1768.
 *  
 *
 * This is a stripped down version of the MCP4725_Library_Test found online, and should make the necessary commands more clear.
 * Last Edited: 12/24/13, Tim Brubaker
 *
 */

DigitalOut testLed(LED1);
Serial pc(USBTX, USBRX);
AnalogIn analogIn(p15);

// Class instantiation (similar to Serial pc(USBTX, USBRX) in function)
MCP4725 bacon(p9, p10, MCP4725::Fast400kHz, 0);
      

int main()
{
    // Print to terminal
    pc.printf("Ready.......FIGHT!\r\n");
    double freqf;
    // if statement
    freqf = 0.5;
    //freqf = 0.05;
 
 
    //if statement
    freqf = freqf/25;
 
 
    while(1) {
        
        testLed = 1;
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.5 ), false);
        
        pc.printf("Value is %f V \r\n",analogIn.read()*3.3);
        
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.625 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.741 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.842 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.922 ), false);
        
        pc.printf("Value is %f V \r\n",analogIn.read()*3.3);
        
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.976 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.999 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.991 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.952 ), false);
        
        pc.printf("Value is %f V \r\n",analogIn.read()*3.3);
        
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.885 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.794 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.684 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.563 ), false);
        
        pc.printf("Value is %f V \r\n",analogIn.read()*3.3);
        
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.437 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.316 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.206 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.115 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.048 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.009 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.001 ), false);
        
        pc.printf("Value is %f V \r\n",analogIn.read()*3.3);
        
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.024 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.078 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.158 ), false);
        
        wait(freqf);
        // Write to DAC register (not EEPROM). Documentation in library files.
        bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.375 ), false);
        

        
        testLed = 0;
        pc.printf("Value is %f V \r\n",analogIn.read()*3.3);
        wait(freqf);
        bacon.write(MCP4725::Normal, (0x000 * (1.0/3.3) ), false);
        
        // Print ADC measurement to terminal. Scale factor of 3.3 needed for internal ADC.
        pc.printf("Value is %f V \r\n",analogIn.read()*3.3);
    }
}