//waveform generator // hacked from https://www.instructables.com/Arduino-Waveform-Generator-1/ #include #include Adafruit_MCP4728 mcp; #define nsamp 256 #define dacmax 256 const byte nclk=42; //number of clock cycles of the loop long int freq; //frequency in mHz long unsigned int phase; long unsigned int phase_inc; void setup() { //TIMSK0 &= ~_BV(TOIE0); // disable timer0 overflow interrupt //Wire.setClock(1400000L); // wooooo Serial.begin(115200); while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens // Try to initialize! if (!mcp.begin(0x64)) { Serial.println("Failed to find MCP4728 chip"); while (1) { delay(10); } } else { Serial.println("Adafruit MCP4728 initialised"); } freq=660; phase=0; calc_phase_inc(); //phase_inc = 1; setwave(); } const float pi=3.14159265; byte waveform[nsamp]; void setwave(){ for (int isamp=0; isamp> 24; phase += analogRead(A0); int redphase = phase % nsamp; mcp.fastWrite(waveform[redphase] << 4, 0, 0, 0); }