示例#1
0
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool erase_bonds;

#ifdef ENABLE_DEBUG_LOG_SUPPORT
    app_trace_init();
#endif

    APPL_LOG("START\r\n");

    // Initialize.
    timers_init();
    buttons_leds_init(&erase_bonds);
    adc_config();
    ble_stack_init();
    device_manager_init(erase_bonds);
    gap_params_init();
    advertising_init();
    services_init();
    conn_params_init();

    // Start execution.
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);
    APPL_LOG("start advertising : %u\n", err_code);

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
示例#2
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    LEDS_CONFIGURE(BSP_LED_0_MASK);
    LEDS_OFF(BSP_LED_0_MASK);

    adc_config();
    UNUSED_RETURN_VALUE(NRF_LOG_INIT());

    NRF_LOG_PRINTF("ADC example\r\n");

    while (true)
    {
        APP_ERROR_CHECK(nrf_drv_adc_buffer_convert(adc_buffer,ADC_BUFFER_SIZE));
        uint32_t i;
        for (i = 0; i < ADC_BUFFER_SIZE; i++)
        {
            // manually trigger ADC conversion
            nrf_drv_adc_sample();
            // enter into sleep mode
            __SEV();
            __WFE();
            __WFE();

            nrf_delay_ms(100);
            LEDS_INVERT(BSP_LED_0_MASK);
        }
    }
}
示例#3
0
文件: main.c 项目: N7QWT/klipper
// Main entry point
int
main(void)
{
    SystemInit();
    LL_Init1msTick(SystemCoreClock);
    clock_config();
    adc_config();
    io_config();
    spi_config();
    sched_main();
    return 0;
}
示例#4
0
文件: entry.c 项目: russot/RT_STM32
int hardware_init(void)
{
	RCC_Configuration_motor();
	//NVIC_Configuration_motor();
	adc_config();
	vout_init();
	usb_init();
	tim2_init();
	rt_kprintf("ADC System initialized!\r\n");
	
	return  0;
}
示例#5
0
文件: main.c 项目: sannyas/avrlib
int main( void ){
	uint8_t idx;
	uint16_t result;

	DDRA = 0;

	usart_init();
	stdout = &usart_file;

	
	adc_config( ADC_PRESCALE_AUTO
			| ADC_INTERRUPT_DISABLE
			| ADC_AUTO_TRIG_DISABLE 
		  );
	adc_setVRef( ADC_REF_AVCC );
	adc_setChannel( ADC_CHANNEL_ADC1 );
	adc_enable();
	
	/* 
	ADCSRA |= (1 << ADPS2) | (1 << ADPS1);
	ADMUX |= (1<<REFS0);
	ADCSRA |= 1<<ADEN;
	*/


	//printf( "20 times single conversion:\n" );
	//for( idx=0; idx<20; ++idx ){
	while( 1 ){

		for( idx=0; idx<8; ++idx ){
			adc_setChannel( ADC_CHANNEL_FROM_IDX(idx) );
			adc_startConversion( );
			adc_waitConversion( );
			printf( "ADC%d = %d\n", idx, ADC );
		}


		printf( "\n" );

		/*
		ADCSRA |= (1 << ADSC); 
		while(!(ADCSRA & (1 << ADIF))); 
		ADCSRA |= (1 << ADIF); 
		printf( "ADC0 = %d\n", ADC );
		*/
		_delay_ms( 1000 );
	}

	return 0;
}
示例#6
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    adc_config();

    uart_config();

    printf("\n\rADC HAL simple example\r\n");

    printf("Current sample value:\r\n");

    nrf_adc_start();

    while (true)
    {
        // enter into sleep mode
        __SEV();
        __WFE();
        __WFE();
    }
}
示例#7
0
/////////////////////////////////////////////////////////////////////
/// Config Battery Monitor
///
/////////////////////////////////////////////////////////////////////
void blebat_Config(void)
{
    //init ADC
    adc_config();

    // Limit maximum number of measurements to the room we have.
    // Don't want to crash and burn....
    if (blebat_batmon_cfg.numberOfMeasurementsToAverage > MAX_MEAS_TO_AVERAGE)
    {
        blebat_batmon_cfg.numberOfMeasurementsToAverage = MAX_MEAS_TO_AVERAGE;
    }

    // Clear battery monitor data
    blebat_curBatteryLevelInReportUnits         = 0;
    batAppState->blebat_measurementSum          = 0;
    batAppState->blebat_oldestMeasurementIndex  = 0;
    batAppState->blebat_measurementAverage      = 0;
    memset(batAppState->blebat_measurements, 0, sizeof(batAppState->blebat_measurements));

}
示例#8
0
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool erase_bonds;

    //uart_config();

    //printf("\n\rBDC HAL simple example\r\n"); //GETS HERE, Dies after first letter!

    // Initialize.
    timers_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    device_manager_init(erase_bonds);
    gap_params_init();
    advertising_init();
    services_init();
    //sensor_simulator_init();
    conn_params_init();

    //uart_config();

    //printf("\n\rBDC HAL simple example\r\n"); //GETS HERE, Dies after first letter!

    //printf("Current sample value:\r\n");

    adc_config();

    // Start execution.
    application_timers_start();
    nrf_adc_start();
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool     erase_bonds;

    // Initialize.
    err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    adc_config();
    timers_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();
    peer_manager_init(erase_bonds);
    if (erase_bonds == true)
    {
        NRF_LOG_INFO("Bonds erased!\r\n");
    }
    gap_params_init();
    advertising_init();
    gatt_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();

    // Start execution.
    NRF_LOG_INFO("Heart Rate Sensor Start!\r\n");
    application_timers_start();
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            power_manage();
        }
    }
}
示例#10
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    adc_config();

    uart_config();

    printf("\n\rADC HAL simple example\r\n");

    printf("Current sample value:\r\n");

    while (true)
    {
			  // trigger next ADC conversion
			  nrf_adc_start();
        // enter into sleep mode
        __SEV();
        __WFE();
        __WFE();
			
			  nrf_delay_ms(100);	
				printf("%d\r\n", (int)adc_sample); // out ADC result
    }
}
示例#11
0
static uint16_t
adc_read_blocking()
{
	while (NRF_ADC->BUSY == 1) {
		// __asm("nop");
	}
	NRF_ADC->EVENTS_END = 0;
	sd_nvic_DisableIRQ(ADC_IRQn);
	NRF_ADC->INTENCLR = ADC_INTENCLR_END_Enabled;
	NRF_ADC->TASKS_START = 1;
        adc_config();
        NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
	while (NRF_ADC->EVENTS_END == 0) {
		// __asm("nop");
	}
	uint16_t    batt_lvl_in_milli_volts;
	uint16_t result = NRF_ADC->RESULT;
	batt_lvl_in_milli_volts = ADC_RESULT_IN_MILLI_VOLTS(result);
	result = battery_level_in_percent(batt_lvl_in_milli_volts);
        NRF_ADC->EVENTS_END     = 0;
	NRF_ADC->TASKS_STOP     = 1;
	return result;
}
示例#12
0
文件: adc.c 项目: ishgum/Wacky-Racers
/** Initalises the ADC registers for polling operation.  */
adc_t
adc_init (const adc_cfg_t *cfg)
{
    adc_sample_t dummy;
    adc_dev_t *adc;
    const adc_cfg_t adc_default_cfg =
        {
            .bits = 10,
            .channel = 0,
            .clock_speed_kHz = 1000
        };
    
    if (adc_devices_num >= ADC_DEVICES_NUM)
        return 0;

    if (adc_devices_num == 0)
    {
        /* The clock only needs to be enabled when sampling.  The clock is
           automatically started for the SAM7.  */
        mcu_pmc_enable (ID_ADC);
        
        adc_reset ();
    }

    adc = adc_devices + adc_devices_num;
    adc_devices_num++;
    
    adc->MR = 0;
    /* The transfer field must have a value of 2.  */
    BITS_INSERT (adc->MR, 2, 28, 29);

    if (!cfg)
        cfg = &adc_default_cfg;

    adc_config_set (adc, cfg);

    /* Note, the ADC is not configured until adc_config is called.  */
    adc_config (adc);

#if 0
    /* I'm not sure why a dummy read is required; it is probably a
       quirk of the SAM7.  This will require a software trigger... */
    adc_read (adc, &dummy, sizeof (dummy));
#endif

    return adc;
}


/** Returns true if a conversion has finished.  */
bool
adc_ready_p (adc_t adc)
{
    return (ADC->ADC_ISR & ADC_ISR_DRDY) != 0;
}


/** Blocking read.  This will hang if a trigger is not supplied
    (except for software triggering mode).  */
int8_t
adc_read (adc_t adc, void *buffer, uint16_t size)
{
    uint16_t i;
    uint16_t samples;
    adc_sample_t *data;

    adc_config (adc);

    samples = size / sizeof (adc_sample_t);
    data = buffer;

    for (i = 0; i < samples; i++)
    {
        /* When the ADC peripheral gets a trigger, it converts all the
           enabled channels consecutively in numerical order.  */

        if (adc->trigger == ADC_TRIGGER_SW)
            adc_conversion_start (adc);

        /* Should have timeout, especially for external trigger.  */
        while (!adc_ready_p (adc))
            continue;

        data[i] = ADC->ADC_LCDR;
    }

    /* Disable channel.  */
    ADC->ADC_CHDR = ~0;

    return samples * sizeof (adc_sample_t);
}
//function to initialize ports
void port_init (void)
{
	lcd_port_config();
	buzzer_pin_config();
	adc_config();
}
示例#14
0
void InitBattery()
{
	adc_config();
}
示例#15
0
/**
 * Initialize analog to digital converter
 */
void adc_init(adc_callback_t half_transfer_callback,
	      adc_callback_t transfer_complete_callback)
{
	/* Reset adc_state. */
	adc_state.dma_transfer_error_counter = 0;
	adc_state.half_transfer_callback = half_transfer_callback;
	adc_state.transfer_complete_callback = transfer_complete_callback;

	/* Initialize peripheral clocks. */
	rcc_peripheral_enable_clock(&RCC_AHBENR, RCC_AHBENR_DMA1EN);
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPAEN);
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN);
	rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC2EN);

	/* Initialize the ADC input GPIO. */
	/* WARNING: this code is written to work with strip. On the strip
	 * hardware we are lucky and all the ADC channels are on the same bank
	 * so we can initialize all of them in one go. This code will need to be
	 * changed/improved if we ever have to support hardware that has the
	 * ADC's spread over more then one bank.
	 */
	gpio_set_mode(ADC_BANK, GPIO_MODE_INPUT,
		      GPIO_CNF_INPUT_ANALOG, ADC_PORT_U_VOLTAGE |
		      ADC_PORT_V_VOLTAGE |
		      ADC_PORT_W_VOLTAGE |
		      ADC_PORT_V_BATT |
		      ADC_PORT_CURRENT);

	/* Configure DMA for data aquisition. */
	/* Channel 1 reacts to: ADC1, TIM2_CH3 and TIM4_CH1 */
	dma_channel_reset(DMA1, DMA_CHANNEL1);

	dma_set_peripheral_address(DMA1, DMA_CHANNEL1, (uint32_t)&ADC1_DR);
	dma_set_memory_address(DMA1, DMA_CHANNEL1,
			       (uint32_t)adc_state.raw_data);
	dma_set_number_of_data(DMA1, DMA_CHANNEL1, ADC_RAW_SAMPLE_COUNT/2);
	dma_set_read_from_peripheral(DMA1, DMA_CHANNEL1);
	dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL1);
	dma_enable_circular_mode(DMA1, DMA_CHANNEL1);
	dma_set_peripheral_size(DMA1, DMA_CHANNEL1, DMA_CCR_PSIZE_32BIT);
	dma_set_memory_size(DMA1, DMA_CHANNEL1, DMA_CCR_MSIZE_32BIT);
	dma_set_priority(DMA1, DMA_CHANNEL1, DMA_CCR_PL_VERY_HIGH);

	dma_enable_half_transfer_interrupt(DMA1, DMA_CHANNEL1);
	dma_enable_transfer_complete_interrupt(DMA1, DMA_CHANNEL1);
	dma_enable_transfer_error_interrupt(DMA1, DMA_CHANNEL1);

	dma_enable_channel(DMA1, DMA_CHANNEL1);

	/* Configure interrupts in NVIC. */
	nvic_set_priority(NVIC_DMA1_CHANNEL1_IRQ, 0);
	nvic_enable_irq(NVIC_DMA1_CHANNEL1_IRQ);

	/* Disable ADC's. */
	adc_off(ADC1);
	adc_off(ADC2);

	/* Enable dualmode. */
	adc_set_dual_mode(ADC_CR1_DUALMOD_RSM); /* Dualmode regular only. */

	/* Configure the adc channels. */
	adc_config(ADC1, adc1_channel_array);
	adc_config(ADC2, adc2_channel_array);

	/* Start converting. */
	adc_start_conversion_regular(ADC1);
}