Reference

This section provides the link to the AD9837 Arduino library, lists all the API functions of the AD9837 Arduino library, as well as the compatibility test list for this product.

Library

Download and install the DFRobot AD9837 Library. (About how to install the library?)

API Description

/************************ Init ********************************/
  /**
   * @fn DFRobot_AD9837
   * @brief Constructor
   * @param fscPin - active-low control pin, pull down for SPI data transfer
   * @param pSpi - extern SPIClass SPI is defined in SPI.h; so just get SPI object address and the methods in SPI can be pointed to and used
   * @return None
   */
  DFRobot_AD9837(int8_t fscPin=5, SPIClass *pSpi=&SPI);

  /**
   * @fn begin
   * @brief Init function, including SPI communication init, module power-on reset
   * @param frequency - the maximum frequency of SPI communication
   * @return None
   */
  void begin(uint32_t frequency=20000000);

/************************** Config function ******************************/
  /**
   * @fn moduleReset
   * @brief Reset internal registers to 0, this corresponds to an analog output of midscale.
   * @param mode - eReset_EN: reset internal register; eReset_DIS: quit reset status
   * @return None
   * @note RESET operation will not reset the phase, frequency, or control register.
   */
  void moduleReset(eControlRegBit_t mode=eReset_DIS);

  /**
   * @fn moduleSleep
   * @brief The parts of AD9837 that are not in use like the internal clock and DAC can be powered down through the sleep function to minimize power consumption. 
   * @param MCLK - eSleepMCLK_NO: enable internal MCLK; eSleepMCLK_YES: disable internal MCLK. The DAC output remains at its present value as the NCO is no longer
   * @     accumulating.
   * @param dacMode - eSleepDAC_NO: keep DAC active; eSleepDAC_YES: power down on-chip DAC. This is useful when AD9837 is used to output MSB of DAC data.
   * @return None
   * @note  RESET operation will not reset the phase, frequency, or control register.
   */
  void moduleSleep(eControlRegBit_t MCLK=eSleepMCLK_NO, eControlRegBit_t dacMode=eSleepDAC_NO);

/************************** Performance function ******************************/
  /**
   * @fn outputSin
   * @brief OUT  The pin outputs sine wave
   * @param phase - Adjust phase offset, range: 0-360, unit: degree (corresponding to waveform phase offset of 0-2π)
   * @param freq - wave frequency, range: 0.06-8000000.00, unit: Hz
   * @return None
   * @note Recommended frequency range: 60-600000Hz, actual resolution is about 0.06Hz, which is obtained by dividing 16MHz by 2^28 
   */
  void outputSin(uint16_t phase, float freq);

  /**
   * @fn outputTriangle
   * @brief OUT  The pin outputs triangle wave
   * @param phase - adjust phase offset, range: 0-360, unit: degree (corresponding to waveform phase offset of 0-2π)
   * @param freq - wave frequency, range: 0.06-8000000.00, unit: Hz
   * @return None
   * @note Recommended frequency range: 60-600000Hz, actual resolution is about 0.06Hz, which is obtained by dividing 16MHz by 2^28
   */
  void outputTriangle(uint16_t phase, float freq);

  /**
   * @fn outputSquare
   * @brief OUT  The pin outputs square wave
   * @param divide - eDIV2_2: MSB/2 of DAC data is output through VOUT pin; eDIV2_1: MSB of DAC data is output via VOUT pin.
   * @param phase - adjust phase offset, range: 0-360, unit: degree (corresponding to waveform phase offset of 0-2π)
   * @param freq - wave frequency, range: 0.06-8000000.00, unit: Hz
   * @return None
   * @note Recommended frequency range: 60-600000Hz, actual resolution is about 0.06Hz, which is obtained by dividing 16MHz by 2^28
   */
  void outputSquare(eControlRegBit_t divide, uint16_t phase, float freq);

Principle

DDS

Direct digital synthesis (DDS) is a method of producing an analog waveform—usually a sine wave—by generating a time-varying signal in digital form and then performing a digital-to-analog conversion.

The ability to accurately produce and control waveforms of various frequencies and profiles has become a key requirement common to a number of industries. Whether providing agile sources of low-phase-noise variable-frequencies with good spurious performance for communications, or simply generating a frequency stimulus in industrial or biomedical test equipment applications, convenience, compactness, and low cost are important design considerations.

DAC

In electronics, a digital-to-analog converter (DAC, D/A, D2A, or D-to-A) is a system that converts a digital signal into an analog signal. DACs are commonly used in music players to convert digital data streams into analog audio signals

Sine Wave

A sine wave consists of a single frequency only. It is a mathematical curve defined in terms of the sine trigonometric function. Any complex signal, such as spectral signal, can be regarded as composed of many sine waves with different frequencies and sizes. For example, the household electricity we use every day is a sine wave AC with a frequency of 50Hz.

MCU Work Well Work Wrong Untested Remarks
Arduino UNO
Arduino MEGA2560
Arduino Leonardo
FireBeetle-ESP8266
FireBeetle-ESP32
FireBeetle-M0
Micro:bit

Was this article helpful?

TOP