Exceeding values when using the SAADC

Good afternoon, 

I am trying to use a function generator to send a sinusoidal function to my nRF7002 DK and I am vizualizing the values in Putty. I am sending with a frequency of 100kHz, 1.5 Vpp. I observed that I get a lot of values of -4096, which it`s the maximum value I can get with the SAADC. Why that might be the reason for reaching that value so easily? On the positive side, my maximum is 1200 or so. 

Thank you.

  • Hi Raluca

    It sounds to me like there might be some configuration issues here. Could you please provide the following information:

    1. SDK version

    2. Your prj.conf

    3. Your device tree

    4. The ADC part of the application

    Regards

    Runar

  • Hello!

    1. SDK version: v2.5.99 - dev1. Answering this I realized I am in a dev branch, I will change and test it again. 

    2.This is my prj file.

     

    CONFIG_LOG=y
    
    # Step 1 - Enable nrfx drivers #
    CONFIG_NRFX_SAADC=y
    CONFIG_NRFX_PPI=y
    CONFIG_NRFX_DPPI=y
    CONFIG_NRFX_TIMER2=y
    
    CONFIG_LOG_BUFFER_SIZE=16384

    3. My device tree:
     

    /dts-v1/;
    #include <nordic/nrf5340_cpuappns_qkaa.dtsi>
    #include "nrf5340_cpuapp_common.dts"
    
    / {
    	model = "Nordic NRF5340 DK NRF5340 Application";
    	compatible = "nordic,nrf5340-dk-nrf5340-cpuapp";
    
    	chosen {
    		zephyr,sram = &sram0_ns;
    		zephyr,flash = &flash0;
    		zephyr,code-partition = &slot0_ns_partition;
    		zephyr,entropy = &psa_rng;
    	};
    
    	psa_rng: psa-rng {
    		compatible = "zephyr,psa-crypto-rng";
    		status = "okay";
    	};
    };


    4. The configuration of the ADC:
     

    static void configure_saadc(void)
    {
        nrfx_err_t err;
    
        /* STEP 5.4 - Connect ADC interrupt to nrfx interrupt handler */
        IRQ_CONNECT(DT_IRQN(DT_NODELABEL(adc)),
        DT_IRQ(DT_NODELABEL(adc), priority),
        nrfx_isr, nrfx_saadc_irq_handler, 0);
    
        /* STEP 5.5 - Initialize the nrfx_SAADC driver */
        err = nrfx_saadc_init(DT_IRQ(DT_NODELABEL(adc), priority));
        if (err != NRFX_SUCCESS) 
        {
            LOG_ERR("nrfx_saadc_init error: %08x", err);
    
            return;
        }   
    
        
        /* STEP 5.6 - Declare the struct to hold the configuration for the SAADC channel used to sample the battery voltage */
        nrfx_saadc_channel_t channel = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN0, 0);
    
        /* STEP 5.7 - Change gain config in default config and apply channel configuration */
        channel.channel_config.gain = NRF_SAADC_GAIN1_6;
        err = nrfx_saadc_channels_config(&channel, 1);
        if (err != NRFX_SUCCESS) 
        {
            LOG_ERR("nrfx_saadc_channels_config error: %08x", err);
            return;
        }
    
        /* STEP 5.8 - Configure channel 0 in advanced mode with event handler (non-blocking mode) */
        nrfx_saadc_adv_config_t saadc_adv_config = NRFX_SAADC_DEFAULT_ADV_CONFIG;
        err = nrfx_saadc_advanced_mode_set(BIT(0),
                                        NRF_SAADC_RESOLUTION_12BIT,
                                        &saadc_adv_config,
                                        saadc_event_handler);
        if (err != NRFX_SUCCESS) 
        {
            LOG_ERR("nrfx_saadc_advanced_mode_set error: %08x", err);
            return;
        }
                                                
        /* STEP 5.9 - Configure two buffers to make use of double-buffering feature of SAADC */
        err = nrfx_saadc_buffer_set(saadc_sample_buffer[0], SAADC_BUFFER_SIZE);
        if (err != NRFX_SUCCESS) 
        {
            LOG_ERR("nrfx_saadc_buffer_set error: %08x", err);
            return;
        }
        err = nrfx_saadc_buffer_set(saadc_sample_buffer[1], SAADC_BUFFER_SIZE);
        if (err != NRFX_SUCCESS) 
        {
            LOG_ERR("nrfx_saadc_buffer_set error: %08x", err);
            return;
        }
    
        /* STEP 5.10 - Trigger the SAADC. This will not start sampling, but will prepare buffer for sampling triggered through PPI */
        err = nrfx_saadc_mode_trigger();
        if (err != NRFX_SUCCESS) 
        {
            LOG_ERR("nrfx_saadc_mode_trigger error: %08x", err);
            return;
        }
    
    }
     

    Maybe it will be clearer if I attach the entire project as well.

     5857.current_code.zip

    Thank you so much!

  • Hi

    Is your signal centered around 0V? if so it will be outside the GPIO range which has a minimum level of -0.3V. If this is the case, could you try to add a positive DC offset and see if the problem is exist? 

    Regards

    Runar

Related