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

Unable to get ADC results using accelerometer

hi, i am working on ble_app_uart_simple_adc example which is referred from the link github.com/.../nrf51-ADC-examples i flashed the code successfully. and detecting the device using NRFTool box application. during the circuit setup i connected accelerometer(ADXL335) Z- output to the p0.01 of the nrf51 development kit and connected ground. after connecting to the device through nrftool box UART application. the log file showing unknown values(strange symbols). how to get accelerometer z output values using this ble_app_uart_simple_adc example code.

Parents
  • The accelerometer should output a different voltage I assume depending on its acceleration. You need to realize what voltage range the accelerometer outputs and adjust the voltage range of the ADC output accordingly. In the ble_app_uart_adc_simple the ADC channel that samples on pin P0.01 is set up with default configuration which is without prescaling, which results in ADC voltage input range of 0V - 1.2V. Sorry for assuming before that the range was 0V - 3.6V, my bad. To configure the range to 0V - 3.6V you need to explicitly set the prescaler to 1/3 as in the following code:

    static void adc_config(void)
    {
    	ret_code_t ret_code;
    	nrf_drv_adc_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG;
    
    	ret_code = nrf_drv_adc_init(&config, adc_event_handler);
    	APP_ERROR_CHECK(ret_code);
    	
    	m_channel_config.config.config.input = NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD;
    
    	nrf_drv_adc_channel_enable(&m_channel_config);
    }
    
Reply
  • The accelerometer should output a different voltage I assume depending on its acceleration. You need to realize what voltage range the accelerometer outputs and adjust the voltage range of the ADC output accordingly. In the ble_app_uart_adc_simple the ADC channel that samples on pin P0.01 is set up with default configuration which is without prescaling, which results in ADC voltage input range of 0V - 1.2V. Sorry for assuming before that the range was 0V - 3.6V, my bad. To configure the range to 0V - 3.6V you need to explicitly set the prescaler to 1/3 as in the following code:

    static void adc_config(void)
    {
    	ret_code_t ret_code;
    	nrf_drv_adc_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG;
    
    	ret_code = nrf_drv_adc_init(&config, adc_event_handler);
    	APP_ERROR_CHECK(ret_code);
    	
    	m_channel_config.config.config.input = NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD;
    
    	nrf_drv_adc_channel_enable(&m_channel_config);
    }
    
Children
Related