RobTillaart / AD5620

Arduino library for AD5620 / AD5640 Digital Analog Convertor (12/14 bit).
MIT License
2 stars 0 forks source link

Testing the examples with a UNO #8

Open thechordmaster opened 17 hours ago

thechordmaster commented 17 hours ago

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?

RobTillaart commented 16 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.

  1. Disconnect the device
  2. Start the sawtooth example
  3. check all pins to see where the clock signal is (train of 8 pulses)
  4. check all pins to see where the data pins is (variable set of pulses)
RobTillaart commented 16 hours ago

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 --
RobTillaart commented 16 hours ago

With this sketch you should be able to see signals on

include "AD5620.h"

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 --

RobTillaart commented 16 hours ago

clock something like ad5620 clock

RobTillaart commented 16 hours ago

data something like ad5620 data

RobTillaart commented 16 hours ago

Between the two data bytes there is a very small moment HIGH (in the middle).

RobTillaart commented 16 hours ago

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.

RobTillaart commented 15 hours ago

24 bits clocks out perfectly (no pull ups cause jitter)

ad5620 data clock

RobTillaart commented 15 hours ago

@thechordmaster

Please give the develop branch a try.

RobTillaart commented 15 hours ago

Root cause is building code on the picture, which shows 16 bit for the AD5620 and AD5640.

image

RobTillaart commented 10 hours ago

@thechordmaster Bumped the version number in the develop branch to 0.2.0 as this is a breaking change.