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>,
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>,
sourcepub fn new(reset: Reset, data: Data, fq_ud: FqUd, w_clk: WClk) -> Self
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:
Signal | AD9850 Pin |
---|---|
reset | 22 |
data | 25 |
fq_ud | 7 |
w_clk | 8 |
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.
sourcepub fn new_with_osc_freq(
reset: Reset,
data: Data,
fq_ud: FqUd,
w_clk: WClk,
osc_freq: f32
) -> Self
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
.
sourcepub fn into_serial_mode(
self
) -> Result<Ad9850<Serial, Reset, Data, FqUd, WClk>, E>
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>,
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>,
sourcepub fn set_frequency(&mut self, frequency: f32) -> Result<(), E>
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
.
sourcepub fn set_frequency_and_phase(
&mut self,
frequency: f32,
phase: u8
) -> Result<(), E>
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.
sourcepub fn update(
&mut self,
tuning_word: u32,
control_and_phase: u8
) -> Result<(), E>
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} $