Esempio n. 1
0
static uint16_t readADC(uint8_t id)
{
	uint16_t dataADC;
	uint16_t first;
	Chip_ADC_EnableChannel(LPC_ADC, id, ENABLE);
    Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

	/* Waiting for A/D conversion complete */
	while (Chip_ADC_ReadStatus(LPC_ADC, id, ADC_DR_DONE_STAT) != SET) {}
	/* Read ADC value */
	Chip_ADC_ReadValue(LPC_ADC, id, &first);

	Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

		/* Waiting for A/D conversion complete */
	while (Chip_ADC_ReadStatus(LPC_ADC, id, ADC_DR_DONE_STAT) != SET) {}
		/* Read ADC value */
	Chip_ADC_ReadValue(LPC_ADC, id, &dataADC);

	int32_t diff = first - dataADC;
	if(diff < 0 ) diff = -diff;
	while(diff > 200) {
		first = dataADC;
		Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

				/* Waiting for A/D conversion complete */
		while (Chip_ADC_ReadStatus(LPC_ADC, id, ADC_DR_DONE_STAT) != SET) {}
				/* Read ADC value */
		Chip_ADC_ReadValue(LPC_ADC, id, &dataADC);
		diff = first - dataADC;
		if(diff < 0 ) diff = -diff;
	}
	Chip_ADC_EnableChannel(LPC_ADC, id, DISABLE);
	return dataADC;
}
Esempio n. 2
0
void adc_read(uint8_t channel, uint16_t *data)
{
	Chip_ADC_EnableChannel(LPC_ADC, (ADC_CHANNEL_T)channel, ENABLE);
	/* Start A/D conversion */
	Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
	/* Waiting for A/D conversion complete */
	while (Chip_ADC_ReadStatus(LPC_ADC, (ADC_CHANNEL_T)channel, ADC_DR_DONE_STAT) != SET)
		;
	/* Read ADC value */
	Chip_ADC_ReadValue(LPC_ADC, channel, data);
	Chip_ADC_EnableChannel(LPC_ADC, (ADC_CHANNEL_T)channel, DISABLE);
	Chip_ADC_SetStartMode(LPC_ADC, ADC_NO_START, ADC_TRIGGERMODE_RISING);
}
Esempio n. 3
0
uint16_t LeerCanalADC(int canal){
	uint16_t* datos;
	Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
	while(Chip_ADC_ReadStatus(LPC_ADC0,ADC_CH1,ADC_DR_DONE_STAT)!=SET);
	Chip_ADC_ReadValue(LPC_ADC0, ADC_CH1, &datos);
	return datos;
};
Esempio n. 4
0
uint16_t readAdc (const adc_t adcNumber)
{
	uint16_t dataADC = 0;

	if ((adcNumber > 0) && (adcNumber < (sizeof (adc) / sizeof (adc_t)))) {
		/* Select using burst mode or not */
		if (ADCSetup.burstMode)
			Chip_ADC_SetBurstCmd (_LPC_ADC_ID, ENABLE);
		else
			Chip_ADC_SetBurstCmd (_LPC_ADC_ID, DISABLE);

		/* Start A/D conversion if not using burst mode */
		if (!ADCSetup.burstMode)
			Chip_ADC_SetStartMode (_LPC_ADC_ID, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

		/* Waiting for A/D conversion complete */
		while (Chip_ADC_ReadStatus (_LPC_ADC_ID, adc[adcNumber], ADC_DR_DONE_STAT) != SET);

		/* Read ADC value */
		Chip_ADC_ReadValue (_LPC_ADC_ID, adc[adcNumber], &dataADC);

		/* Disable burst mode, if any */
		if (ADCSetup.burstMode)
			Chip_ADC_SetBurstCmd (_LPC_ADC_ID, DISABLE);
	}

	return (dataADC);
}
Esempio n. 5
0
/* Polling routine for ADC example */
static void App_Polling_Test(void)
{
	uint16_t dataADC;

	/* Select using burst mode or not */
	if (Burst_Mode_Flag) {
		Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE);
	}
	else {
		Chip_ADC_SetBurstCmd(_LPC_ADC_ID, DISABLE);
	}

	/* Get  adc value until get 'x' character */
	while (DEBUGIN() != 'x') {
		/* Start A/D conversion if not using burst mode */
		if (!Burst_Mode_Flag) {
			Chip_ADC_SetStartMode(_LPC_ADC_ID, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
		}
		/* Waiting for A/D conversion complete */
		while (Chip_ADC_ReadStatus(_LPC_ADC_ID, _ADC_CHANNLE, ADC_DR_DONE_STAT) != SET) {}
		/* Read ADC value */
		Chip_ADC_ReadValue(_LPC_ADC_ID, _ADC_CHANNLE, &dataADC);
		/* Print ADC value */
		App_print_ADC_value(dataADC);
	}

	/* Disable burst mode, if any */
	if (Burst_Mode_Flag) {
		Chip_ADC_SetBurstCmd(_LPC_ADC_ID, DISABLE);
	}
}
Esempio n. 6
0
/* Interrupt routine for ADC example */
static void App_Interrupt_Test(void)
{
	/* Enable ADC Interrupt */
	NVIC_EnableIRQ(_LPC_ADC_IRQ);
	Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, _ADC_CHANNLE, ENABLE);
	/* Enable burst mode if any, the AD converter does repeated conversions
	   at the rate selected by the CLKS field in burst mode automatically */
	if (Burst_Mode_Flag) {
		Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE);
	}
	Interrupt_Continue_Flag = 1;
	ADC_Interrupt_Done_Flag = 1;
	while (Interrupt_Continue_Flag) {
		if (!Burst_Mode_Flag && ADC_Interrupt_Done_Flag) {
			ADC_Interrupt_Done_Flag = 0;
			Chip_ADC_SetStartMode(_LPC_ADC_ID, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
		}
	}
	/* Disable burst mode if any */
	if (Burst_Mode_Flag) {
		Chip_ADC_SetBurstCmd(_LPC_ADC_ID, DISABLE);
	}
	/* Disable ADC interrupt */
	NVIC_DisableIRQ(_LPC_ADC_IRQ);
}
Esempio n. 7
0
/**
 * @brief	main routine for ADC example
 * @return	Function should not exit
 */
int main(void)
{
	uint16_t dataADC;
	int j;

	SystemCoreClockUpdate();
	Board_Init();
	Init_ADC_PinMux();
	DEBUGSTR("ADC Demo\r\n");

	/* ADC Init */
	Chip_ADC_Init(LPC_ADC, &ADCSetup);
	Chip_ADC_EnableChannel(LPC_ADC, ADC_CH0, ENABLE);

	while (1) {
		/* Start A/D conversion */
		Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

		/* Waiting for A/D conversion complete */
		while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH0, ADC_DR_DONE_STAT) != SET) {}

		/* Read ADC value */
		Chip_ADC_ReadValue(LPC_ADC, ADC_CH0, &dataADC);

		/* Print ADC value */
		DEBUGOUT("ADC value is 0x%x\r\n", dataADC);

		/* Delay */
		j = 500000;
		while (j--) {}
	}

	/* Should not run to here */
	return 0;
}
Esempio n. 8
0
void InicializarADC()
{
	Chip_SCU_ADC_Channel_Config(ADC0,CANAL1); //adc_18xx_43xx.h”:
	Chip_ADC_Init(LPC_ADC0, &configclock );
	Chip_ADC_EnableChannel(LPC_ADC0, ADC_CH1, ENABLE);
	Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
	//Chip_ADC_ReadStatus(LPC_ADC_T *pADC, uint8_t channel, uint32_t StatusType);
}
Esempio n. 9
0
void Board_ADC_StartConversion(void)
{
        uint32_t index = 0; // always using ADC0
        flagWaitingADCConv=1;
        Chip_ADC_SetStartMode(adcsData[index].adc, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
        while(flagWaitingADCConv==1); // wait until conversion is finished

}
Esempio n. 10
0
uint16_t Board_TPS_2_ADC_Read(uint16_t *adc_data) {
	/* Enable this channel and disable all others (because burst mode not enabled) */
	Chip_ADC_EnableChannel(LPC_ADC, ADC_CH0, DISABLE);
	Chip_ADC_EnableChannel(LPC_ADC, ADC_CH1, ENABLE);
	/* Start A/D conversion */
    Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

    /* Waiting for A/D conversion complete */
    while (!Chip_ADC_ReadStatus(LPC_ADC, ADC_CH1, ADC_DR_DONE_STAT)) {}
    /* Read ADC value */
    Chip_ADC_ReadValue(LPC_ADC, ADC_CH1, adc_data);
}
Esempio n. 11
0
uint16_t ConvertDataADC(void)
{
	uint16_t dataADC;
    /*disparo conversion del ADC0, con Start Now*/
	Chip_ADC_SetStartMode(LPC_ADC0,ADC_START_NOW,ADC_TRIGGERMODE_RISING);
	/* ahora me quedo mirando un flag del registro del ADC0 que se va a poner a 1
	 * cuando termine de convertir. Entonces mientras sea diferente de 1, queda esperando*/

	while(Chip_ADC_ReadStatus(LPC_ADC0,ADC_CH1,ADC_DR_DONE_STAT)!=SET)
	{}

    Chip_ADC_ReadValue(LPC_ADC0, ADC_CH1, & dataADC);
    return dataADC;
}
Esempio n. 12
0
/*
 * @brief   Get the value of one ADC channel. Mode: BLOCKING
 * @param   AI0 ... AIn
 * @return  analog value
 */
uint16_t analogRead( uint8_t analogInput ){

   uint8_t lpcAdcChannel = 49 - analogInput;
   uint16_t analogValue = 0;

   Chip_ADC_EnableChannel(LPC_ADC0, lpcAdcChannel, ENABLE);
   Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

   while( (Chip_ADC_ReadStatus(LPC_ADC0, lpcAdcChannel, ADC_DR_DONE_STAT) != SET) );
   Chip_ADC_ReadValue( LPC_ADC0, lpcAdcChannel, &analogValue );

   Chip_ADC_EnableChannel( LPC_ADC0, lpcAdcChannel, DISABLE );

   return analogValue;
}
Esempio n. 13
0
/* DMA routine for ADC example */
static void App_DMA_Test(void)
{
	uint16_t dataADC;

	/* Initialize GPDMA controller */
	Chip_GPDMA_Init(LPC_GPDMA);
	/* Setting GPDMA interrupt */
	NVIC_DisableIRQ(DMA_IRQn);
	NVIC_SetPriority(DMA_IRQn, ((0x01 << 3) | 0x01));
	NVIC_EnableIRQ(DMA_IRQn);
	/* Setting ADC interrupt, ADC Interrupt must be disable in DMA mode */
	NVIC_DisableIRQ(_LPC_ADC_IRQ);
	Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, _ADC_CHANNLE, ENABLE);
	/* Get the free channel for DMA transfer */
	dmaChannelNum = Chip_GPDMA_GetFreeChannel(LPC_GPDMA, _GPDMA_CONN_ADC);
	/* Enable burst mode if any, the AD converter does repeated conversions
	   at the rate selected by the CLKS field in burst mode automatically */
	if (Burst_Mode_Flag) {
		Chip_ADC_SetBurstCmd(_LPC_ADC_ID, ENABLE);
	}
	/* Get  adc value until get 'x' character */
	while (DEBUGIN() != 'x') {
		/* Start A/D conversion if not using burst mode */
		if (!Burst_Mode_Flag) {
			Chip_ADC_SetStartMode(_LPC_ADC_ID, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
		}
		channelTC = 0;
		Chip_GPDMA_Transfer(LPC_GPDMA, dmaChannelNum,
						  _GPDMA_CONN_ADC,
						  (uint32_t) &DMAbuffer,
						  GPDMA_TRANSFERTYPE_P2M_CONTROLLER_DMA,
						  1);

		/* Waiting for reading ADC value completed */
		while (channelTC == 0) {}

		/* Get the ADC value fron Data register*/
		dataADC = ADC_DR_RESULT(DMAbuffer);
		App_print_ADC_value(dataADC);
	}
	/* Disable interrupts, release DMA channel */
	Chip_GPDMA_Stop(LPC_GPDMA, dmaChannelNum);
	NVIC_DisableIRQ(DMA_IRQn);
	/* Disable burst mode if any */
	if (Burst_Mode_Flag) {
		Chip_ADC_SetBurstCmd(_LPC_ADC_ID, DISABLE);
	}
}
Esempio n. 14
0
/** \brief ADC Ch1 Acquisition method by pooling */
uint16_t read_ADC_value_pooling(void)
{
	/** \details
	 * This function initialize the DAC peripheral in the EDU-CIAA board,
	 * with the correct parameters with LPCOpen methods.
	 *
	 * \param none
	 *
	 * \return uint8_t: TBD (to support errors in the init function)
	 * */
	uint16_t valueRead = 0 ;

	/** Start Acquisition */
	Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
	/** The pooling magic! */
	while (Chip_ADC_ReadStatus(LPC_ADC0, ADC_CH1, ADC_DR_DONE_STAT) != SET)
	{
		/** pooooliiinnggg maaagggicccc plif plif pluf pluf */
	}
	/** Conversion complete, and value reading */
	Chip_ADC_ReadValue(LPC_ADC0,ADC_CH1, &valueRead);

	return valueRead;
}
Esempio n. 15
0
void ADC_Start() {
	Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW,ADC_TRIGGERMODE_RISING);
}
Esempio n. 16
0
/**
 * @brief    Main routine for W5500 EVB firmware
 * @return   Function should not exit.
 */
int main(void) {

#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
#endif
#endif

    uint16_t dataADC;
    int16_t calc_temp;

    /* Flag for running user's code  */
    bool run_user_applications = true;

	/* Enable and setup SysTick Timer at a periodic rate */
	SysTick_Config(SystemCoreClock / TICKRATE_HZ1);

	/* ADC Init */
	Init_ADC_PinMux();
	Chip_ADC_Init(LPC_ADC, &ADCSetup);
	Chip_ADC_EnableChannel(LPC_ADC, TEMP_SENSOR_CH, ENABLE);

#ifdef _MAIN_DEBUG_
    printf("\r\n=======================================\r\n");
	printf(" WIZnet W5500 EVB\r\n");
	printf(" On-board Temperature sensor demo example v%d.%.2d\r\n", VER_H, VER_L);
	printf("=======================================\r\n");
	printf(">> This example using ADC, SysTick\r\n");
	printf("=======================================\r\n");
#endif

	/* Main loop ***************************************/
	while(1)
	{
    	// TODO: insert user's code here
    	if(run_user_applications)
    	{
    		if(ADC_read_enable)
    		{
    			ADC_read_enable = false;

				/* Start A/D conversion */
    			Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

				/* Waiting for A/D conversion complete */
				while (Chip_ADC_ReadStatus(LPC_ADC, TEMP_SENSOR_CH, ADC_DR_DONE_STAT) != SET) {}

				/* Read ADC value */
				Chip_ADC_ReadValue(LPC_ADC, TEMP_SENSOR_CH, &dataADC);

				/* Calculate ADC value to Celsius temperature */
				calc_temp = (((dataADC * SUPPLY_VOLTAGE) / 1023) - 500) / 10;

				/* Print ADC value */
				printf("ADC value is 0x%x, ", dataADC);
				/* Print Celsius temperature */
				printf("Celsius temperature : %d C\r\n", calc_temp);
    		}
    	} // End of user's code
	} // End of Main loop

    return 0;
}
Esempio n. 17
0
// funcion de atenci+on de interrupcion
void MyRITimerISR(void){
	Chip_ADC_SetStartMode(LPC_ADC0, ADC_START_NOW,ADC_TRIGGERMODE_RISING);
	Chip_RIT_ClearInt(LPC_RITIMER);

}
Esempio n. 18
0
void batteryInit() {
	Chip_ADC_SetStartMode(LPC_ADC1, ADC_START_NOW, ADC_TRIGGERMODE_RISING); //This must be before the burst cmd
	Chip_ADC_SetBurstCmd(LPC_ADC1, ENABLE);
	Chip_ADC_EnableChannel(LPC_ADC1, 1, ENABLE);
}
Esempio n. 19
0
__INLINE void skynetbase_windvane_start(void) {
	// activate adc
	Chip_ADC_EnableChannel(LPC_ADC, ADC_CHANNEL, DISABLE);
	Chip_ADC_EnableChannel(LPC_ADC, WINDVANE_ADC, ENABLE);
	Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);
}