Skip to content

Commit 2bc1eee

Browse files
update UI to allow specification of SPI bus
1 parent 00e9b96 commit 2bc1eee

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

cedargrove_ad9833.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AD9833:
3939
The AD9833 is a programmable waveform generator that produces sine, square,
4040
and triangular waveform output from 0 MHz to 12.5MHz with 28-bit frequency
4141
resolution. The CircuitPython class sets the waveform generator's frequency,
42-
phase, and waveshape properties as well as providing methods for
42+
phase, and wave shape properties as well as providing methods for
4343
resetting, starting, pausing, and stopping the generator."""
4444

4545
# pylint: disable=too-many-arguments
@@ -48,26 +48,30 @@ def __init__(
4848
wave_freq=440,
4949
wave_phase=0,
5050
wave_type="sine",
51-
select="D6",
51+
spi=board.SPI(),
52+
select=board.D6,
5253
m_clock=25000000,
5354
):
54-
"""Initialize SPI bus interconnect, derive chip select pin (to allow
55-
multiple class instances), and create the SPIDevice instance. During
56-
intialization, the generator is reset and placed in the pause state.
55+
"""Initialize SPI bus interconnect and create the SPIDevice instance.
56+
During initialization, the generator is reset and placed in the pause
57+
state.
5758
5859
:param int wave_freq: The 28-bit waveform frequency in Hz ranging from
5960
0 to 2 ** 28. Practical maximum is 12.5MHz (one-half the master clock
6061
frequency). Defaults to 440.
6162
:param int wave_phase: The waveform phase offset in 2π Rad // 4096.
6263
Defaults to 0.
63-
:param str wave_type: The "sine", "triangle", or "square" waveshape.
64+
:param str wave_type: The "sine", "triangle", or "square" wave shape.
6465
Defaults to "sine".
65-
:param str select: The AD9833 chip select pin designation. Defaults to "D6".
66+
:param busio.SPI spi: The board's `busio.SPI` definition. Defaults to
67+
`board.SPI()`.
68+
:param board select: The AD9833 chip select pin designation. Defaults to
69+
`board.D6`.
6670
:param int m_clock: Master clock frequency in Hz. Defaults to 25MHz.
6771
"""
6872

69-
self._spi = board.SPI() # Define SPI bus
70-
self._cs = digitalio.DigitalInOut(getattr(board, select))
73+
self._spi = spi # Define SPI bus
74+
self._cs = digitalio.DigitalInOut(select)
7175
self._device = SPIDevice(
7276
self._spi, self._cs, baudrate=5000000, polarity=1, phase=0
7377
)

examples/AD9833_ADSR_FeatherWing_sweep_v03.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2022 JG for Cedar Grove Maker Studios
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 JG for Cedar Grove Maker Studios
22
#
33
# SPDX-License-Identifier: MIT
44
"""
5-
AD9833_ADSR_FeatherWing_sweep_v03.py 2022-10-12
5+
AD9833_ADSR_FeatherWing_sweep.py 2023-03-19 version 3.0.0
66
77
Fixed or swept frequency generator example. Update "initial parameters"
88
section for required functionality.
99
1010
Uses optional AD5245 digital potentiometer for output level control.
1111
12-
Tested with Adafruit Feather M4 Express and CircuitPython 8.0.0-beta.1
12+
Tested with Adafruit Feather M4 Express and CircuitPython 8.0.3
1313
"""
1414

1515
import time
16+
import board
1617
import cedargrove_ad5245
1718
import cedargrove_ad9833
1819

@@ -24,7 +25,7 @@
2425
print("AD5245 digital potentiometer not connected.")
2526
digi_pot_connected = False
2627

27-
wave_gen = cedargrove_ad9833.AD9833(select="D6")
28+
wave_gen = cedargrove_ad9833.AD9833(spi=board.SPI(), select=board.D6)
2829

2930
print("AD9833_ADSR_FeatherWing_sweep_v03.py")
3031

examples/ad9833_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2022 JG for Cedar Grove Maker Studios
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 JG for Cedar Grove Maker Studios
22
#
33
# SPDX-License-Identifier: Unlicense

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2-
# SPDX-FileCopyrightText: Copyright (c) 2022 JG for Cedar Grove Maker Studios
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 JG for Cedar Grove Maker Studios
32
#
43
# SPDX-License-Identifier: MIT
54

0 commit comments

Comments
 (0)