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; }
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 ADC_IRQHandler(void) #endif { static uint16_t data; Chip_ADC_ReadValue(LPC_ADC, ADC_CH1, &data); #ifdef lpc4337_m4 static uint32_t cont; cont++; if (cont == 4) { cont = 0; #if(USAR_FUNCIONES_ASSEMBLER) asm_fir_q31_put(&filtro, data); #else fir_q31_put(&filtro, data); #endif } #else #if(USAR_FUNCIONES_ASSEMBLER) asm_fir_q31_put(&filtro, data>>2); #else fir_q31_put(&filtro, data>>2); #endif #endif adcFlag=1; }
/* 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; };
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); }
/** * Interrupt Handler called when ADC is finished. */ void ADC_IRQ_HANDLER(void) { /** * g_dataADC : result of ADC */ // Read ADC Channel 0 Chip_ADC_ReadValue(_LPC_ADC_ID, ADC_CH0, &g_dataADC); }
/** * @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; }
void SysTick_Handler(void) { uint16_t dataADC; //int i; uint32_t currentPWM; currentPWM=LPC_PWM1->MR1; //Board_LED_Toggle(0); Board_LED_Set(0,1); //Chip_ADC_SetStartMode(_LPC_ADC_ID, ADC_START_NOW, ADC_TRIGGERMODE_RISING); //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); /* if(rotation_time<MEMORY_CAPACITY){ rotation_debug_holder[rotation_time]=(int) dataADC; rotation_time++; } */ rotation_time++; //if(rotation_counter<MEMORY_CAPACITY){ //debug line if(dataADC>sensor_threshold){ if(rotation_phase==0){ //rotation_debug_holder[rotation_counter]=rotation_time; //debug line //rotation_debug_holder2[rotation_counter]=dataADC; //debug line if(currentPWM < (1000-regulation_step) && currentPWM > (regulation_step)){ //debug needed here if(rotation_time>desired_rotation_time){ PWM_SetCycle(currentPWM+regulation_step,1000); }else{ PWM_SetCycle(currentPWM-regulation_step,1000); } } rotation_counter++; rotation_time=0; rotation_phase=1; } }else{ rotation_phase = 0; } //} //debug line if(rotation_time==1000){ if(currentPWM < (1000-regulation_step)){ PWM_SetCycle(currentPWM+10*regulation_step,1000); } rotation_time=0; } Board_LED_Set(0,0); }
STATIC INLINE void printADCRead(uint8_t sensorId, uint8_t channel) { uint16_t data; if (Chip_ADC_ReadValue(LPC_ADC1, channel, &data) == SUCCESS) { xprintf("-S%d %u\n", sensorId, data); } else { xprintf("-S%d -1\n", sensorId); } }
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); }
void ADC_IRQHandler(void) { static uint16_t data; Chip_ADC_ReadValue(LPC_ADC, ADC_CH0, &data); #if(USAR_FUNCIONES_ASSEMBLER) asm_fir_q31_put(&filtro, data>>2); #else fir_q31_put(&filtro, data>>2); #endif adcFlag=1; }
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 ADC0 interrupt handler sub-routine * @return Nothing */ void ADC_IRQHandler(void) { uint16_t dataADC; /* Interrupt mode: Call the stream interrupt handler */ NVIC_DisableIRQ(_LPC_ADC_IRQ); Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, _ADC_CHANNLE, DISABLE); Chip_ADC_ReadValue(_LPC_ADC_ID, _ADC_CHANNLE, &dataADC); ADC_Interrupt_Done_Flag = 1; App_print_ADC_value(dataADC); if (DEBUGIN() != 'x') { NVIC_EnableIRQ(_LPC_ADC_IRQ); Chip_ADC_Int_SetChannelCmd(_LPC_ADC_ID, _ADC_CHANNLE, ENABLE); } else {Interrupt_Continue_Flag = 0; } }
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 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; }
/** \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; }
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; }
uint32_t LeerADC(uint8_t canal) { uint16_t aux; Chip_ADC_ReadValue(LPC_ADC0, canal, &aux); return aux; }
/** * @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; }
// funcion de atenci+on de interrupcion void MyEocAdcISR(void){ Chip_ADC_ReadValue(LPC_ADC0, 1, &adc_value); EOCFlag = 1; }
void batteryReport() { uint16_t adcRead; if (Chip_ADC_ReadValue(LPC_ADC1, 1, &adcRead) == SUCCESS) { uint32_t data = (adcRead * 2800 * VBAT_DIVISOR) >> 10; //divide by 1024 xprintf("-S0 %u\n", data); } else {
/** * The Systick handler is used for a lot more tasks than sensor timing. * It also provides a timer for decaying for the motor velocity, motor control * and second timer used for the LED blinking and Retina event rate. */ void SysTick_Handler(void) { // now the systick handler function is called every 1/50000 second static uint16_t second_timer = 0; static uint16_t data_left = 0; static uint16_t data_right = 0; static uint32_t debug_timer = 0; //static uint16_t data0,data1; #if USE_PUSHBOT static uint16_t one_k_hertz_timer = 0; static uint16_t ten_hertz_timer = 0; if (++ten_hertz_timer >= 5000) { // 100 ten_hertz_timer = 0; if (motor0.controlMode & DECAY_MODE) { if (motor0.decayCounter == 0) { if (motor0.controlMode & DIRECT_MODE) { if (motor0.requestedWidth != 0) { motor0.requestedWidth = (motor0.requestedWidth * 90) / 100; updateMotorWidth(0, motor0.requestedWidth); } } else { if (motor0.requestedVelocity > 0) { motor0.requestedVelocity--; } else if (motor0.requestedVelocity < 0) { motor0.requestedVelocity++; } } } else { motor0.decayCounter--; } } if (motor1.controlMode & (DECAY_MODE)) { if (motor1.decayCounter == 0) { if (motor1.controlMode & DIRECT_MODE) { if (motor1.requestedWidth != 0) { motor1.requestedWidth = (motor1.requestedWidth * 90) / 100; updateMotorWidth(1, motor1.requestedWidth); } } else { if (motor1.requestedVelocity > 0) { motor1.requestedVelocity--; } else if (motor1.requestedVelocity < 0) { motor1.requestedVelocity++; } } } else { motor1.decayCounter--; } } } if(one_k_hertz_timer == 50){ one_k_hertz_timer = 0; if (motor0.controlMode & VELOCITY_MODE) { motor0.updateRequired = 1; } if (motor1.controlMode & VELOCITY_MODE) { motor1.updateRequired = 1; } } #endif if (++second_timer >= 50000) { //1000 lastEventCount = events.currentEventRate; #if USE_SDCARD lastByteCount = sdcard.bytesWrittenPerSecond; lastEventRecordedCount = sdcard.eventsRecordedPerSecond; #endif __DSB(); //Ensure it has been saved events.currentEventRate = 0; #if USE_SDCARD sdcard.bytesWrittenPerSecond = 0; sdcard.eventsRecordedPerSecond = 0; #endif second_timer = 0; toggleLed0 = 1; } // send left&right channel adc values through serial if(++debug_timer >= 1000){ debug_timer = 0; if(stream_adc_flag){ if (Chip_ADC_ReadValue(LPC_ADC1, ADC1_CHANNEL, &data_left) == SUCCESS){ if (Chip_ADC_ReadValue(LPC_ADC1, ADC5_CHANNEL, &data_right) == SUCCESS){ xprintf("L%uR%u\r\n", data_left, data_right); } } } } /* //GET adc value every 1/50000 second // only when both channels successfully get the data that we increase the buf length //if(++debug_timer >= 100){ //xputs("1\n"); //debug_timer = 0; if(!buf_flag){ //xputs("22\n"); if(Chip_ADC_ReadValue(LPC_ADC1, ADC1_CHANNEL, &left0[buf_length]) == SUCCESS){ // &left0[buf_length].real //xputs("in1\n"); if(Chip_ADC_ReadValue(LPC_ADC1, ADC5_CHANNEL, &right0[buf_length]) == SUCCESS){ //xprintf(" %d\n", data0); //left0[buf_length].real = data0; //right0[buf_length].real = data1; if(++buf_length == BUFFER_MAX_SIZE){ buf_length = 0; buf_flag = !buf_flag; process_flag = 0; //xputs(">>>>>"); } } } }else{ //xputs("333\n"); if(Chip_ADC_ReadValue(LPC_ADC1, ADC1_CHANNEL, &left1[buf_length]) == SUCCESS){ //xputs("in2\n"); if(Chip_ADC_ReadValue(LPC_ADC1, ADC5_CHANNEL, &right1[buf_length]) == SUCCESS){ //xprintf(" %d\n", data0); //left1[buf_length].real = data0; //right1[buf_length].real = data1; if(++buf_length == BUFFER_MAX_SIZE){ buf_length = 0; buf_flag = !buf_flag; process_flag = 1; //xputs("<<"); } } } } //} */ /* for (int i = 0; i < sensorsEnabledCounter; ++i) { if (--enabledSensors[i]->counter == 0) { enabledSensors[i]->counter = enabledSensors[i]->reload; enabledSensors[i]->triggered = 1; sensorRefreshRequested = 1; } } */ }