RobTillaart / AD985X

Arduino library for AD9850 and AD9851 function generators.
MIT License
12 stars 2 forks source link
arduino function-generator waveform

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

AD985X

Arduino library for AD9850 and AD9851 function generators.

Description

Library for the AD9850 and AD9851 function generators. These devices can produce a square and a sine wave

type max freq phase (step size) Notes
AD9850 40 MHz 0..31 x 11.25°
AD9851 70 MHz 0..31 x 11.25° has more options.

Note that at the max frequency the devices do not give a nice sine any more. You need to check what is acceptable for your project.

The library has a AD9850 as base class that implements the commonalities. The AD9851 is derived and has its own setFrequency() methods. Furthermore the AD9851 also has function to select the reference clock, a feature the AD9850 does not have. This feature improves the tuning for both low and high frequencies.

Warning The library is not suitable for AD9852 as that is a function generator with way more functionality.

Note: mainly tested on Arduino UNO.

0.5.0 Breaking change

Version 0.5.0 introduced a breaking change to improve handling the SPI dependency. The user has to call SPI.begin() or equivalent before calling AD.begin(). Optionally the user can provide parameters to the SPI.begin(...)

0.4.0 Breaking change

The version 0.4.0 has breaking changes in the interface. The essence is removal of ESP32 specific code from the library. Furthermore it moved parameters from begin() to the constructor. Finally made a specific constructor for HW SPI and SW SPI. This makes it possible to support the ESP32-S3 and other processors in the future. Also it makes the library a bit simpler to maintain.

Connection

Schema break-out

          TOP VIEW
        +-----------+
        |   X-TAL   |
        |         L |
    VCC | o       o | VCC
    CLK | o       o | D0
   PUFD | o       o | D1
   DATA | o       o | D2
  RESET | o       o | D3
    GND | o CCC   o | D4
  QOUT1 | o CCC   o | D5
  QOUT2 | o       o | D6
  ZOUT1 | o       o | D7 ----- SELECT SERIAL LOW
  ZOUT2 | o  PP   o | GND
        |    PP     |
        +-----------+

  XTAL = crystal
  L    = LED
  C    = chip
  P    = potentiometer => for duty cycle square wave

Related

Multi device

See Multi_AD985X_devices.pdf

Discussion leading to the document see - https://github.com/RobTillaart/AD985X/issues/13

The AD985X board can be connected with a SPI bus like interface. However there is no Chip Select pin (CS) so one must take other measures to control multiple AD985X devices.

Trivial solution

The trivial implementation is to give each device a set of unique pins. If you have pins to spare this is the perfect solution.

Shared line solution

A more common SPI solution is to share the data and clock lines. However that would typical set all AD985X devices simultaneously. So extra hardware is needed to prevent this.

A possible solution is to put all needed lines behind an AND port that allows only communication when the SELECT is HIGH.

     Arduino        AND           AD985X
--------------------------------------------------

                +--------+
     SELECT ----| A      |
                |      Y |------- DATA
     DATA  -----| B      |
                +--------+

                +--------+
     SELECT ----| A      |
                |      Y |------- CLOCK
     CLOCK  ----| B      |
                +--------+

                +--------+
     SELECT ----| A      |
                |      Y |------- FQ_UD
     FQ_UD  ----| B      |
                +--------+

                +--------+
     SELECT ----| A      |
                |      Y |------- RESET
     RESET  ----| B      |
                +--------+

The DATA line of the device is connected to the output of an AND port.
The inputs if the AND port are (a) the SPI bus DATA line and (b) the SELECT pin.
Strictly for the DATA this is not needed as data will only clock in if there is a CLOCK.

The CLOCK pin of the device is connected to the output of an AND port.
The inputs if the AND port are (a) the SPI bus CLOCK line and (b) the SELECT pin.

The FQ_UD pin of the device is connected to the output of an AND port.
The inputs if the AND port are (a) the MCU FQ_UD line and (b) the SELECT pin. See FQ_UD note below.

The RESET pin of the device is connected to the output of an AND port.
The inputs if the AND port are (a) the MCU RESET line and (b) the SELECT pin.

A typical IC to use is the 74HC08 which has 4 AND ports in it.

In short this setup makes the lines 'switchable' pass through, with the SELECT line. It allows to have multiple AD985X devices, and even to share the SPI bus DATA and CLOCK lines with other SPI devices.

FQ_UD note

It might be possible to connect a single FQ_UD line to multiple AD985X devices directly. The FQ_UD pulse would update the frequency and as this register is not changed, the FQ_UD pulse might just have no changing effect. To be investigated to confirm this.

If confirmed this would change the above Shared line solution a bit.

If the FQ_UD line can be shared directly it offers a way to start / change multiple devices at the same time.

Interface

#include "AD985X.h"

Constructors

Common interface

Calibration

Warning: use with care.

Note: reset() resets the offset to 0.. Note: setting the offset reduces the range of frequencies (at the ends of scale).

Auto update / manual update

(new since 0.2.2)

Warning: use with care.

Manual updating allows one to prepare the frequency, and actually apply it at a later moment.

Note: The default of the autoUpdate flag is true.
Note: reset() resets the autoUpdateFlag to true.

Hardware SPI

To be used only if one needs a specific speed.

AD9851 additional

Operation

See examples.

Operational notes

Future

Must

Should

Could

Wont

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,