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.

  • Good, now we are making progress. The value 00-02-00-02-00-02-00-02 are 4 hex values all with values 0x0002. This value should be ideally 0x0000, but apparently there is 2 LSB offset error. This might improve if you run the ADC offset calibration task. Anyway, close enough.

    If you change the adc buffer size to 1, i.e. set ADC_BUFFER_SIZE to 1, then you would only get one 0x0002 value instead of four. The value 0x01ff when you leave the pin open is equal to decimal 511.

    The ADC output range with 10 bit configuration as in this example is 0-1023, which corresponds to the input range of 0V-3.6V. So if you get e.g. ADC output code of 600 = 0x0258 that corresponds to 3.6V*600/1023=2.11V input voltage on the P0.01 ADC input pin.

  • Thanks for the reply Stefan, I understand what you conveyed there. I have used example at github.com/.../nrf51-ADC-examples and getting 1023 decimal value if analog pin p0.01 is connected to VDD and 511 if I left it open in air. I am using ADXL335 that has 3.3v connected to its VCC.

    When I connect accelerometer xout to the p0.01 decimal value sent to uart and nrfconnect app keeps on increasing (for e.g. 241 to 468) even I have accelerometer idle. Can you tell me, where could I have possibly gone wrong and what is the ADC configuration I should be using ?

    If you can also let me know what should be my interfacing setup it would be of a great help.

  • 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);
    }
    
  • You must implement the transfer function yourself from ADC output value to meaningful g value. For example, if the specification for the accelerometer says that 2.0V output is positive 10g acceleration, 1.0V is no acceleration and 0V is negative 10g acceleration, and the relationship between acceleration and accelerometer voltage output is linear, then you can with algebra find the transfer function where you have ADC output value on one axis and g value on the other.

  • If you have configured the ADC to sample on P0.01, and the ADC output values rises, that is because the voltage on P0.01 is rising. Then the accelerometer is not outputting the sensor reading properly. Try to connect e.g. multimeter to the accelerometer to see if the output makes sense.

Related