GY-63_MS5611/libraries/MCP4725/examples/mcp4725_test/mcp4725_test.ino

297 lines
6.4 KiB
Arduino
Raw Normal View History

//
// FILE: mcp4725_test.ino
// AUTHOR: Rob Tillaart
2020-11-27 05:20:37 -05:00
// VERSION: 0.1.5
// PURPOSE: test mcp4725 lib
// DATE: 2013-11-24
2020-11-27 05:20:37 -05:00
// URL: https://github.com/RobTillaart/MCP4725
//
2020-11-27 05:20:37 -05:00
#include "Wire.h"
#include "MCP4725.h"
MCP4725 DAC(0x62); // 0x62 or 0x63
2020-11-27 05:20:37 -05:00
volatile int x;
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
Serial.print("MCP4725 test program: ");
Serial.println(MCP4725_VERSION);
DAC.begin();
2020-11-27 05:20:37 -05:00
test1();
test2();
test3();
test4();
test5();
test6();
}
2020-11-27 05:20:37 -05:00
void test1()
{
Serial.print("\nValue:\t");
Serial.println(DAC.getValue());
Serial.println();
2020-11-27 05:20:37 -05:00
for (int i = 100; i < 500; i += 100)
{
Serial.print("setValue(");
Serial.print(i);
Serial.print(")\n");
DAC.setValue(i);
Serial.print("Value:\t");
Serial.println(DAC.getValue());
}
Serial.println();
2020-11-27 05:20:37 -05:00
}
2020-11-27 05:20:37 -05:00
void test2()
{
Serial.println("\n\nMCP4725_II\n\n");
2020-11-27 05:20:37 -05:00
for (int i = 100; i < 500; i += 100)
{
Serial.print("writeDAC(");
Serial.print(i);
Serial.print(")\n");
DAC.writeDAC(i);
Serial.print("DACValue:\t");
Serial.println(DAC.readDAC());
Serial.print("EEValue:\t");
2020-11-27 05:20:37 -05:00
Serial.println(DAC.readEEPROM());
}
Serial.println();
2020-11-27 05:20:37 -05:00
for (int i = 100; i < 500; i += 100)
{
Serial.print("writeDAC(");
Serial.print(i);
Serial.print(", true)\n");
DAC.writeDAC(i, true);
Serial.print("DACValue:\t");
Serial.println(DAC.readDAC());
Serial.print("EEValue:\t");
2020-11-27 05:20:37 -05:00
Serial.println(DAC.readEEPROM());
}
Serial.println();
Serial.println("writeDAC(200)");
DAC.writeDAC(200);
Serial.print("DACValue:\t");
Serial.println(DAC.readDAC());
Serial.print("EEValue:\t");
2020-11-27 05:20:37 -05:00
Serial.println(DAC.readEEPROM());
Serial.println();
2020-11-27 05:20:37 -05:00
}
2020-11-27 05:20:37 -05:00
void test3()
{
Serial.println("\n\nMCP4725_POWERDOWNMODE\n\n");
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 4; i++)
{
Serial.print("DAC.writePowerDownMode(");
Serial.print(i);
Serial.println(")");
DAC.writePowerDownMode(i);
Serial.print("EPR PDM Value:\t");
Serial.println(DAC.readPowerDownModeEEPROM());
Serial.println();
}
2020-11-27 05:20:37 -05:00
Serial.println("\n\nEXPERIMENTAL");
Serial.println("DAC.writePowerDownMode(3)");
DAC.writePowerDownMode(3);
DAC.writeDAC(305);
Serial.print("Value:\t");
Serial.println(DAC.getValue());
Serial.println("DAC.powerOnReset()");
Serial.println("Before");
Serial.print("DAC PDM Value:\t");
Serial.println(DAC.readPowerDownModeDAC());
Serial.print("EPR PDM Value:\t");
Serial.println(DAC.readPowerDownModeEEPROM());
Serial.print("DACValue:\t");
Serial.println(DAC.readDAC());
Serial.print("EEValue:\t");
2020-11-27 05:20:37 -05:00
Serial.println(DAC.readEEPROM());
DAC.powerOnReset();
Serial.println("After");
Serial.print("DAC PDM Value:\t");
Serial.println(DAC.readPowerDownModeDAC());
Serial.print("EPR PDM Value:\t");
Serial.println(DAC.readPowerDownModeEEPROM());
Serial.print("DACValue:\t");
Serial.println(DAC.readDAC());
Serial.print("EEValue:\t");
2020-11-27 05:20:37 -05:00
Serial.println(DAC.readEEPROM());
Serial.print("Value:\t");
Serial.println(DAC.getValue());
Serial.println();
2020-11-27 05:20:37 -05:00
}
2020-11-27 05:20:37 -05:00
void test4()
{
Serial.println("\n\nEXPERIMENTAL");
Serial.println("DAC.writePowerDownMode(2)");
DAC.writePowerDownMode(2);
DAC.writeDAC(405);
Serial.print("Value:\t");
Serial.println(DAC.getValue());
Serial.println("DAC.powerOnWakeUp()");
Serial.println("Before");
Serial.print("DAC PDM Value:\t");
Serial.println(DAC.readPowerDownModeDAC());
Serial.print("EPR PDM Value:\t");
Serial.println(DAC.readPowerDownModeEEPROM());
Serial.print("DACValue:\t");
Serial.println(DAC.readDAC());
Serial.print("EEValue:\t");
2020-11-27 05:20:37 -05:00
Serial.println(DAC.readEEPROM());
DAC.powerOnWakeUp();
Serial.println("after");
Serial.print("DAC PDM Value:\t");
Serial.println(DAC.readPowerDownModeDAC());
Serial.print("EPR PDM Value:\t");
Serial.println(DAC.readPowerDownModeEEPROM());
Serial.print("DACValue:\t");
Serial.println(DAC.readDAC());
Serial.print("EEValue:\t");
2020-11-27 05:20:37 -05:00
Serial.println(DAC.readEEPROM());
Serial.print("Value:\t");
Serial.println(DAC.getValue());
Serial.println();
2020-11-27 05:20:37 -05:00
}
2020-11-27 05:20:37 -05:00
void test5()
{
Serial.println("\n\nPERFORMANCE");
Serial.println();
2020-11-27 05:20:37 -05:00
start = micros();
for (int i = 0; i < 1000; i++)
{
2020-11-27 05:20:37 -05:00
x = DAC.getValue();
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("1000x DAC.getValue():\t\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
start = micros();
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 1000; i++)
{
DAC.setValue(i);
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("1000x DAC.setValue(i):\t\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
start = micros();
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 1000; i++)
{
DAC.setValue(1000);
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("1000x DAC.setValue(1000):\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
start = micros();
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 1000; i++)
{
2020-11-27 05:20:37 -05:00
x = DAC.readDAC();
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("1000x DAC.readDAC():\t\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
start = micros();
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 1000; i++)
{
2020-11-27 05:20:37 -05:00
x = DAC.writeDAC(i);
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("1000x DAC.writeDAC(i):\t\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
start = micros();
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 10; i++)
{
2020-11-27 05:20:37 -05:00
x = DAC.writeDAC(i, true);
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("10x DAC.writeDAC(i, true):\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
start = micros();
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 1000; i++)
{
2020-11-27 05:20:37 -05:00
x = DAC.ready();
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("1000x DAC.ready():\t\t");
Serial.println(stop - start);
2020-11-27 05:20:37 -05:00
while (!DAC.ready());
DAC.writeDAC(0, true);
start = micros();
2020-11-27 05:20:37 -05:00
while (!DAC.ready());
stop = micros();
Serial.print("EEPROM write latency:\t\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
}
2020-11-27 05:20:37 -05:00
void test6()
{
Serial.println("\n\nEXPERIMENTAL II");
start = micros();
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 10; i++)
{
2020-11-27 05:20:37 -05:00
x = DAC.readPowerDownModeDAC();
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("10x DAC.readPowerDownModeDAC():\t\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
start = micros();
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 10; i++)
{
2020-11-27 05:20:37 -05:00
x = DAC.readPowerDownModeEEPROM();
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("10x DAC.readPowerDownModeEEPROM():\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
start = micros();
2020-11-27 05:20:37 -05:00
for (int i = 0; i < 10; i++)
{
2020-11-27 05:20:37 -05:00
x = DAC.writePowerDownMode(i & 0x03);
}
2020-11-27 05:20:37 -05:00
stop = micros();
Serial.print("10x DAC.writePowerDownMode(i):\t\t");
2020-11-27 05:20:37 -05:00
Serial.println(stop - start);
Serial.print("\nDone... (start triangle mode)");
}
2020-11-27 05:20:37 -05:00
void loop()
{
2020-11-27 05:20:37 -05:00
for (uint16_t i = 0; i < 4096; i++)
2013-11-30 16:21:07 -05:00
{
DAC.setValue(i);
delay(10);
}
2020-11-27 05:20:37 -05:00
for (uint16_t i = 0; i < 4096; i++)
2013-11-30 16:21:07 -05:00
{
DAC.setValue(4096 - i);
delay(10);
}
}
2020-11-27 05:20:37 -05:00
// -- END OF FILE --