This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BLE and SAADC parameter settings

In my code, the parameter definitions like this :
#define APP_ADV_INTERVAL                300                                     /**< The advertising interval (in units of 0.625 ms. This value corresponds to 187.5 ms). */

#define APP_ADV_DURATION                18000                                   /**< The advertising duration (180 seconds) in units of 10 milliseconds. */
#define APP_BLE_OBSERVER_PRIO           3                                       /**< Application's BLE observer priority. You shouldn't need to modify this value. */
#define APP_BLE_CONN_CFG_TAG            1                                       /**< A tag identifying the SoftDevice BLE configuration. */

#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(100, UNIT_1_25_MS)        /**< Minimum acceptable connection interval (0.1 seconds). */
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(200, UNIT_1_25_MS)        /**< Maximum acceptable connection interval (0.2 second). */
#define SLAVE_LATENCY                   0                                       /**< Slave latency. */
#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)         /**< Connection supervisory timeout (4 seconds). */

#define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(5000)                   /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
#define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(30000)                  /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT    3                                       /**< Number of attempts before giving up the connection parameter negotiation. */

#define SEC_PARAM_BOND                  1                                       /**< Perform bonding. */
#define SEC_PARAM_MITM                  0                                       /**< Man In The Middle protection not required. */
#define SEC_PARAM_LESC                  0                                       /**< LE Secure Connections not enabled. */
#define SEC_PARAM_KEYPRESS              0                                       /**< Keypress notifications not enabled. */
#define SEC_PARAM_IO_CAPABILITIES       BLE_GAP_IO_CAPS_NONE                    /**< No I/O capabilities. */
#define SEC_PARAM_OOB                   0                                       /**< Out Of Band data not available. */
#define SEC_PARAM_MIN_KEY_SIZE          7                                       /**< Minimum encryption key size. */
#define SEC_PARAM_MAX_KEY_SIZE          16                                      /**< Maximum encryption key size. */

#define DEAD_BEEF                       0xDEADBEEF                              /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */

#define BATTERY_TIMER_INTERVAL          APP_TIMER_TICKS(60000)                  /**< Battery timer interval (60000 ms). */
#define SAADC_TIMER_INTERVAL            APP_TIMER_TICKS(200)                    /**< Saadc sampling timer interval (200 ms). */


#define ADC_RESULT_IN_MILLI_VOLTS(ADC_RESULT) (ADC_RESULT * 0.87890625)        /**< Function used to convert the saadc resault to a voltage value. */

#define POTENTIO_ANALOG_PIN        NRF_SAADC_INPUT_AIN1                        /**< Potentiometer analog pin. */
#define SAMPLES_IN_BUFFER 2                                                  /**< Number of saadc samples that will be stored in a buffer before the converstion starts. */

static nrf_saadc_value_t     m_buffer_pool[2][SAMPLES_IN_BUFFER];               /**< Number of saadc pools for holding the saadc samples. A 2nd pool would hold the next samples while the precedent ones gets converted. */
static uint32_t              m_adc_evt_counter;          
In my application, I used SAADC in SEGGER to convert my analog sensor input to digital and then i want to sent my data to pc via BLE. I find a code and used as an axample. I shared some definitions for saadc time and ble parameters from this code. I want to increase my sample number in my saadc block. Sampling frequency should be at least 2kHz. While i increase the sample number or decrease the app timer ticks, i had connection problems (device couldn't connect with pc via BLE. How can i change and define the timer and BLE parameters properly?
Thanks for your help.

  • 1) Okay, thank you. I changed it with 0.5 for 2 kHz sampling frequency.

    2) How can i increase the data transfer speed for 2 kHz or more sampling frequency?

    3) 

       If i use like this :

         float val;

         val = adc_value * 12 / 4096;
         printf("Val= %f\r\n" , val);

         It couldn't calculate the value  or it couldn't print it on terminal, there was no result or error.

    Probably due to adc_value is not float ,the calculation couldnt be done. How can i print the float voltage value?

    4) Also , the adc values which i read on terminal is not stable , it changes continuously , despite the input dont change.  What is the reason of this?

    5) Lastly, NUS is a bit confusing, what is the working principle of it? The data transfer is done by BLE , isn't it? And data can be read on uart interface?

    I am new with nrf52 dk and segger , thanks for your informations and help. 

  • gozde said:
    I am new with nrf52 dk and segger , thanks for your informations and help. 

    Thank you for telling me, this is good for me to know!
    I am happy to help you get started with Nordic development, no worries :) 

    gozde said:
    1) Okay, thank you. I changed it with 0.5 for 2 kHz sampling frequency.

    Then you should instead change to using the nrf_drv_timer_us_to_ticks function with the sample rate given in µs, rather than nrf_drv_timer_ms_to_ticks that you are using now.

    gozde said:
    2) How can i increase the data transfer speed for 2 kHz or more sampling frequency?

    To increase the throughput of the connection you must change some SoftDevice configurations and the connection parameters according to the throughput documentation.

    gozde said:
    Probably due to adc_value is not float ,the calculation couldnt be done. How can i print the float voltage value?

    The uint16_t should be implicitly castable to a float,
    Try:

    ..
            float total;
            uint16_t adc_value;
            
            total = (adc_value * 12) / 4096;
            printf("%.2f" " ", total);
    ..

    gozde said:
    4) Also , the adc values which i read on terminal is not stable , it changes continuously , despite the input dont change.  What is the reason of this?

    How much do they fluctuate?
    Some fluctuations is always to be expected when sampling the SAADC.
    This depends both on internal factors of the SAADC such as calibration etc, but also on external factors such as noise and a unstable supply being read.
    How have you confirmed / measured the voltage you are measuring with the SAADC - how do you know that it does not change? It is likely that it also fluctuates somewhat.

    gozde said:
    5) Lastly, NUS is a bit confusing, what is the working principle of it? The data transfer is done by BLE , isn't it? And data can be read on uart interface?

    The principle of the NUS service is that it should work similar to an UART over BLE. The ble app uart example uses both the NUS service, and the UART peripheral, so that when something is received over the UART serial peripheral it is sent to the other device through the NUS service and then printed on the UART of the connected device.
    If you would like to read more about the BLE principles in general I highly recommend this Advertising, Services and Characteristics tutorial.

    Best regards,
    Karl

Related