test00

Dependencies:   MCP4725 mbed

Fork of test01 by Four Squared

Committer:
xWhitfordx
Date:
Wed Nov 02 17:56:38 2016 +0000
Revision:
1:c5360811157c
Parent:
0:77006df50c28
Child:
2:76f0ff8c3068
Sq wave success

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xWhitfordx 0:77006df50c28 1 #include "mbed.h"
xWhitfordx 0:77006df50c28 2 #include "mcp4725.h"
xWhitfordx 0:77006df50c28 3
xWhitfordx 0:77006df50c28 4 /**
xWhitfordx 0:77006df50c28 5 * A test program for the MCP4725 DAC Library. This Test Application requires the following:
xWhitfordx 0:77006df50c28 6 * * An MCP4725 connected to the I2C bus of the mbed LPC1768.
xWhitfordx 0:77006df50c28 7 * * The analog out of the MCP1768 connected to Pin15 (analog in) of the mbed LPC1768.
xWhitfordx 0:77006df50c28 8 *
xWhitfordx 0:77006df50c28 9 *
xWhitfordx 0:77006df50c28 10 * This is a stripped down version of the MCP4725_Library_Test found online, and should make the necessary commands more clear.
xWhitfordx 0:77006df50c28 11 * Last Edited: 12/24/13, Tim Brubaker
xWhitfordx 0:77006df50c28 12 *
xWhitfordx 0:77006df50c28 13 */
xWhitfordx 0:77006df50c28 14
xWhitfordx 0:77006df50c28 15 DigitalOut testLed(LED1);
xWhitfordx 0:77006df50c28 16 Serial pc(USBTX, USBRX);
xWhitfordx 0:77006df50c28 17 AnalogIn analogIn(p15);
xWhitfordx 0:77006df50c28 18
xWhitfordx 0:77006df50c28 19 // Class instantiation (similar to Serial pc(USBTX, USBRX) in function)
xWhitfordx 0:77006df50c28 20 MCP4725 bacon(p9, p10, MCP4725::Fast400kHz, 0);
xWhitfordx 0:77006df50c28 21
xWhitfordx 0:77006df50c28 22
xWhitfordx 0:77006df50c28 23 int main()
xWhitfordx 0:77006df50c28 24 {
xWhitfordx 0:77006df50c28 25 // Print to terminal
xWhitfordx 0:77006df50c28 26 pc.printf("Ready.......FIGHT!\r\n");
xWhitfordx 1:c5360811157c 27 double freqf;
xWhitfordx 1:c5360811157c 28 // if statement
xWhitfordx 1:c5360811157c 29 //freqf = 0.5;
xWhitfordx 1:c5360811157c 30 freqf = 0.05;
xWhitfordx 1:c5360811157c 31
xWhitfordx 1:c5360811157c 32
xWhitfordx 1:c5360811157c 33
xWhitfordx 1:c5360811157c 34
xWhitfordx 0:77006df50c28 35
xWhitfordx 0:77006df50c28 36 while(1) {
xWhitfordx 1:c5360811157c 37
xWhitfordx 0:77006df50c28 38 testLed = 1;
xWhitfordx 1:c5360811157c 39 wait(freqf);
xWhitfordx 0:77006df50c28 40 // Write to DAC register (not EEPROM). Documentation in library files.
xWhitfordx 1:c5360811157c 41 bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) ), false);
xWhitfordx 0:77006df50c28 42 testLed = 0;
xWhitfordx 1:c5360811157c 43 pc.printf("Value is %f V \r\n",analogIn.read()*3.3);
xWhitfordx 1:c5360811157c 44 wait(freqf);
xWhitfordx 1:c5360811157c 45 bacon.write(MCP4725::Normal, (0x000 * (1.0/3.3) ), false);
xWhitfordx 1:c5360811157c 46
xWhitfordx 0:77006df50c28 47 // Print ADC measurement to terminal. Scale factor of 3.3 needed for internal ADC.
xWhitfordx 0:77006df50c28 48 pc.printf("Value is %f V \r\n",analogIn.read()*3.3);
xWhitfordx 0:77006df50c28 49 }
xWhitfordx 0:77006df50c28 50 }