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; }
void ADC0_IRQHandler (void) { uint16_t value; uint32_t index = 0; // always using ADC0 if(Chip_ADC_ReadStatus(adcsData[index].adc, ADC_CH1, ADC_DR_ADINT_STAT) == SET) { Chip_ADC_ReadValue(adcsData[index].adc, ADC_CH1, &value); ADCValues[0] = value; } if(Chip_ADC_ReadStatus(adcsData[index].adc, ADC_CH2, ADC_DR_ADINT_STAT) == SET) { Chip_ADC_ReadValue(adcsData[index].adc, ADC_CH2, &value); ADCValues[1] = value; } if(Chip_ADC_ReadStatus(adcsData[index].adc, ADC_CH3, ADC_DR_ADINT_STAT) == SET) { Chip_ADC_ReadValue(adcsData[index].adc, ADC_CH3, &value); ADCValues[2] = value; } flagWaitingADCConv=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; }
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); }
/* 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); } }
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; };
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); }
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); }
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; }
/* * @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; }
uint16_t skynetbase_windvane_measure(void) { skynetbase_windvane_start(); // Waiting for A/D conversion complete while (Chip_ADC_ReadStatus(LPC_ADC, WINDVANE_ADC, ADC_DR_DONE_STAT) != SET) {} // Read ADC value Chip_ADC_ReadValue(LPC_ADC, WINDVANE_ADC, &windvane_buffer); skynetbase_windvane_stop(); uint32_t upscaled = (uint32_t)windvane_buffer * (uint32_t)windvane_max_target; return upscaled / windvane_max; }
/** \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; }
/** * @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; }
int ADC_GetValue() { uint16_t value; while(Chip_ADC_ReadStatus(LPC_ADC0,ADC_CH1,ADC_DR_DONE_STAT) != SET); Chip_ADC_ReadValue(LPC_ADC0,ADC_CH1,&value); return value; }