Example #1
0
/**
 * @brief ADC interrupt handler.
 */
void ADC_IRQHandler(void)
{
    unsigned adc_sample;
    nrf_adc_conversion_event_clean();
    adc_sample = nrf_adc_result_get();
    g_vcc_mv = adc_sample * 3600 / 1024;
}
Example #2
0
/**@brief Function for handling the ADC interrupt.
 *
 * @details  This function will fetch the conversion result from the ADC, convert the value into
 *           percentage and send it to peer.
 */
void ADC_IRQHandler(void)
{
    if (nrf_adc_conversion_finished())
    {
        uint8_t  adc_result;
        uint16_t batt_lvl_in_milli_volts;
        uint8_t  percentage_batt_lvl;
        uint32_t err_code;

        nrf_adc_conversion_event_clean();

        adc_result = nrf_adc_result_get();

        batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_result) +
                                  DIODE_FWD_VOLT_DROP_MILLIVOLTS;
        percentage_batt_lvl     = battery_level_in_percent(batt_lvl_in_milli_volts);

        err_code = ble_bas_battery_level_update(&m_bas, percentage_batt_lvl);
        if (
            (err_code != NRF_SUCCESS)
            &&
            (err_code != NRF_ERROR_INVALID_STATE)
            &&
            (err_code != BLE_ERROR_NO_TX_BUFFERS)
            &&
            (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
           )
        {
            APP_ERROR_HANDLER(err_code);
        }
    }
}
Example #3
0
File: main.c Project: JulianYG/WNR
/**@brief Function for handling the ADC interrupt.
 *
 * @details  This function will fetch the conversion result from the ADC, convert the value into
 *           percentage and send it to peer.
 */
void ADC_IRQHandler(void)
{
    uint32_t err_code;
    uint16_t adc_value;
    uint8_t  percentage_batt_lvl;
    uint16_t batt_lvl_in_milli_volts;
    nrf_adc_conversion_event_clean();
    nrf_adc_stop();
    
    adc_value = nrf_adc_result_get();
    
    
    batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(adc_value);
    
    percentage_batt_lvl     = battery_level_in_percent(batt_lvl_in_milli_volts);

    err_code = ble_bas_battery_level_update(&m_bas, percentage_batt_lvl);
    if (
        (err_code != NRF_SUCCESS)
        &&
        (err_code != NRF_ERROR_INVALID_STATE)
        &&
        (err_code != BLE_ERROR_NO_TX_PACKETS)
        &&
        (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
       )
    {
        APP_ERROR_HANDLER(err_code);
    }
}
Example #4
0
/**
 * @brief ADC interrupt handler.
 */
void ADC_IRQHandler(void)
{
    nrf_adc_conversion_event_clean();

    adc_sample = nrf_adc_result_get();

    // trigger next ADC conversion
    nrf_adc_start();
}
Example #5
0
/**
 * @brief ADC interrupt handler.
 */
void ADC_IRQHandler(void)
{
    //nrf_adc_int_disable(ADC_INTENSET_END_Enabled << ADC_INTENSET_END_Pos);

    nrf_adc_conversion_event_clean();

    adc_sample = nrf_adc_result_get();
    //battery_level_update();

   // nrf_adc_int_enable(ADC_INTENSET_END_Enabled << ADC_INTENSET_END_Pos);
    // trigger next ADC conversion
    nrf_adc_start();
}
Example #6
0
void ADC_IRQHandler(void)
{
	nrf_adc_conversion_event_clean();

	adc = nrf_adc_result_get();
	adc2 = (adc * 3600 / 1023);
	BatteryVoltage = adc2 * (1800 + 6800) / 1800;

	if (BatteryVoltage < 6000)
		LowVoltage++;
	else
		LowVoltage = 0;
}
Example #7
0
/**
 * @brief ADC interrupt handler.
 */
void ADC_IRQHandler(void)
{

    nrf_adc_conversion_event_clean();

    m_adc_value = (uint16_t)nrf_adc_result_get();
//    if (m_adc_value >= ADC_THRESHOLD) {
//        nrf_gpio_pin_clear(BSP_LED_2);
//    }
//    else {
//        nrf_gpio_pin_set(BSP_LED_2);
//    }
    bluetooth_adc_send(m_adc_value);
}
Example #8
0
/**
 * @brief Blocking function for executing single ADC conversion.
 *
 * This function selects desired input, starts single conversion,
 * waits for its finish  and returns result.
 * ADC is left in STOP state, given input is selected.
 * This function does not check if ADC is initialized and powered.
 *
 * @param[in] input is requested input to be selected
 *
 * @return conversion result
 */
int32_t nrf_adc_convert_single(nrf_adc_config_input_t input)
{
    int32_t val;

    nrf_adc_input_select(input);
    nrf_adc_start();

    while (!nrf_adc_conversion_finished())
    {
    }
    nrf_adc_conversion_event_clean();
    val = nrf_adc_result_get();
    nrf_adc_stop();
    return val;
}
Example #9
0
/* Interrupt handler for ADC data ready event */
void ADC_IRQHandler(void)
{
    nrf_adc_conversion_event_clean();

    adc_sample = nrf_adc_result_get();
}