Crates.io | ad983x |
lib.rs | ad983x |
version | 1.0.0 |
source | src |
created_at | 2019-05-29 16:35:04.355151 |
updated_at | 2024-05-04 18:31:47.367793 |
description | Platform-agnostic Rust driver for the AD9833, AD9834, AD9837 and AD9838 low-power programmable waveform generators / direct digital synthesizers. |
homepage | https://github.com/eldruin/ad983x-rs |
repository | https://github.com/eldruin/ad983x-rs |
max_upload_size | |
id | 137732 |
size | 65,619 |
This is a platform agnostic Rust driver for the AD9833, AD9834, AD9837 and AD9838 low-power programmable waveform generators / direct digital synthesizers (DDS) using the embedded-hal
traits.
This driver allows you to:
enable()
.set_frequency()
.select_frequency()
.set_phase()
.select_phase()
.set_frequency_msb()
.set_output_waveform()
.set_powered_down()
.set_control_source()
.The AD9833, AD9834, AD9837 and AD9838 are low power, programmable waveform generators capable of producing sine, triangular, and square wave outputs. Waveform generation is required in various types of sensing, actuation, and time domain reflectometry (TDR) applications. The output frequency and phase are software programmable, allowing easy tuning. No external components are needed. The frequency registers are 28 bits wide: with a 25 MHz clock rate, resolution of 0.1 Hz can be achieved; with a 1 MHz clock rate, the AD9833 can be tuned to 0.004 Hz resolution.
The devices are written to via a 3-wire serial interface (SPI). This serial interface operates at clock rates up to 40 MHz and is compatible with DSP and microcontroller standards. The devices operate with a power supply from 2.3 V to 5.5 V.
Datasheets:
Application Note:
Article explaining DDS using an AD9833:
To use this driver, import this crate and an embedded_hal
implementation,
then instantiate the appropriate device.
I wrote an example MIDI player that plays Beethoven's ninth symphony in hardware :). See: driver-examples.
use ad983x::{Ad983x, FrequencyRegister};
use embedded_hal_bus::spi::ExclusiveDevice;
use linux_embedded_hal::{Delay, SpidevBus, SysfsPin};
fn main() {
let spi = SpidevBus::open("/dev/spidev0.0").unwrap();
let chip_select = SysfsPin::new(25);
let dev = ExclusiveDevice::new(spi, chip_select, Delay);
let mut dds = Ad983x::new_ad9833(dev);
dds.reset().unwrap(); // reset is necessary before operation
dds.set_frequency(FrequencyRegister::F0, 4724).unwrap();
dds.enable().unwrap();
// Given a 25 MHz clock, this now outputs a sine wave
// with a frequency of 440 Hz, which is a standard
// A4 tone.
// Get device back
let _dev = dds.destroy();
}
For questions, issues, feature requests like compatibility with similar devices and other changes, please file an issue in the github project.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.