Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow user to use all 8 channels on PmodDA4 #1419

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 18 additions & 5 deletions pynq/lib/pmod/pmod_dac.py
Expand Up @@ -24,6 +24,15 @@ class Pmod_DAC(object):

"""

CHANNEL_A = 0
CHANNEL_B = 1
CHANNEL_C = 2
CHANNEL_D = 3
CHANNEL_E = 4
CHANNEL_F = 5
CHANNEL_G = 6
CHANNEL_H = 7

def __init__(self, mb_info, value=None):
"""Return a new instance of a DAC object.

Expand All @@ -43,17 +52,20 @@ def __init__(self, mb_info, value=None):
if value:
self.write(value)

def write(self, value):
def write(self, value, channel=0):
"""Write a floating point number onto the DAC Pmod.

Note
----
Input value must be in the range [0.00, 2.50]
Input channel must be an integer in the range [0, 7]

Parameters
----------
value : float
The value to be written to the DAC.
channel : int
The channel to write on to the DAC.

Returns
-------
Expand All @@ -63,9 +75,10 @@ def write(self, value):
if not 0.00 <= value <= 2.5:
raise ValueError("Requested value not in range [0.00, 2.50].")

if not 0 <= channel <= 7:
raise ValueError("Requested channel not in range [0, 7].")

# Calculate the voltage value and write to DAC
int_val = int(value / 0.0006105)
cmd = (int_val << 20) | FIXEDGEN
int_val = int(value * 1638)
cmd = (int_val << 20) | (channel << 16) | FIXEDGEN
self.microblaze.write_blocking_command(cmd)