2021-08-01 09:52:01 -04:00
|
|
|
//
|
|
|
|
// FILE: MCP4921_VSPI.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-11-26 10:56:37 -05:00
|
|
|
// PURPOSE: test MCP_DAC lib
|
2024-01-20 08:53:57 -05:00
|
|
|
// URL: https://github.com/RobTillaart/MCP_DAC
|
2021-12-21 10:10:14 -05:00
|
|
|
|
2021-08-01 09:52:01 -04:00
|
|
|
|
|
|
|
#ifndef ESP32
|
|
|
|
#error ESP32 only example, please select appropriate board
|
|
|
|
#endif
|
|
|
|
|
2023-11-26 10:56:37 -05:00
|
|
|
|
2021-08-01 09:52:01 -04:00
|
|
|
#include "MCP_DAC.h"
|
|
|
|
|
2023-11-26 10:56:37 -05:00
|
|
|
|
|
|
|
// HSPI uses default SCLK=14, MISO=12, MOSI=13, SELECT=15
|
|
|
|
// VSPI uses default SCLK=18, MISO=19, MOSI=23, SELECT=5
|
|
|
|
SPIClass * myspi = new SPIClass(VSPI);
|
|
|
|
MCP4921 MCP(myspi); // HW SPI
|
2021-08-01 09:52:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
volatile int x;
|
|
|
|
uint32_t start, stop;
|
|
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
|
2024-01-20 08:53:57 -05:00
|
|
|
myspi->begin();
|
|
|
|
|
2023-11-26 10:56:37 -05:00
|
|
|
MCP.begin(5); // 5 for VSPI and 15 for HSPI
|
2021-08-01 09:52:01 -04:00
|
|
|
|
|
|
|
Serial.print("MCP_DAC_LIB_VERSION: ");
|
|
|
|
Serial.println(MCP_DAC_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
Serial.print("CHANNELS:\t");
|
|
|
|
Serial.println(MCP.channels());
|
|
|
|
Serial.print("MAXVALUE:\t");
|
|
|
|
Serial.println(MCP.maxValue());
|
|
|
|
delay(100);
|
|
|
|
|
2023-11-26 10:56:37 -05:00
|
|
|
// MCP.setSPIspeed(100000); // for slower scopes
|
2021-08-01 09:52:01 -04:00
|
|
|
performance_test();
|
|
|
|
|
|
|
|
Serial.println("\nDone...");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void performance_test()
|
|
|
|
{
|
|
|
|
Serial.println();
|
|
|
|
Serial.println(__FUNCTION__);
|
|
|
|
|
|
|
|
start = micros();
|
|
|
|
for (uint16_t value = 0; value < MCP.maxValue(); value++)
|
|
|
|
{
|
2023-12-19 10:59:32 -05:00
|
|
|
x = MCP.write(value, 0);
|
2021-08-01 09:52:01 -04:00
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print(MCP.maxValue());
|
2023-12-19 10:59:32 -05:00
|
|
|
Serial.print(" x MCP.write():\t");
|
2021-08-01 09:52:01 -04:00
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println((stop - start) / (MCP.maxValue() + 1.0) );
|
|
|
|
delay(10);
|
|
|
|
|
|
|
|
start = micros();
|
|
|
|
for (uint16_t value = 0; value < MCP.maxValue(); value++)
|
|
|
|
{
|
|
|
|
MCP.fastWriteA(value);
|
|
|
|
}
|
|
|
|
stop = micros();
|
|
|
|
Serial.print(MCP.maxValue());
|
|
|
|
Serial.print(" x MCP.fastWriteA():\t");
|
|
|
|
Serial.print(stop - start);
|
|
|
|
Serial.print("\t");
|
|
|
|
Serial.println((stop - start) / (MCP.maxValue() + 1.0) );
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
performance_test();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-26 10:56:37 -05:00
|
|
|
// -- END OF FILE --
|
2021-12-21 10:10:14 -05:00
|
|
|
|