Four Squared
/
SinTest
with sin wave
Fork of test01 by
main.cpp@2:8fc9f673d972, 2016-11-09 (annotated)
- Committer:
- xWhitfordx
- Date:
- Wed Nov 09 18:54:40 2016 +0000
- Revision:
- 2:8fc9f673d972
- Parent:
- 1:c5360811157c
With sin wave
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:8fc9f673d972 | 29 | freqf = 0.5; |
xWhitfordx | 2:8fc9f673d972 | 30 | //freqf = 0.05; |
xWhitfordx | 1:c5360811157c | 31 | |
xWhitfordx | 1:c5360811157c | 32 | |
xWhitfordx | 2:8fc9f673d972 | 33 | //if statement |
xWhitfordx | 2:8fc9f673d972 | 34 | freqf = freqf/25; |
xWhitfordx | 1:c5360811157c | 35 | |
xWhitfordx | 0:77006df50c28 | 36 | |
xWhitfordx | 0:77006df50c28 | 37 | while(1) { |
xWhitfordx | 1:c5360811157c | 38 | |
xWhitfordx | 0:77006df50c28 | 39 | testLed = 1; |
xWhitfordx | 1:c5360811157c | 40 | wait(freqf); |
xWhitfordx | 0:77006df50c28 | 41 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 42 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.5 ), false); |
xWhitfordx | 2:8fc9f673d972 | 43 | |
xWhitfordx | 2:8fc9f673d972 | 44 | pc.printf("Value is %f V \r\n",analogIn.read()*3.3); |
xWhitfordx | 2:8fc9f673d972 | 45 | |
xWhitfordx | 2:8fc9f673d972 | 46 | |
xWhitfordx | 2:8fc9f673d972 | 47 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 48 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 49 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.625 ), false); |
xWhitfordx | 2:8fc9f673d972 | 50 | |
xWhitfordx | 2:8fc9f673d972 | 51 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 52 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 53 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.741 ), false); |
xWhitfordx | 2:8fc9f673d972 | 54 | |
xWhitfordx | 2:8fc9f673d972 | 55 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 56 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 57 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.842 ), false); |
xWhitfordx | 2:8fc9f673d972 | 58 | |
xWhitfordx | 2:8fc9f673d972 | 59 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 60 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 61 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.922 ), false); |
xWhitfordx | 2:8fc9f673d972 | 62 | |
xWhitfordx | 2:8fc9f673d972 | 63 | pc.printf("Value is %f V \r\n",analogIn.read()*3.3); |
xWhitfordx | 2:8fc9f673d972 | 64 | |
xWhitfordx | 2:8fc9f673d972 | 65 | |
xWhitfordx | 2:8fc9f673d972 | 66 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 67 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 68 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.976 ), false); |
xWhitfordx | 2:8fc9f673d972 | 69 | |
xWhitfordx | 2:8fc9f673d972 | 70 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 71 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 72 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.999 ), false); |
xWhitfordx | 2:8fc9f673d972 | 73 | |
xWhitfordx | 2:8fc9f673d972 | 74 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 75 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 76 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.991 ), false); |
xWhitfordx | 2:8fc9f673d972 | 77 | |
xWhitfordx | 2:8fc9f673d972 | 78 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 79 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 80 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.952 ), false); |
xWhitfordx | 2:8fc9f673d972 | 81 | |
xWhitfordx | 2:8fc9f673d972 | 82 | pc.printf("Value is %f V \r\n",analogIn.read()*3.3); |
xWhitfordx | 2:8fc9f673d972 | 83 | |
xWhitfordx | 2:8fc9f673d972 | 84 | |
xWhitfordx | 2:8fc9f673d972 | 85 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 86 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 87 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.885 ), false); |
xWhitfordx | 2:8fc9f673d972 | 88 | |
xWhitfordx | 2:8fc9f673d972 | 89 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 90 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 91 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.794 ), false); |
xWhitfordx | 2:8fc9f673d972 | 92 | |
xWhitfordx | 2:8fc9f673d972 | 93 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 94 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 95 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.684 ), false); |
xWhitfordx | 2:8fc9f673d972 | 96 | |
xWhitfordx | 2:8fc9f673d972 | 97 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 98 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 99 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.563 ), false); |
xWhitfordx | 2:8fc9f673d972 | 100 | |
xWhitfordx | 2:8fc9f673d972 | 101 | pc.printf("Value is %f V \r\n",analogIn.read()*3.3); |
xWhitfordx | 2:8fc9f673d972 | 102 | |
xWhitfordx | 2:8fc9f673d972 | 103 | |
xWhitfordx | 2:8fc9f673d972 | 104 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 105 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 106 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.437 ), false); |
xWhitfordx | 2:8fc9f673d972 | 107 | |
xWhitfordx | 2:8fc9f673d972 | 108 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 109 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 110 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.316 ), false); |
xWhitfordx | 2:8fc9f673d972 | 111 | |
xWhitfordx | 2:8fc9f673d972 | 112 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 113 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 114 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.206 ), false); |
xWhitfordx | 2:8fc9f673d972 | 115 | |
xWhitfordx | 2:8fc9f673d972 | 116 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 117 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 118 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.115 ), false); |
xWhitfordx | 2:8fc9f673d972 | 119 | |
xWhitfordx | 2:8fc9f673d972 | 120 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 121 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 122 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.048 ), false); |
xWhitfordx | 2:8fc9f673d972 | 123 | |
xWhitfordx | 2:8fc9f673d972 | 124 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 125 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 126 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.009 ), false); |
xWhitfordx | 2:8fc9f673d972 | 127 | |
xWhitfordx | 2:8fc9f673d972 | 128 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 129 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 130 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.001 ), false); |
xWhitfordx | 2:8fc9f673d972 | 131 | |
xWhitfordx | 2:8fc9f673d972 | 132 | pc.printf("Value is %f V \r\n",analogIn.read()*3.3); |
xWhitfordx | 2:8fc9f673d972 | 133 | |
xWhitfordx | 2:8fc9f673d972 | 134 | |
xWhitfordx | 2:8fc9f673d972 | 135 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 136 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 137 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.024 ), false); |
xWhitfordx | 2:8fc9f673d972 | 138 | |
xWhitfordx | 2:8fc9f673d972 | 139 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 140 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 141 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.078 ), false); |
xWhitfordx | 2:8fc9f673d972 | 142 | |
xWhitfordx | 2:8fc9f673d972 | 143 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 144 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 145 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.158 ), false); |
xWhitfordx | 2:8fc9f673d972 | 146 | |
xWhitfordx | 2:8fc9f673d972 | 147 | wait(freqf); |
xWhitfordx | 2:8fc9f673d972 | 148 | // Write to DAC register (not EEPROM). Documentation in library files. |
xWhitfordx | 2:8fc9f673d972 | 149 | bacon.write(MCP4725::Normal, (0xFFF * (1.0/3.32) * 0.375 ), false); |
xWhitfordx | 2:8fc9f673d972 | 150 | |
xWhitfordx | 2:8fc9f673d972 | 151 | |
xWhitfordx | 2:8fc9f673d972 | 152 | |
xWhitfordx | 0:77006df50c28 | 153 | testLed = 0; |
xWhitfordx | 1:c5360811157c | 154 | pc.printf("Value is %f V \r\n",analogIn.read()*3.3); |
xWhitfordx | 1:c5360811157c | 155 | wait(freqf); |
xWhitfordx | 1:c5360811157c | 156 | bacon.write(MCP4725::Normal, (0x000 * (1.0/3.3) ), false); |
xWhitfordx | 1:c5360811157c | 157 | |
xWhitfordx | 0:77006df50c28 | 158 | // Print ADC measurement to terminal. Scale factor of 3.3 needed for internal ADC. |
xWhitfordx | 0:77006df50c28 | 159 | pc.printf("Value is %f V \r\n",analogIn.read()*3.3); |
xWhitfordx | 0:77006df50c28 | 160 | } |
xWhitfordx | 0:77006df50c28 | 161 | } |