Skip to content

Commit

Permalink
Fix ADC.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody82 committed Jan 15, 2017
1 parent b836a38 commit 4342649
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 35 deletions.
39 changes: 6 additions & 33 deletions car_app/battery.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "battery.h"
#include "nrf_drv_adc.h"
#include "nrf_adc.h"
#include "app_error.h"


Expand All @@ -8,7 +8,7 @@ static volatile int32_t adc;
static volatile int32_t adc2;
volatile int32_t LowVoltage = 0;

/*void ADC_IRQHandler(void)
void ADC_IRQHandler(void)
{
nrf_adc_conversion_event_clean();

Expand All @@ -22,6 +22,9 @@ volatile int32_t LowVoltage = 0;
LowVoltage = 0;
}

#ifndef NRF_APP_PRIORITY_HIGH
#define NRF_APP_PRIORITY_HIGH 1
#endif
static void adc_config(void)
{
const nrf_adc_config_t nrf_adc_config = NRF_ADC_CONFIG_DEFAULT;
Expand All @@ -31,36 +34,6 @@ static void adc_config(void)
nrf_adc_int_enable(ADC_INTENSET_END_Enabled << ADC_INTENSET_END_Pos);
NVIC_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_HIGH);
NVIC_EnableIRQ(ADC_IRQn);
}*/

//#define ADC_BUFFER_SIZE 1 /**< Size of buffer for ADC samples. */
//static nrf_adc_value_t adc_buffer[ADC_BUFFER_SIZE]; /**< ADC buffer. */
static nrf_drv_adc_channel_t m_channel_config = NRF_DRV_ADC_DEFAULT_CHANNEL(NRF_ADC_CONFIG_INPUT_4); /**< Channel instance. Default configuration used. */

static void adc_event_handler(nrf_drv_adc_evt_t const * p_event)
{
if (p_event->type == NRF_DRV_ADC_EVT_SAMPLE)
{
adc = p_event->data.sample.sample;
adc2 = (adc * 3600 / 1023);
BatteryVoltage = adc2 * (1800 + 6800) / 1800;

if (BatteryVoltage < 6000)
LowVoltage++;
else
LowVoltage = 0;
}
}

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);

nrf_drv_adc_channel_enable(&m_channel_config);
}

void InitBattery()
Expand All @@ -70,5 +43,5 @@ void InitBattery()

void BatteryTick()
{
nrf_drv_adc_sample();
nrf_adc_start();
}
2 changes: 1 addition & 1 deletion car_app/config/sdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
// <e> ADC_ENABLED - nrf_drv_adc - Driver for ADC peripheral (nRF51)
//==========================================================
#ifndef ADC_ENABLED
#define ADC_ENABLED 1
#define ADC_ENABLED 0
#endif
#if ADC_ENABLED
// <o> ADC_CONFIG_IRQ_PRIORITY - Interrupt priority
Expand Down
2 changes: 1 addition & 1 deletion car_app/pca10028/s130/armgcc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SRC_FILES += \
$(SDK_ROOT)/components/drivers_nrf/uart/nrf_drv_uart.c \
$(SDK_ROOT)/components/drivers_nrf/ppi/nrf_drv_ppi.c \
$(SDK_ROOT)/components/drivers_nrf/timer/nrf_drv_timer.c \
$(SDK_ROOT)/components/drivers_nrf/adc/nrf_drv_adc.c \
$(SDK_ROOT)/components/drivers_nrf/hal/nrf_adc.c \
$(PROJ_DIR)/main.c \
$(PROJ_DIR)/settings.c \
$(PROJ_DIR)/main_ble.c \
Expand Down

0 comments on commit 4342649

Please sign in to comment.