Skip to content

Commit 3c8a4ce

Browse files
add raw frequency property; update docs
1 parent 3319913 commit 3c8a4ce

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ A CircuitPython driver for the AD9833 Programmable Waveform Generator.
2323
.. image:: https://github.com/CedarGroveStudios/CircuitPython_AD9833/blob/master/media/DSC05796_combo.jpg
2424

2525

26-
The AD9833 is a programmable waveform generator that produces sine, square, and triangular waveform output from 0 MHz to 12.5MHz with 28-bit resoluLon. The driver controls the waveform generator's frequency, phase, and waveform type.
26+
The AD9833 is a programmable waveform generator that produces sine, square, and triangular waveform output from 0 MHz to 12.5MHz with 28-bit resolution. The driver controls the waveform generator's frequency, phase, and waveform type.
2727

28-
The Cedar Grove AD9833 Precision Waveform Generator and AD9833 ADSR Precision Waveform Generator FeatherWings provide all the support circuitry for the AD9833. The ADSR (Attack, Decay, Sustain, Release) version incorporates the AD5245 digital potenLometer to provide output amplitude control.
28+
The Cedar Grove AD9833 Precision Waveform Generator and AD9833 ADSR Precision Waveform Generator FeatherWings provide all the support circuitry for the AD9833. The ADSR (Attack, Decay, Sustain, Release) version incorporates the AD5245 digital potentiometer to provide output amplitude control.
2929

3030

3131
Dependencies

cedargrove_ad9833.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def __init__(
5555
During initialization, the generator is reset and placed in the pause
5656
state.
5757
58-
:param int wave_freq: The 28-bit waveform frequency in Hz ranging from
59-
0 to 2 ** 28. Practical maximum is 12.5MHz (one-half the master clock
60-
frequency). Defaults to 440.
58+
:param float wave_freq: The floating point waveform frequency in Hz
59+
ranging from 0.09 to 12.5MHz (one-half the master clock frequency).
60+
Defaults to 440. Resolution is approximately 0.09Hz.
6161
:param int wave_phase: The waveform phase offset in 2π Rad // 4096.
6262
Defaults to 0.
6363
:param str wave_type: The "sine", "triangle", or "square" wave shape.
@@ -92,7 +92,9 @@ def __init__(
9292

9393
@property
9494
def wave_freq(self):
95-
"""The wave generator output frequency value."""
95+
"""The frequency output of the wave generator. The wave_freq value can
96+
differ slightly from the wave generator’s output frequency due to the
97+
internal conversion needed for loading the DAC counter register."""
9698
return self._wave_freq
9799

98100
@wave_freq.setter
@@ -104,6 +106,16 @@ def wave_freq(self, new_wave_freq=440):
104106
self._wave_freq = min(self._wave_freq, self._m_clock // 2)
105107
self._update_freq_register(self._wave_freq)
106108

109+
@property
110+
def raw_wave_freq(self):
111+
"""The frequency output of the wave generator as derived from the
112+
DAC counter register (FREQREG) value. The raw frequency is based on the
113+
25Mhz master clock and the 28-bit DAC counter register. The raw wave
114+
value can differ slightly from wave_freq due to the internal conversion
115+
needed for loading the DAC counter register."""
116+
freq_word = int(round(float(self._wave_freq * pow(2, 28)) / self._m_clock))
117+
return freq_word * (self._m_clock / pow(2, 28))
118+
107119
@property
108120
def wave_phase(self):
109121
"""The wave generator integer output phase value."""
@@ -129,7 +141,7 @@ def wave_type(self, new_wave_type="sine"):
129141
:param str new_wave_type: The waveform type. Defaults to 'sine'."""
130142
self._wave_type = new_wave_type
131143
if self._wave_type not in ("triangle", "square", "sine"):
132-
# Default to sine in type isn't valid
144+
# Default to sine if type isn't valid
133145
self._wave_type = "sine"
134146
self._update_control_register()
135147

773 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)