dac module

Direct control of the digital-to-analog converted.

This module contains a class for directly controlling the output of the MCP 4822 Digital-to-Analog Coverter (DAC). This is in contrast to the functiongenerator.FuncGen class, which modulates the DAC in the background.

Examples

Acessing the A-channel of the DAC and setting it to 1 volt:

>>> from dac import DAC
>>>
>>> dac_a = DAC('A') # Create a DAC object
>>>
>>> dac_a.write(1)

Creating an array of voltages from 0 to 3.3 volts with steps of 250 milli-volts to set the DAC to and sampling after the DAC changes:

>>> import time
>>> import machine
>>> import numpy as np
>>> from dac import DAC
>>>
>>> dac_a = DAC('A')
>>> voltages = np.arange(0, 3.3, 0.25)
>>> for voltage in voltages:
        dac_a.write(voltage)

        time.sleep(0.1)

        print(a0.read_u16() * 5.0354e-05) # Convert to volts

>>> dac_a.off() # Turning off the DAC after use

Note

Consider using functiongenerator.Waveform.get_voltages() to create an array of voltages to pass to the DAC.

class dac.DAC(channel: str = 'A', unsafe: bool = False)

Bases: object

A class representing the digital-to-analog converter.

Class for controlling the digital-to-analog converter on the ALPACA.

dac_A

A boolean specifying if the DAC A channel is used (rather than DAC B).

Type:

bool

unsafe

A boolean indicating whether the waveform is allowed to exceed a maximum voltage of 3.3 volts (the maximum voltage of the analog inputs on the Raspberry Pi Pico on the ALPACA). Defaults to False.

Type:

bool

Parameters:
  • channel (str) – A string specifying which channel to use. For ‘a’ or ‘A’, channel A on the DAC is used. For ‘b’ or ‘B’, channel B is used. Defaults to ‘A’.

  • unsafe (bool) – A boolean indicating whether the waveform is allowed to exceed a maximum voltage of 3.3 volts (the maximum voltage of the analog inputs on the Raspberry Pi Pico on the ALPACA). Defaults to False.

Note

By default, the voltage range of the DAC is limited to 0-3.3 V, the range that is safe for input to the analog input pins of the Raspberry Pi Pico in the ALPACA. Voltages of a waveform that fall outside this range are clipped, i.e. set to either 0 or 3.3 V. This behavior can be turned off using the unsafe parameter, increasing the range of the waveform to that of the MCP 4822 DAC, i.e. to 0-4.096 V. Note that in both cases, this clipping will occur silently.

off()

Turns off the digital-to-analog converter.

It is recommended to run this after use.

write(voltage: float) None

Sets the digital-to-analog converter to a voltage.

Parameters:

voltage (float) – Voltage to se the DAC to:

Returns:

None