Open thechordmaster opened 17 hours ago
Do you know the difference between software SPI and hardware SPI?
If you have a scope you should be able to determine the SPI pins used.
Stripped version that uses the software SPI pins (5 = CS, 6 = DATA, 7 = CLOCK).
You should see the pulses of the three lines on the scope. If not there is a problem with your board.
//
// FILE: AD5620_sawtooth.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test basic behaviour and performance
// URL: https://github.com/RobTillaart/AD5620
#include "AD5620.h"
AD5620 AD16_SW(5, 6, 7);
float frequency = 50;
float amplitude = 4095; // 12 bits
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("AD5620_LIB_VERSION: ");
Serial.println(AD5620_LIB_VERSION);
AD16_SW.begin();
Serial.print("HWSPI: ");
Serial.println(AD16_SW.usesHWSPI());
}
void loop()
{
float period = 1000000.0 / frequency;
float value = fmod(millis(), period); // 0..period
// value = period - value; // reverse
value = amplitude * value / period;
AD16_SW.setValue(value);
Serial.println(value);
delay(1);
}
// -- END OF FILE --
With this sketch you should be able to see signals on
//
// FILE: AD5620_sawtooth.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test basic behaviour and performance
// URL: https://github.com/RobTillaart/AD5620
AD5620 AD16_HW(8, &SPI); AD5620 AD16_SW(5, 6, 7);
float frequency = 50; float amplitude = 4095; // 12 bits
void setup() { Serial.begin(115200); Serial.println(); Serial.println(FILE); Serial.print("AD5620_LIB_VERSION: "); Serial.println(AD5620_LIB_VERSION);
SPI.begin(); AD16_HW.setSPIspeed(50000); AD16_HW.begin(); AD16_SW.begin();
Serial.print("HWSPI: "); Serial.println(AD16_HW.usesHWSPI()); Serial.print("HWSPI: "); Serial.println(AD16_SW.usesHWSPI()); }
void loop() { float period = 1000000.0 / frequency; float value = fmod(millis(), period); // 0..period // value = period - value; // reverse
value = amplitude * value / period; AD16_SW.setValue(value); AD16_HW.setValue(value); Serial.println(value); delay(1); }
// -- END OF FILE --
clock something like
data something like
Between the two data bytes there is a very small moment HIGH (in the middle).
Found a bug in the library
from datasheet In a normal write sequence for the AD5660, the SYNC line is kept low for at least 24 falling edges of SCLK, and the DAC is updated on the 24th falling edge. However, if SYNC is brought high before the 24th falling edge, this acts as an interrupt to the write sequence.
As there are only 2 data bytes to send I bring the sync high after the 16th bit so the device is reset. So I will create a develop branch which sends three bytes asap.
24 bits clocks out perfectly (no pull ups cause jitter)
@thechordmaster
Please give the develop branch a try.
Root cause is building code on the picture, which shows 16 bit for the AD5620 and AD5640.
@thechordmaster Bumped the version number in the develop branch to 0.2.0 as this is a breaking change.
I tried running the example code(sawtooth) wired the setup as below:
5620 - UNO CLK - SCK (ICSP HEADER PIN) DIN - MOSI (ICSP HEADER PIN) SYNC - PIN 8 OF THE UNO (As per the line in the example AD5620 AD16_HW(8, &SPI);) Vdd - 3v3 pin GND - GND
Tried measuring with an oscilloscope at Vout and GND - only get an erratic waveform that does not correlate with the frequency specified in code. Am I doing something wrong? Should I be editing the AD5620 AD16_SW(5, 6, 7); line?