This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to configure ADC in single end mode and also how to control my samplerate using local timer?

Hello, I am using nRF52832 DK, and implement my software using eclipse with ARM GCC complier sdk12.1. I have interface accelerometer sensor with this board. I have read SAADC and send adc value to android apps. I am using 12 bit ADC, But problem is for calibrating acceleration analog value. So I want to use single ended mode for ADC and how to select mode for control the sample rate using CC. I read data sheet for controlling sample rate, but unable to understand what's I need to change in my program. nRF52832 data sheet is in given like this (Capture and compare value. Sample rate is 16 MHz/CC). So please help me for how to configure my program with above changes let me know., or can you give me some reference link tutorial.......

Thanks in Advanced......

Parents
  • Thank you sir for giving me reply. let me explain what actually I have faing problem. I have using ADXL335 accelerometer sensor and I have successfully read three axis X Y Z by 12 bit SAADC and also send this to BLE. Actual sensor data is coming but sir I need to increase sampling rate upto 24575 point for each analog channel. my ADC is in scan mode I have use only three channel for X y and z axis. When I increase sampling rate and covert to micro second BLE is not connect with my apps. Please sir how to solved this problem. and one if the another problem is I am not able to send 12 bit value for the range of 0-4095. Its only 8 bit data send not see properly my three axis value. Please tell me sir how to convert uint_8 array into uint16_t bit array. I am search lots of tutorial and community it said it say like this --> value[i2] = adc_value; value[(i2)+1] = adc_value >> 8; why need to right shift by 8 bit. for sending data data over ble. please sir let me know. And I know your support is very good and quick response with question.. My ADC code is

    void saadc_sampling_event_enable(void)
    {
        ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
        APP_ERROR_CHECK(err_code);
    }
    
    void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
    {
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            ret_code_t err_code;
            uint16_t adc_value;
          //  uint16_t value1[SAADC_SAMPLES_IN_BUFFER*2];
            uint8_t value[SAADC_SAMPLES_IN_BUFFER*2]; // own change uint8_t
            uint8_t bytes_to_send;
    //        uint16_t data[3];
         
            // set buffers
            err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
            APP_ERROR_CHECK(err_code);
    
            // print samples on hardware UART and parse data for BLE transmission
            printf("ADC event number: %d\r\n",(int)m_adc_evt_counter);
            for (int i = 0; i < SAADC_SAMPLES_IN_BUFFER; i++)
            {
                printf("%d\r\n", p_event->data.done.p_buffer[i]);
                 adc_value = p_event->data.done.p_buffer[i];
    //             for (int j = 0; j <24576; j++)
    //             {
    //            	 data = adc_value;
    //             }
    //            adc_value = 4095;
                value[i*2] = adc_value;
                value[(i*2)+1] = adc_value >> 8;
    
            }
    				
            // Send data over BLE via NUS service. Makes sure not to send more than 20 bytes.
            if((SAADC_SAMPLES_IN_BUFFER*2) <= 20)
            {
                bytes_to_send = (SAADC_SAMPLES_IN_BUFFER*2);
            }
            else 
            {
                bytes_to_send = 20;
            }
    
    
            err_code = ble_nus_string_send(&m_nus, value, bytes_to_send);
            if (err_code != NRF_ERROR_INVALID_STATE) 
            {
                APP_ERROR_CHECK(err_code);
            }
    						
            m_adc_evt_counter++;
        }
    }
    
    void saadc_init(void)
    {
        ret_code_t err_code;
    	
        nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
        saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
    	
        nrf_saadc_channel_config_t channel_0_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4);
        channel_0_config.gain = NRF_SAADC_GAIN1_4;
        channel_0_config.reference = NRF_SAADC_REFERENCE_VDD4;
    	
        nrf_saadc_channel_config_t channel_1_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
        channel_1_config.gain = NRF_SAADC_GAIN1_4;
        channel_1_config.reference = NRF_SAADC_REFERENCE_VDD4;
    
        nrf_saadc_channel_config_t channel_2_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);
        channel_2_config.gain = NRF_SAADC_GAIN1_4;
        channel_2_config.reference = NRF_SAADC_REFERENCE_VDD4;
    	
    //    nrf_saadc_channel_config_t channel_3_config =
    //        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN7);
    //    channel_3_config.gain = NRF_SAADC_GAIN1_4;
    //    channel_3_config.reference = NRF_SAADC_REFERENCE_VDD4;
    
        err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_channel_init(0, &channel_0_config);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_saadc_channel_init(1, &channel_1_config);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_saadc_channel_init(2, &channel_2_config);
        APP_ERROR_CHECK(err_code);
    //    err_code = nrf_drv_saadc_channel_init(3, &channel_3_config);
    //    APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0],SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);   
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1],SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    }
    
Reply
  • Thank you sir for giving me reply. let me explain what actually I have faing problem. I have using ADXL335 accelerometer sensor and I have successfully read three axis X Y Z by 12 bit SAADC and also send this to BLE. Actual sensor data is coming but sir I need to increase sampling rate upto 24575 point for each analog channel. my ADC is in scan mode I have use only three channel for X y and z axis. When I increase sampling rate and covert to micro second BLE is not connect with my apps. Please sir how to solved this problem. and one if the another problem is I am not able to send 12 bit value for the range of 0-4095. Its only 8 bit data send not see properly my three axis value. Please tell me sir how to convert uint_8 array into uint16_t bit array. I am search lots of tutorial and community it said it say like this --> value[i2] = adc_value; value[(i2)+1] = adc_value >> 8; why need to right shift by 8 bit. for sending data data over ble. please sir let me know. And I know your support is very good and quick response with question.. My ADC code is

    void saadc_sampling_event_enable(void)
    {
        ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
        APP_ERROR_CHECK(err_code);
    }
    
    void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
    {
        if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
        {
            ret_code_t err_code;
            uint16_t adc_value;
          //  uint16_t value1[SAADC_SAMPLES_IN_BUFFER*2];
            uint8_t value[SAADC_SAMPLES_IN_BUFFER*2]; // own change uint8_t
            uint8_t bytes_to_send;
    //        uint16_t data[3];
         
            // set buffers
            err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
            APP_ERROR_CHECK(err_code);
    
            // print samples on hardware UART and parse data for BLE transmission
            printf("ADC event number: %d\r\n",(int)m_adc_evt_counter);
            for (int i = 0; i < SAADC_SAMPLES_IN_BUFFER; i++)
            {
                printf("%d\r\n", p_event->data.done.p_buffer[i]);
                 adc_value = p_event->data.done.p_buffer[i];
    //             for (int j = 0; j <24576; j++)
    //             {
    //            	 data = adc_value;
    //             }
    //            adc_value = 4095;
                value[i*2] = adc_value;
                value[(i*2)+1] = adc_value >> 8;
    
            }
    				
            // Send data over BLE via NUS service. Makes sure not to send more than 20 bytes.
            if((SAADC_SAMPLES_IN_BUFFER*2) <= 20)
            {
                bytes_to_send = (SAADC_SAMPLES_IN_BUFFER*2);
            }
            else 
            {
                bytes_to_send = 20;
            }
    
    
            err_code = ble_nus_string_send(&m_nus, value, bytes_to_send);
            if (err_code != NRF_ERROR_INVALID_STATE) 
            {
                APP_ERROR_CHECK(err_code);
            }
    						
            m_adc_evt_counter++;
        }
    }
    
    void saadc_init(void)
    {
        ret_code_t err_code;
    	
        nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
        saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
    	
        nrf_saadc_channel_config_t channel_0_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN4);
        channel_0_config.gain = NRF_SAADC_GAIN1_4;
        channel_0_config.reference = NRF_SAADC_REFERENCE_VDD4;
    	
        nrf_saadc_channel_config_t channel_1_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN5);
        channel_1_config.gain = NRF_SAADC_GAIN1_4;
        channel_1_config.reference = NRF_SAADC_REFERENCE_VDD4;
    
        nrf_saadc_channel_config_t channel_2_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);
        channel_2_config.gain = NRF_SAADC_GAIN1_4;
        channel_2_config.reference = NRF_SAADC_REFERENCE_VDD4;
    	
    //    nrf_saadc_channel_config_t channel_3_config =
    //        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN7);
    //    channel_3_config.gain = NRF_SAADC_GAIN1_4;
    //    channel_3_config.reference = NRF_SAADC_REFERENCE_VDD4;
    
        err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_channel_init(0, &channel_0_config);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_saadc_channel_init(1, &channel_1_config);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_saadc_channel_init(2, &channel_2_config);
        APP_ERROR_CHECK(err_code);
    //    err_code = nrf_drv_saadc_channel_init(3, &channel_3_config);
    //    APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0],SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);   
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1],SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
    }
    
Children
No Data
Related