samd: Add a vref=num option to the ADC and DAC constructor.

ADC: The argument of vref=num is an integer. Values for num are:

    SAMD21:
    0  INT1V   1.0V voltage reference
    1  INTVCC0 1/1.48 Analog voltage supply
    2  INTVCC1 1/2 Analog voltage supply (only for VDDANA > 2.0V)
    3  VREFA   External reference
    4  VREFB   External reference

    SAMD51:
    0  INTREF  internal bandgap reference
    1  INTVCC1 Analog voltage supply
    2  INTVCC0 1/2 Analog voltage supply (only for VDDANA > 2.0v)
    3  AREFA   External reference A
    4  AREFB   External reference B
    5  AREFC   External reference C (ADC1 only)

DAC: The argument of vref=num is an integer. Suitable values:

    SAMD21:
    0  INT1V   Internal voltage reference
    1  VDDANA  Analog voltage supply
    2  VREFA   External reference

    SAMD51:
    0  INTREF Internal bandgap reference
    1  VDDANA Analog voltage supply
    2  VREFAU Unbuffered external voltage reference (not buffered in DAC)
    4  VREFAB Buffered external voltage reference (buffered in DAC).
This commit is contained in:
robert-hh
2022-12-02 21:08:46 +01:00
committed by Damien George
parent a73dcb3d22
commit e69313f89c
4 changed files with 143 additions and 33 deletions

View File

@@ -254,16 +254,38 @@ an external ADC.
ADC Constructor
```````````````
.. class:: ADC(dest, *, average=16)
.. class:: ADC(dest, *, average=16, vref=n)
:noindex:
Construct and return a new ADC object using the following parameters:
Construct and return a new ADC object using the following parameters:
- *dest* is the Pin object on which the ADC is output.
- *dest* is the Pin object on which the ADC is output.
Keyword arguments:
Keyword arguments:
- *average* is used to reduce the noise. With a value of 16 the LSB noise is about 1 digit.
- *average* is used to reduce the noise. With a value of 16 the LSB noise is about 1 digit.
- *vref* sets the reference voltage for the ADC.
The default setting is for 3.3V. Other values are:
==== ============================== ===============================
vref SAMD21 SAMD51
==== ============================== ===============================
0 1.0V voltage reference internal bandgap reference (1V)
1 1/1.48 Analogue voltage supply Analogue voltage supply
2 1/2 Analogue voltage supply 1/2 Analogue voltage supply
3 External reference A External reference A
4 External reference B External reference B
5 - External reference C
==== ============================== ===============================
ADC Methods
```````````
.. method:: read_u16()
Read a single ADC value as unsigned 16 bit quantity. The voltage range is defined
by the vref option of the constructor, the resolutions by the bits option.
DAC (digital to analog conversion)
----------------------------------
@@ -280,6 +302,32 @@ The DAC class provides a fast digital to analog conversion. Usage example::
The resolution of the DAC is 12 bit for SAMD51 and 10 bit for SAMD21. SAMD21 devices
have 1 DAC channel at GPIO PA02, SAMD51 devices have 2 DAC channels at GPIO PA02 and PA05.
DAC Constructor
```````````````
.. class:: DAC(id, *, vref=3)
:noindex:
The vref arguments defines the output voltage range, the callback option is used for
dac_timed(). Suitable values for vref are:
==== ============================ ================================
vref SAMD21 SAMD51
==== ============================ ================================
0 Internal voltage reference Internal bandgap reference (~1V)
1 Analogue voltage supply Analogue voltage supply
2 External reference Unbuffered external reference
3 - Buffered external reference
==== ============================ ================================
DAC Methods
```````````
.. method:: write(value)
Write a single value to the selected DAC output. The value range is 0-1023 for
SAMD21 and 0-4095 for SAMD51. The voltage range depends on the vref setting.
Software SPI bus
----------------