Struct ad9850::Ad9850

source ·
pub struct Ad9850<Mode, Reset, Data, FqUd, WClk> { /* private fields */ }
Expand description

Represents a connection to a AD9850 device.

See crate level documentation, or check the new method for an entry point.

Implementations§

source§

impl<Reset, Data, FqUd, WClk, E> Ad9850<Init, Reset, Data, FqUd, WClk>where Reset: OutputPin<Error = E>, Data: OutputPin<Error = E>, FqUd: OutputPin<Error = E>, WClk: OutputPin<Error = E>,

source

pub fn new(reset: Reset, data: Data, fq_ud: FqUd, w_clk: WClk) -> Self

Construct a new Ad9850 instance, in inital mode.

This call does not communicate with the device yet. You need to call into_serial_mode to initiate a reset before you can send any data.

Example:

let ad9850 = Ad9850::new(
    pins.d4.into_output(),
    pins.d5.into_output(),
    pins.d6.into_output(),
    pins.d7.into_output(),
).into_serial_mode().unwrap();

The four parameters correspond to the digital pins connected to the AD9850:

SignalAD9850 Pin
reset22
data25
fq_ud7
w_clk8

NOTE: the “data” pin is labeled “D7” in the AD9850 datasheet. It’s used either as the MSB in parallel mode, or as the single data pin in serial mode. Breakout boards usually expose this pin twice: once as D7 on the parallel interface, and again as a pin labeled DATA. For this reason, make sure not to ground the D7 pin if you are planning to use serial mode.

source

pub fn new_with_osc_freq( reset: Reset, data: Data, fq_ud: FqUd, w_clk: WClk, osc_freq: f32 ) -> Self

Same as new, but allows the oscillator frequency to be specified.

Use this if your board’s oscillator is not 125 MHz.

This value is used in calculations done by set_frequency and set_frequency_and_phase.

source

pub fn into_serial_mode( self ) -> Result<Ad9850<Serial, Reset, Data, FqUd, WClk>, E>

Reset the ad9850 device into serial mode.

This is the only supported mode at the moment.

Returns an error, if any of the set_low / set_high calls on one of the pins fail.

source§

impl<Reset, Data, FqUd, WClk, E> Ad9850<Serial, Reset, Data, FqUd, WClk>where Reset: OutputPin<Error = E>, Data: OutputPin<Error = E>, FqUd: OutputPin<Error = E>, WClk: OutputPin<Error = E>,

source

pub fn set_frequency(&mut self, frequency: f32) -> Result<(), E>

Set output frequency to the given value (in Hz)

Convenience function to set only the frequency, with a phase of $0$. Computes the proper tuning word (assuming an oscillator frequency of 125MHz) and calls update.

source

pub fn set_frequency_and_phase( &mut self, frequency: f32, phase: u8 ) -> Result<(), E>

Set output frequency and phase to given values

Panics

The given phase must not exceed 5 bits (decimal 31, 0x1F). Otherwise this function panics.

source

pub fn update( &mut self, tuning_word: u32, control_and_phase: u8 ) -> Result<(), E>

Update device register with given data.

This is a low-level interface. See the set_* methods for a high-level wrapper.

The Ad9850 register is 40-bit wide:

  • The first 32 bit are the “tuning word”, which determines the frequency
  • Next two bits are “control bits”, which should always be zero (enforced by this function)
  • This is followed by a single “power down” bit
  • The remaining 5 bits determine the “phase” by which the output signal is shifted.

To find the correct tuning word for a given frequency that you want to set, you’ll need to know the frequency of the oscillator connected to the Ad9850. Assuming an oscillator frequency of 125 MHz (the default on most breakout boards), then the tuning word $tw$ for a given frequency $f$ can be found with this formula:

$ tw = \frac{f}{2^{32} * 125MHz} $

Auto Trait Implementations§

§

impl<Mode, Reset, Data, FqUd, WClk> RefUnwindSafe for Ad9850<Mode, Reset, Data, FqUd, WClk>where Data: RefUnwindSafe, FqUd: RefUnwindSafe, Mode: RefUnwindSafe, Reset: RefUnwindSafe, WClk: RefUnwindSafe,

§

impl<Mode, Reset, Data, FqUd, WClk> Send for Ad9850<Mode, Reset, Data, FqUd, WClk>where Data: Send, FqUd: Send, Mode: Send, Reset: Send, WClk: Send,

§

impl<Mode, Reset, Data, FqUd, WClk> Sync for Ad9850<Mode, Reset, Data, FqUd, WClk>where Data: Sync, FqUd: Sync, Mode: Sync, Reset: Sync, WClk: Sync,

§

impl<Mode, Reset, Data, FqUd, WClk> Unpin for Ad9850<Mode, Reset, Data, FqUd, WClk>where Data: Unpin, FqUd: Unpin, Mode: Unpin, Reset: Unpin, WClk: Unpin,

§

impl<Mode, Reset, Data, FqUd, WClk> UnwindSafe for Ad9850<Mode, Reset, Data, FqUd, WClk>where Data: UnwindSafe, FqUd: UnwindSafe, Mode: UnwindSafe, Reset: UnwindSafe, WClk: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.