Question about the nRF Connect SDK v2.1.0 - adc example using nRF52840(PCA10056)

Hello, I am trying to understand the adc example using the PCA10056. 

HI can see the following code that initializes 3 `zephyr_user` channels

#if !DT_NODE_EXISTS(DT_PATH(zephyr_user)) || \
	!DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)
#error "No suitable devicetree overlay specified"
#endif

#define DT_SPEC_AND_COMMA(node_id, prop, idx) \
	ADC_DT_SPEC_GET_BY_IDX(node_id, idx),

/* Data of ADC io-channels specified in devicetree. */
static const struct adc_dt_spec adc_channels[] = {
	DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels,
	DT_SPEC_AND_COMMA)
	};
In the DT file, there are two different adcs in the device tree:
arduino_adc: analog-connector {
                compatible = "arduino,uno-adc";
                #io-channel-cells = <1>;
                io-channel-map = <0 &adc 1>,
                                 <1 &adc 2>,
                                 <2 &adc 4>,
                                 <3 &adc 5>,
                                 <4 &adc 6>,
                                 <5 &adc 7>;
        };

        zephyr,user {
                io-channels = <&adc 0>, <&adc 1>, <&adc 7>;
        };
My first question is: What is the difference between the `arduino_adc` vs the `zephyr_user` ADC? 
The second question: Based on the PCA10056 pin assignment, AIN0 - AIN7 are analog input pins, if I would like to use pins other than 0, 1, and 7. How can I initialize the DT?
For the `zephyr_user` adcs, I can see a node with the following properties
adc: adc@40007000 {
                        compatible = "nordic,nrf-saadc";
                        reg = <0x40007000 0x1000>;
                        interrupts = <7 NRF_DEFAULT_IRQ_PRIORITY>;
                        status = "okay";
                        #io-channel-cells = <1>;
                        #address-cells = <1>;
                        #size-cells = <0>;
                        channel@0 {
                                reg = <0>;
                                zephyr,gain = "ADC_GAIN_1_6";
                                zephyr,reference = "ADC_REF_INTERNAL";
                                zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
                                zephyr,input-positive = <NRF_SAADC_AIN1>;
                                zephyr,resolution = <12>;
                        };

                        channel@1 {
                                reg = <1>;
                                zephyr,gain = "ADC_GAIN_1_6";
                                zephyr,reference = "ADC_REF_INTERNAL";
                                zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
                                zephyr,input-positive = <NRF_SAADC_VDD>;
                                zephyr,resolution = <14>;
                                zephyr,oversampling = <8>;
                        };

                        channel@7 {
                                reg = <7>;
                                zephyr,gain = "ADC_GAIN_1_5";
                                zephyr,reference = "ADC_REF_VDD_1_4";
                                zephyr,vref-mv = <750>;
                                zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
                                zephyr,input-positive = <NRF_SAADC_AIN6>;
                                zephyr,input-negative = <NRF_SAADC_AIN7>;
                                zephyr,resolution = <12>;
                        };

                };

The third question: Can anyone helps me understand the following properties in the node?
zephyr,gain;
zephyr,reference;
zephyr,vref-mv;
zephyr,acquisition-time;
zephyr,input-positive;
zephyr,input-negative;
zephyr,resolution;
Last question: After I checked the pin assignment, it seems there is no analog out. I am wondering why is that or maybe I missed something.
Thanks
Parents
  • My first question is: What is the difference between the `arduino_adc` vs the `zephyr_user` ADC? 

    The VS Code Extension gives a good description of "zephyr,user":

    The zephyr,user node does not have a compatible field. This is unusual, as far as I'm aware, a node will always have a compatible field. The compatible field can then be used to access the DTS node properties from a .c/.h file

    The arduino_adc on the other hand has a compatible field, which is "arduino,uno-adc". I could not find any samples in the nRF Connect SDK that used this node. Check out the arduino,uno-adc binding for an explanation of this compatible: https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/dts/bindings/adc/arduino%2Cuno-adc.yaml 

    The second question: Based on the PCA10056 pin assignment, AIN0 - AIN7 are analog input pins, if I would like to use pins other than 0, 1, and 7. How can I initialize the DT?

    You can not use any other pins than AIN0-AIN7. Check out nRF52840 --> Pin assignments to see what Pin number that are associated with AIN0-AIN7:

    AIN0 P0.04
    AIN1 P0.05
    AIN2 P0.06
    AIN3 P0.07
    AIN4 P0.25
    AIN5 P0.26
    AIN6 P0.27
    AIN7 P0.28

    I would recommend you to read through nRF52840 --> SAADC (ADC), to get a better understanding of the ADC on a deeper level

    If you would like to use P0.28 for example, you can modify the file \zephyr\samples\drivers\adc\boards\nrf52840dk_nrf52840.overlay accordingly:

    / {
    	zephyr,user {
    		io-channels = <&adc 7>;
    	};
    };

    You may take a look at 3.5 Add the ADC peripheral as well, NCS 1.5.0 is used which is a bit outdated, but the section should still be useful.

    The third question: Can anyone helps me understand the following properties in the node?
    zephyr,gain;
    zephyr,reference;
    zephyr,vref-mv;
    zephyr,acquisition-time;
    zephyr,input-positive;
    zephyr,input-negative;
    zephyr,resolution;

    These fields belongs to the compatible "nordic,nrf-saadc". Take a look at the associated bindings for more information:

    https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/dts/bindings/adc/nordic%2Cnrf-saadc.yaml,

    this includes the binding adc-controller.yaml, which contains a description for all these fields

    https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/dts/bindings/adc/adc-controller.yaml 

    For an even more thorough description of these fields, check out

    nRF52840 --> SAADC

    Best regards,

    Simon

Reply
  • My first question is: What is the difference between the `arduino_adc` vs the `zephyr_user` ADC? 

    The VS Code Extension gives a good description of "zephyr,user":

    The zephyr,user node does not have a compatible field. This is unusual, as far as I'm aware, a node will always have a compatible field. The compatible field can then be used to access the DTS node properties from a .c/.h file

    The arduino_adc on the other hand has a compatible field, which is "arduino,uno-adc". I could not find any samples in the nRF Connect SDK that used this node. Check out the arduino,uno-adc binding for an explanation of this compatible: https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/dts/bindings/adc/arduino%2Cuno-adc.yaml 

    The second question: Based on the PCA10056 pin assignment, AIN0 - AIN7 are analog input pins, if I would like to use pins other than 0, 1, and 7. How can I initialize the DT?

    You can not use any other pins than AIN0-AIN7. Check out nRF52840 --> Pin assignments to see what Pin number that are associated with AIN0-AIN7:

    AIN0 P0.04
    AIN1 P0.05
    AIN2 P0.06
    AIN3 P0.07
    AIN4 P0.25
    AIN5 P0.26
    AIN6 P0.27
    AIN7 P0.28

    I would recommend you to read through nRF52840 --> SAADC (ADC), to get a better understanding of the ADC on a deeper level

    If you would like to use P0.28 for example, you can modify the file \zephyr\samples\drivers\adc\boards\nrf52840dk_nrf52840.overlay accordingly:

    / {
    	zephyr,user {
    		io-channels = <&adc 7>;
    	};
    };

    You may take a look at 3.5 Add the ADC peripheral as well, NCS 1.5.0 is used which is a bit outdated, but the section should still be useful.

    The third question: Can anyone helps me understand the following properties in the node?
    zephyr,gain;
    zephyr,reference;
    zephyr,vref-mv;
    zephyr,acquisition-time;
    zephyr,input-positive;
    zephyr,input-negative;
    zephyr,resolution;

    These fields belongs to the compatible "nordic,nrf-saadc". Take a look at the associated bindings for more information:

    https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/dts/bindings/adc/nordic%2Cnrf-saadc.yaml,

    this includes the binding adc-controller.yaml, which contains a description for all these fields

    https://github.com/nrfconnect/sdk-zephyr/blob/v3.1.99-ncs1/dts/bindings/adc/adc-controller.yaml 

    For an even more thorough description of these fields, check out

    nRF52840 --> SAADC

    Best regards,

    Simon

Children
No Data
Related