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
  • Hi

    The nRFtoolbox UART app is probably receiving the correct ADC values, but it displays the values as ascii characters. If you would instead send readable ascii characters, then the nrftoolbox UART app would be able to display it correctly. E.g. if you would write the adc_event_handler as follows:

    static void adc_event_handler(nrf_drv_adc_evt_t const * p_event)
    {
    	uint8_t adc_result_temp[] = {'c','a','f','e'};
    	
    	if (p_event->type == NRF_DRV_ADC_EVT_DONE)
    	{
    		ble_nus_string_send(&m_nus, &adc_result_temp[0], 4);
    	}
    }
    

    it would write "cafe" in nRFtoolbox. If you want to see the real ADC values however, it is better to connect with nRF Connect app, then you see the raw hexadecimal values instead of ascii characters.

  • 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.

Reply
  • 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.

Children
No Data
Related