/***************************************************************************** ** Main Function main() ******************************************************************************/ int main (void) { /* SystemClockUpdate() updates the SystemFrequency variable */ SystemClockUpdate(); /* Initialize ADC */ ADCInit( ADC_CLK ); while(1) { #if BURST_MODE /* Interrupt driven only */ ADCBurstRead(); while ( !ADCIntDone ); ADCIntDone = 0; if ( OverRunCounter != 0 ) { while ( 1 ); } #else /* Not burst mode */ #if ADC_INTERRUPT_FLAG /* Interrupt driven */ for ( i = 0; i < ADC_NUM; i++ ) { ADCRead( i ); while ( !ADCIntDone ); ADCIntDone = 0; } #else /* Polling */ for ( i = 0; i < ADC_NUM; i++ ) { ADCValue[i] = ADCRead( i ); } #endif /* Endif interrupt driven */ #endif /* Endif BURST mode */ } }
bool wallPresent(void){ rightSensor = ADCRead(adc[1])*1000; leftSensor = ADCRead(adc[2])*1000; if (rightSensor>450||leftSensor>450){ return true; } else { return false; } }
void followWall(void){ // includes avoiding other robots ////get sensor values frontSensor = ADCRead(adc[0])*1000; rightSensor = ADCRead(adc[1])*1000; leftSensor = ADCRead(adc[2])*1000; if (rightSensor>300 && rightSensor>leftSensor) { ///follow whichever wall is closer //////if right wall is closer if(frontSensor > 900){ ////back up and turn if wall ahead SetMotor(leftMotor, -1); SetMotor(rightMotor, -1); SysTick_Wait10ms(70); //reverse for 3 seconds turn90Degrees(LEFT); wasRightWall = true; wasLeftWall = false; } else if(rightSensor > 650){ SetMotor(leftMotor, -.25); SetMotor(rightMotor, .8); } else{ SetMotor(leftMotor, 1); SetMotor(rightMotor, .25); } } /////////if left wall is closer else if(leftSensor>300 && leftSensor>rightSensor){ if(frontSensor > 900){ ////back up and turn if wall ahead SetMotor(leftMotor, -1); SetMotor(rightMotor, -1); SysTick_Wait10ms(70); //reverse turn90Degrees(RIGHT); wasLeftWall = true; wasRightWall = false; } else if(leftSensor > 650){ SetMotor(leftMotor, .8); SetMotor(rightMotor, -.25); } else{ SetMotor(leftMotor, .25); SetMotor(rightMotor, 1); } } else { if (wasLeftWall) { SetMotor(leftMotor, 1); SetMotor(rightMotor, .7); } else { SetMotor(leftMotor, .7); SetMotor(rightMotor, 1); } } }
void squareDance(void){ int turns = 0; bool postTurn = true; bool clockWise; float sensor; rightSensor = ADCRead(adc[1])*1000; leftSensor = ADCRead(adc[2])*1000; if (rightSensor>leftSensor){ clockWise = true; }else{ clockWise = false; } while(turns < 4) { if (clockWise) {sensor = ADCRead(adc[1])*1000;}else{sensor = ADCRead(adc[2])*1000;} if (postTurn){ //////after we make a turn SetMotor(leftMotor, 1); SetMotor(rightMotor, 1); SysTick_Wait10ms(250); // go straight for a short time to get back by object do { if (clockWise) {sensor = ADCRead(adc[1])*1000;}else{sensor = ADCRead(adc[2])*1000;} }while(sensor > 400); postTurn = false; } else { SetMotor(leftMotor, 1); SetMotor(rightMotor, 1); /////keep going straight while no wall is close do { if (clockWise) {sensor = ADCRead(adc[1])*1000;}else{sensor = ADCRead(adc[2])*1000;} }while(sensor < 400); /////now that we have encountered a wall /////keep going straight until we have passed the wall so we can make turn do { if (clockWise) {sensor = ADCRead(adc[1])*1000;}else{sensor = ADCRead(adc[2])*1000;} }while(sensor > 400); SysTick_Wait10ms(70); /////stop briefly SetMotor(leftMotor, 0); SetMotor(rightMotor, 0); SysTick_Wait10ms(40); /////turn corner if (clockWise) {turn90Degrees(RIGHT);} else { turn90Degrees(LEFT);} turns += 1; postTurn = true; } } //////once we have made 4 turns we will stop SetMotor(leftMotor, 0); SetMotor(rightMotor, 0); while(true); }
void IRSensorDemo(void) { Printf("Press any key to quit\n"); while(!KeyWasPressed()) { float ADCValue = ADCRead(adc[0]); Printf("IR values: %d\t", (int)(1000 * ADCValue)); ADCValue = ADCRead(adc[1]); Printf(" %d\t", (int)(1000 * ADCValue)); ADCValue = ADCRead(adc[2]); Printf(" %d\t", (int)(1000 * ADCValue)); ADCValue = ADCRead(adc[3]); Printf(" %d\r", (int)(1000 * ADCValue)); } Printf("\n"); }
/****************************************************************************** ** Function name: MCPWM_IRQHandler ** ** Descriptions: MCPWM interrupt handler ** ** parameters: None ** Returned value: None ** ******************************************************************************/ void MCPWM_IRQHandler(void) { static uint32_t slowcounter = 0; volatile uint32_t regVal; regVal = LPC_MCPWM->INTEN; regVal = LPC_MCPWM->INTF; if (regVal & 0x01) // a result of lim0 counter expiring. This should go off at the pwm rate (currently 10kHz) { //start the ai read // device_on(FAN); // timing SSPIntReadACI (); if (++slowcounter >= 50) { // reset counter and choose next slowcounter = 0; // start next slow read ADCRead( schan ); } } LPC_MCPWM->INTF_CLR = regVal; return; }
void TIMER32_0_IRQHandler(void) { blinkCaller(); if(report_adc == 1) { ++adc_timer_counter; if(adc_timer_counter>(adc_report_speed*100)) { ADCRead( 0 ); adc_timer_counter = 0; } } if ( LPC_TMR32B0->IR & 0x01 ) { LPC_TMR32B0->IR = 1; /* clear interrupt flag */ timer32_0_counter++; } if ( LPC_TMR32B0->IR & (0x1<<4) ) { LPC_TMR32B0->IR = 0x1<<4; /* clear interrupt flag */ timer32_0_capture++; } /* if(timer32_0_counter%10==0){ char* value="Hello World!"; uint32_t stringLength = 12; UARTSend( (uint8_t*)value, stringLength ); } */ return; }
// ADC test mode for line following sensors void ADCTest() { while (1) { ADCRead(); } }
static void TestADC_CH0(void) { uint32_t adc_value; uint8_t value_string[8], index = 4; // We want to see only 4 digits adc_value = ADCRead(ADC_CH0); do { uint8_t temp; temp = (adc_value & 0x0f); if(temp>=10) { temp = temp - 10 + 'A'; } else { temp = temp + '0'; } index --; value_string[index] = temp; adc_value >>= 4; } while (index>0); WriteMultiByteToUARTRingBuffer(value_string,sizeof(value_string)); }
int main(void) { delay_ms(100); led_setup(); adc_init(); LCD_SETUP(buffer); tcp_setup.Gateway = GateWay;//Gateway Address tcp_setup.MAC = MAC; tcp_setup.Source_IP = IP;//IP Address tcp_setup.Source_Port = 80; // Web Port tcp_setup.Subnet = SubNet;//SubnetMask Address tcp_setup.s = 0; tcp_socket_init(&tcp_setup); while(1) { if(check_for_connections(&tcp_setup)) // Wait for connection) { process_request(&tcp_setup); tcp_socket_init(&tcp_setup); } sprintf(buffer2,"%d",ADCRead(0)); drawString8x12(10,60,buffer2); } }
void IRSensorDemo(void) { Printf("Press any key to quit\n"); // loop as long as the user doesn't press a key while (!KeyWasPressed()) { Printf( "IR values: front: %1.3f right: %1.3f left: %1.3f \r", ADCRead(adc[0]), ADCRead(adc[1]), ADCRead(adc[2]) //ADCRead(adc[3]) ); } Printf("\n"); }
void figureEight(void) { // Runtime code can go here frontSensor = ADCRead(adc[0])*1000; rightSensor = ADCRead(adc[1])*1000; leftSensor = ADCRead(adc[2])*1000; if(rightSensor > 300 && leftSensor < 300){ if (rightSensor > 700){ SetMotor(rightMotor, .2); //TURN RIGHT SetMotor(leftMotor, 1); }else{ SetMotor(rightMotor, .15); //TURN RIGHT SetMotor(leftMotor, 1); } wasRight = 1; wasLeft = 0; } else if(leftSensor > 300 && rightSensor < 300){ if (leftSensor>700){ SetMotor(rightMotor, 1); SetMotor(leftMotor,.2); }else{ SetMotor(rightMotor, 1); //TURN LEFT SetMotor(leftMotor, .15); } wasLeft = 1; wasRight = 0; } else if (leftSensor>300 && rightSensor>300) { if (wasRight){ SetMotor(leftMotor, .2); SetMotor(rightMotor, 1); }else if (wasLeft){ SetMotor(leftMotor, 1); SetMotor(rightMotor, .2); } } else{ SetMotor(leftMotor, 1); SetMotor(rightMotor, 1); wasLeft = 0; wasRight = 0; } }
int readTemperature(void) { GPIO_SetValue(TEMP_SENSE_EN_PORT, TEMP_SENSE_EN_BIT, ON); scandal_delay(200); ADCRead(ADC_TEMP); GPIO_SetValue(TEMP_SENSE_EN_PORT, TEMP_SENSE_EN_BIT, OFF); return ADCValue[ADC_TEMP]; //error checking? }
int readVoltage(void) { GPIO_SetValue(VOLT_SENSE_EN_PORT, VOLT_SENSE_EN_BIT, ON); scandal_delay(200); ADCRead(ADC_VOLT); GPIO_SetValue(VOLT_SENSE_EN_PORT, VOLT_SENSE_EN_BIT, OFF); return ADCValue[ADC_VOLT]; //error checking? }
int readRight(void){int cmdist; inputR = ADCRead(adc[2]); inputR *= 3.3; Printf("%fV ", inputR); if(inputR > 2.2){return -1;} // too close if(inputR >= 1.1){//10-20cm , 1.3+ V : distance = -10.2 * input voltage + 33.6. distance = (-2611*input + 8627) >> 8 cmdist = (int)(-2611*inputR + 8627); cmdist = cmdist >> 8; if(cmdist<10){return 0;} return cmdist-offset; // offset }
testKeithley2100Lib::testKeithley2100Lib(QWidget *parent) : QWidget(parent) { ui.setupUi(this); ADCTimer = new QTimer(this); connect(ADCTimer, SIGNAL(timeout()), this, SLOT(ADCRead())); QPluginLoader loader4("libKeithley2100Lib.so", this); KDmm = qobject_cast<IKeithley2100Interface*> (loader4.instance()); }
bool ModuloRead(uint8_t command, ModuloReadBuffer *buffer) { switch(command) { case FUNCTION_GET_TEMPERATURE: buffer->AppendValue<uint16_t>(static_cast<uint16_t>(temperature)); return true; case FUNCTION_GET_RAW_VALUE: buffer->AppendValue<uint16_t>( ADCRead(11)); return true; } return false; }
uint32_t readReflexChannel(uint32_t channel) { uint32_t reflexValue; reflexValue = ADCRead( channel ); //Correct, switch dir at white if( reflexValue <= 850 ) { return 1; //i+5 } return 0; }
int readAnalog(void* params) { struct analogParams* par = (struct analogParams*) params; ADCSetChannel(par->channel); ADCStartConversion(); uint16_t adc = 0; while (ADCRead(&adc)) { NutThreadYield(); } //TODO zrobić coś z adc //return (adc >> 1) - 183; return adc; }
int main(void) { /* Start led connected to P1.29 and P1.18 */ LPC_GPIO1->FIODIR |= 0x20040000; LPC_GPIO1->FIOSET |= (1 << 29); LPC_GPIO1->FIOCLR |= (1 << 18); SystemInit(); // lpc1768_startup.c SystemCoreClockUpdate(); GPIOInit(); TimerInit(); ValueInit(); ADCInit(); comm_init(); // welcomeMsg(); set_echo(); easyWEB_init(); printchar("at+ndhcp=1\r"); printchar("at+wa=greenet\r"); printchar("at+nstcp=20\r"); printchar(" \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); while(1) { easyWEB_s_loop(); //handle_command(); //UART command if(UpdateChannel >= 3) { UpdateChannel = -1; ADCRead(0); if (mode ==1) //decide which ADC channel to read when the converter is working in different direction { Vout = ADCValues(0); Vin = ADCValues(1); } else { Vout = ADCValues(1); Vin = ADCValues(0); } Iref = ADCValues(2); Il = abs (ADCValues(3) - Iref); //get the correct inductor current MeanValues(); BangBang(); LPC_GPIO1->FIOPIN ^= (1 << 29); LPC_GPIO1->FIOPIN ^= (1 << 18); } } return 0; }
int myadc_getrandomseed(void){ int i,tmp,seed; ADCInit(1000000); for(i=0;i<8;i++){ tmp=ADCRead(i); tmp&=0x7; //three bits seed|=(tmp<<(i*3)); } //ADCDeinit(); seed=seed; return seed; }
uint16_t reflexRead() { uint32_t i = 0; //for ( i = 0; i < REFLEX_NUM; i++ ) //{ reflexValue[i] = ADCRead( 5 ); if( reflexValue[i] >= 500 ) { return 1; } //} return 0; }
void competition(void){ runRoller(); // float wdist = .10f; // while(ADCRead(adc[0]) > .20f){ // linefollow(); // } // setm(.75f,.25f); float i = .20f; while(i<.70f){ while(1){ wallfollow(.20f,ADCRead(adc[0])); } i+=.10f; } }
void ISR_TIMER(void) { uint16_t LecturaADC; LecturaADC = A * ADCRead(); Led1Toggle(); if(LecturaADC > 1023) LecturaADC = 1023; if(LecturaADC < 10) LecturaADC = 0; DACUpdate(LecturaADC); TimerClearFlag(); }
int main(void) { uint8_t led = 0; GPIOInit(); ADCInit(ADC_CLK); init_timer32(0, 10); GPIOSetDir(PORT0, 7, 1); while (1) { uint32_t value = ADCRead(0); delay32Ms(0, value); GPIOSetValue(PORT0, 7, led); led = !led; } return 0; }
int testSPI::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: on_pushButton_clicked(); break; case 1: on_SelectADC_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: on_testFileLoad_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 3: on_testFile_clicked(); break; case 4: on_horizontalSlider_valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 5: on_DCVolt_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 6: on_ReadAll_clicked(); break; case 7: on_Reset_clicked(); break; case 8: on_SelectApp_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 9: on_AppWrite_clicked(); break; case 10: on_AppRead_clicked(); break; case 11: on_SelectPart_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 12: on_SelectMode_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 13: on_Exit_clicked(); break; case 14: on_SelectSPI_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 15: on_SelectOperation_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 16: on_Execute_clicked(); break; case 17: receiveValue((*reinterpret_cast< uint(*)>(_a[1]))); break; case 18: receiveValue((*reinterpret_cast< double(*)>(_a[1]))); break; case 19: receiveValue((*reinterpret_cast< QString(*)>(_a[1]))); break; case 20: callAddressEdit(); break; case 21: callDataEdit(); break; case 22: callAppAddressEdit(); break; case 23: callAppDataEdit(); break; case 24: callMaskDataEdit(); break; case 25: callSPIClockEdit(); break; case 26: callDMMAddrEdit(); break; case 27: callAvgEdit(); break; case 28: ADCRead(); break; default: ; } _id -= 29; } return _id; }
void squaredance(void){ int p=0; while(p<4){ setm(.5f,.5f); if(ADCRead(adc[2])>.4f){ Wait(3.0f); ledRed(); setm(0.0f,0.5f); Wait(3.45f); setm(.5f,.5f); Wait(2.0f); p+=1; } else{ ledBlue(); } } setm(0.0f,0.0f); }
void feight(void){ while(1){ setm(.5f,.5f); if(ADCRead(adc[2])>.4f){ ledRed(); Wait(3.0f); setm(0.0f,0.7f); Wait(3.0f); setm(0.5f,0.5f); Wait(2.0f); setm(0.0f,0.7f); Wait(3.0f); setm(0.5f,0.5f); Wait(2.0f); } else{ ledBlue(); } } }
uint32_t reflexReadAnalog() { uint32_t i = 0; uint32_t reflexValue; for ( i = 0; i < 4; i++ ) { reflexValue = ADCRead( i ); //Correct, switch dir at white if( reflexValue <= 850 ) { return i; //i+5 } //Inverterted, switch dir at black /*if( reflexValue >= 950 ) { return i; //i+5 }*/ } return 4; }
/****************************************************************************** ** Function name: shunt_read ** ** Description: Reads ADC values for V and I ** ** Parameters: None ** Returned value: None ** ******************************************************************************/ void shunt_read (void) { float ADC_B, ADC_C; int i = 0; bmu_data.bus_v = iir_filter_float((float)(ADCRead(0) + ADCRead(0) + ADCRead(0) + ADCRead(0) + ADCRead(0) + ADCRead(0) + ADCRead(0) + ADCRead(0))/(8.0 * V_DIVIDER), bmu_data.bus_v, IIR_GAIN_ELECTRICAL); for(i = 0; i<64;i++) { ADC_B += (float)ADCRead(1); ADC_C += (float)ADCRead(2); } ADC_B /= 64.0; ADC_C /= 64.0; ADC_B = (ADC_B_CAL - ADC_B) / ADC_B_SCALE; ADC_C = (ADC_C_CAL - ADC_C) / ADC_C_SCALE; bmu_data.bus_i = iir_filter_float((ADC_B+ADC_C)/2.0, bmu_data.bus_i, IIR_GAIN_ELECTRICAL); bmu_data.watts = bmu_data.bus_i * bmu_data.bus_v; }