Ejemplo n.º 1
0
ret_code_t nrf_drv_csense_sample(void)
{
    ASSERT(m_csense.module_state == NRF_DRV_STATE_POWERED_ON);

    if(m_csense.adc_channels_input_mask != 0)
    {
        if(m_csense.channels_to_read == 0)
        {
#if USE_COMP == 0 && defined(SAADC_PRESENT)
            nrf_saadc_enable();
#endif
            if(nrf_drv_csense_is_busy() == true)
            {
                return NRF_ERROR_BUSY;
            }
            m_csense.busy = true;
            m_csense.channels_to_read = m_csense.adc_channels_input_mask;
            calculate_next_channel();
        }

#if USE_COMP
        if (!m_csense.timers_powered_on)
        {
            nrf_drv_timer_enable(&m_timer0);
            nrf_drv_timer_enable(&m_timer1);
            m_csense.timers_powered_on = true;
        }
        else
        {
            nrf_drv_timer_resume(&m_timer0);
            nrf_drv_timer_resume(&m_timer1);
        }
        nrf_drv_comp_pin_select((nrf_comp_input_t)m_csense.cur_chann_idx);
        nrf_drv_comp_start(0, 0);
#else
        ret_code_t err_code;
#ifdef ADC_PRESENT
        adc_channel.config.config.ain = (nrf_adc_config_input_t)(1<<m_csense.cur_chann_idx);
        nrf_gpio_pin_clear(m_csense.output_pin);
        err_code = nrf_drv_adc_sample_convert(&adc_channel, NULL);
#elif defined(SAADC_PRESENT)
        saadc_channel.pin_p = (nrf_saadc_input_t)(m_csense.cur_chann_idx + 1);
        nrf_saadc_channel_input_set(0, saadc_channel.pin_p, NRF_SAADC_INPUT_DISABLED);
        nrf_gpio_pin_clear(m_csense.output_pin);
        err_code = nrf_drv_saadc_sample();
#endif //ADC_PRESENT
        if(err_code != NRF_SUCCESS)
        {
            return err_code;
        }
#endif //USE_COMP
    }

    return NRF_SUCCESS;
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: JulianYG/WNR
/**@brief Function for handling the Battery measurement timer timeout.
 *
 * @details This function will be called each time the battery level measurement timer expires.
 *          This function will start the ADC.
 *
 * @param[in] p_context   Pointer used for passing some arbitrary information (context) from the
 *                        app_start_timer() call to the timeout handler.
 */
static void battery_level_meas_timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    #ifdef NRF51
    nrf_adc_start();
    #else // NRF52
    uint32_t err_code;
    err_code = nrf_drv_saadc_sample();
    APP_ERROR_CHECK(err_code);
    #endif // NRF51
}
Ejemplo n.º 3
0
static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
    uint32_t err_code;
	
    if (int_type == NRF_DRV_RTC_INT_COMPARE0)
    {
        nrf_drv_saadc_sample();                                        //Trigger the SAADC SAMPLE task
			
        LEDS_INVERT(BSP_LED_0_MASK);                                   //Toggle LED1 to indicate SAADC sampling start
			
        err_code = nrf_drv_rtc_cc_set(&rtc,0,RTC_CC_VALUE,true);       //Set RTC compare value. This needs to be done every time as the nrf_drv_rtc clears the compare register on every compare match
        APP_ERROR_CHECK(err_code);
        nrf_drv_rtc_counter_clear(&rtc);                               //Clear the RTC counter to start count from zero
    }
}