int main() { u08 i; i = 0; u08 adc_0, adc_1; setup(); while(1==1) { adc_0 = a2dConvert8bit(ADC_CH_ADC0); adc_1 = a2dConvert8bit(ADC_CH_ADC1); rprintfu08(adc_0); rprintfu08(adc_1); rprintfChar(0); // rprintfCRLF(); _delay_ms(32); /* i++; if(i<=128) { sbi(PORTB, PB3); } if(i>128) { cbi(PORTB, PB3); } */ //_delay_ms(32); //_delay_ms(32); //_delay_ms(32); } return 0; }
//----- Begin Code ------------------------------------------------------------ int main(void) { u16 a=0; u08 i=0; // initialize our libraries // initialize the UART (serial port) uartInit(); // make all rprintf statements use uart for output rprintfInit(uartSendByte); // initialize the timer system timerInit(); // turn on and initialize A/D converter a2dInit(); // print a little intro message so we know things are working vt100ClearScreen(); vt100SetCursorPos(1,1); rprintf("Welcome to the a2d test!\r\n"); // configure a2d port (PORTA) as input // so we can receive analog signals DDRA = 0x00; // make sure pull-up resistors are turned off PORTA = 0x00; // set the a2d prescaler (clock division ratio) // - a lower prescale setting will make the a2d converter go faster // - a higher setting will make it go slower but the measurements // will be more accurate // - other allowed prescale values can be found in a2d.h a2dSetPrescaler(ADC_PRESCALE_DIV32); // set the a2d reference // - the reference is the voltage against which a2d measurements are made // - other allowed reference values can be found in a2d.h a2dSetReference(ADC_REFERENCE_AVCC); // use a2dConvert8bit(channel#) to get an 8bit a2d reading // use a2dConvert10bit(channel#) to get a 10bit a2d reading while(1) { // sample all a2d channels and print them to the terminal vt100SetCursorPos(2,1); for(i=0; i<8; i++) { rprintf("Channel %d: %d \r\n", i, a2dConvert8bit(i)); } // print the sample number so far rprintf("Sample # : %d \r\n", a++); } return 0; }
//----- Begin Code ------------------------------------------------------------ int main(void) { uint8_t a=0; // initialize our libraries // initialize the UART (serial port) uartInit(); // make all rprintf statements use uart for output rprintfInit(uartSendByte); // turn on and initialize A/D converter a2dInit(); // initialize the timer system timerInit(); // print a little intro message so we know things are working rprintf("\r\nWelcome to AVRlib!\r\n"); // initialize LCD lcdInit(); // direct printf output to LCD rprintfInit(lcdDataWrite); // print message on LCD rprintf("Welcome to AVRlib!"); DDRA = 0x00; PORTA = 0x00; // display a bargraph of the analog voltages on a2d channels 0,1 while(1) { lcdGotoXY(0,0); lcdProgressBar(a2dConvert8bit(0), 255, 20); rprintf(" X: %d", a2dConvert8bit(0)); rprintf(" Sample: %d", a++); lcdGotoXY(0,1); lcdProgressBar(a2dConvert8bit(1), 255, 20); rprintf(" Y: %d", a2dConvert8bit(1)); } return 0; }
void sensor_monitoring_user() //Called from mmc_main.c /***************************/ { sens[TEMPERATURE_SENSOR1].value = tempSensorRead(TEMPERATURE_SENSOR1); if (run_type == INCRATE) check_temp_event(TEMPERATURE_SENSOR1); sens[TEMPERATURE_SENSOR2].value = tempSensorRead(TEMPERATURE_SENSOR2); if (run_type == INCRATE) check_temp_event(TEMPERATURE_SENSOR2); sens[VOLT_12].value = a2dConvert8bit(0); //MJ: Why is there a voltage related command in a function that deals with temperature? }
int main(void) { u08 adc_1, adc_2, adc_3, adc_4, adc_5; u08 i; setup(); while(1==1) { //rprintfStr("Hello"); adc_1 = a2dConvert8bit(ADC_CH_ADC1); adc_2 = a2dConvert8bit(ADC_CH_ADC2); adc_3 = a2dConvert8bit(ADC_CH_ADC3); adc_4 = a2dConvert8bit(ADC_CH_ADC4); adc_5 = a2dConvert8bit(ADC_CH_ADC5); rprintfu08(adc_1); // rprintfu08(adc_2); // rprintfu08(adc_3); // rprintfu08(adc_4); // rprintfu08(adc_5); rprintfCRLF(); _delay_ms(32); i++; } return 0; }
DISTANCE_TYPE _gp2_read(ADC_CHANNEL adc, const SHARP* table, uint8_t entries){ int16_t adc8 = (int16_t)a2dConvert8bit(adc); int16_t minAdc =0; int16_t maxAdc; while(maxAdc=(int16_t)(pgm_read_byte(&table->end_adc)), adc8 > maxAdc ){ minAdc = maxAdc+1; table++; } DISTANCE_TYPE minDist = pgm_read_word(&table->minDist); DISTANCE_TYPE maxDist = pgm_read_word(&table->maxDist); uint16_t result = interpolate(adc8, minAdc,maxAdc, (int16_t)minDist, (int16_t)maxDist); return (DISTANCE_TYPE)result; }
void sensor_monitoring_user() //Called from mmc_main.c /***************************/ { sens[TEMPERATURE_SENSOR1].value = tempSensorRead(TEMPERATURE_SENSOR1); //MJMJ: code missing? if (run_type == INCRATE) check_temp_event(TEMPERATURE_SENSOR1); sens[TEMPERATURE_SENSOR2].value = tempSensorRead(TEMPERATURE_SENSOR2); if (run_type == INCRATE) check_temp_event(TEMPERATURE_SENSOR2); sens[TEMPERATURE_SENSOR3].value = tempSensorRead(TEMPERATURE_SENSOR3); if(run_type == INCRATE) check_temp_event(TEMPERATURE_SENSOR3); sens[VOLT_12].value = a2dConvert8bit(0); }
void oscope(void) { u08 i=0; u08 oldbuffer[128]; u08 newbuffer[128]; glcdClearScreen(); while(1) { for(i=0; i<128; i++) oldbuffer[i] = newbuffer[i]; for(i=0; i<128; i++) newbuffer[i] = a2dConvert8bit(0); for(i=0; i<128; i++) { glcdClearDot(i,oldbuffer[i]>>2); glcdSetDot(i,newbuffer[i]>>2); } } }
void control() { unsigned right_rotHi = 0; unsigned right_rotLo = 0; int rightCount = 0; unsigned left_rotHi = 0; unsigned left_rotLo = 0; int leftCount = 0; int right_rotState =a2dConvert8bit(0);//right rotations //int se1 =a2dConvert8bit(1); int right_direction =a2dConvert8bit(3);//right direction, forward = low, reverse = hi int left_direction =a2dConvert8bit(7);//left direction, forward = hi, reverse = low int left_rotState =a2dConvert8bit(8);//left rotations //int se5 =a2dConvert8bit(9); while( uart1GetByte() != 'x') { if( 0 <= right_rotState && 10 > right_rotState ) //if rotState is low { right_rotLo++; } if( 250 < right_rotState && 255 >= right_rotState ) //if rotState is high { right_rotHi++; } if( 0 <= left_rotState && 10 > left_rotState) //if rotState is low { left_rotLo++; } if( 250 < left_rotState && 255 >=left_rotState) //if rotState is high { left_rotHi++; } //--------------------------- if( right_rotLo > 0 && right_rotHi > 0)//if the encoder has seen both white and black { if( 0 <= right_direction && right_direction < 10) { rightCount++; } if( 250 < right_direction && right_direction <= 255) { rightCount--; } right_rotLo = 0; right_rotHi = 0; } if( left_rotLo > 0 && left_rotHi > 0)//if the encoder has seen both white and black { if( 0 <= left_direction && left_direction < 10) { leftCount--; } if( 250 < left_direction && left_direction <= 255) { leftCount++; } left_rotLo = 0; left_rotHi = 0; } rprintf(" %d, %d, %d, %d \n %d %d %d %d \n",left_rotLo,left_rotHi, left_direction,leftCount,right_rotLo,right_rotHi,right_direction,rightCount); rprintf("LEFT DIR:%d, LEFT DST:%d, RIGHT DIR:%d, RIGHT DST:%d\n,",left_direction,leftCount,right_direction, rightCount); right_rotState =a2dConvert8bit(0);//right rotations right_direction =a2dConvert8bit(3);//right direction, forward = low, reverse = hi left_direction =a2dConvert8bit(7);//left direction, forward = hi, reverse = low left_rotState =a2dConvert8bit(8);//left rotations } /* unsigned right_rotHi = 0; if( 250 < left_direction && left_direction <= 255) {leftCount++;} left_rotLo = 0; left_rotHi = 0; } //rprintf(" %d, %d, %d, %d \n %d %d %d %d \n",left_rotLo,left_rotHi, left_direction,leftCount,right_roLo,right_rotHi,right_direction,rightCount); //rprintf("LEFT DIR:%d, LEFT DST:%d, RIGHT DIR:%d, RIGHT DST:%d\n,",left_direction,leftCount,right_direction, rightCount); right_rotState =a2dConvert8bit(0);//right rotations right_direction =a2dConvert8bit(3);//right direction, forward = low, reverse = hi left_direction =a2dConvert8bit(7);//left direction, forward = hi, reverse = low left_rotState =a2dConvert8bit(8);//left rotations } int control_PID( ) { } void update_motors() { //Right 607-640 braking range //left 613-633 braking range if(motorLeftSpeed<613||motorLeftSpeed>633) { wheel_Left(motorLeftSpeed); } if(motorRightSpeed<607||motorRightSpeed>640) { wheel_Right(motorRightSpeed); } }*/ }
void test_oscope(void) { int se0,se1,se2,se3,se4,se5,se6,se7,se8; int se9,se10,se11,se12,se13,se14,se15; LED_on(); if (button_pressed()) LED_off(); //pulse each fast for oscope testing //right row servo(PORTC,0,360); servo(PORTC,1,360); servo(PORTC,2,360); servo(PORTC,3,360); servo(PORTC,4,360); servo(PORTC,5,360); servo(PORTC,6,360); servo(PORTC,7,360); servo(PORTJ,6,360); servo(PORTA,0,360); servo(PORTA,1,360); servo(PORTA,2,360); servo(PORTA,3,360); servo(PORTA,4,360); servo(PORTA,5,360); servo(PORTA,6,360); servo(PORTA,7,360); //left row servo(PORTE,2,360); servo(PORTE,3,360); servo(PORTE,4,360); servo(PORTE,5,360); servo(PORTE,6,360); servo(PORTE,7,360); servo(PORTH,2,360); servo(PORTH,3,360); servo(PORTH,4,360); servo(PORTH,5,360); servo(PORTH,6,360); //top row se0=a2dConvert8bit(0); se1=a2dConvert8bit(1); se2=a2dConvert8bit(2); se3=a2dConvert8bit(3); se4=a2dConvert8bit(4); se5=a2dConvert8bit(5); se6=a2dConvert8bit(6); se7=a2dConvert8bit(7); se8=a2dConvert8bit(8); se9=a2dConvert8bit(9); se10=a2dConvert8bit(10); se11=a2dConvert8bit(11); se12=a2dConvert8bit(12); se13=a2dConvert8bit(13); se14=a2dConvert8bit(14); se15=a2dConvert8bit(0x0f);//15 rprintfInit(uart1SendByte); rprintf("0:%d 1:%d 2:%d 3:%d 4:%d 5:%d 6:%d 7:%d \r\n",se0,se1,se2,se3,se4,se5,se6,se7); rprintf("8:%d 9:%d 10:%d 11:%d 12:%d 13:%d 14:%d 15:%d \r\n",se8,se9,se10,se11,se12,se13,se14,se15); rprintfInit(uart0SendByte); rprintf(" 0"); rprintfInit(uart2SendByte); rprintf(" 2"); rprintfInit(uart3SendByte); rprintf(" 3"); delay_cycles(65500); }
void update_sensors(void) { sensor_right=a2dConvert8bit(2)+auto_calib_R; sensor_left=a2dConvert8bit(14)+auto_calib_L;//right sensor is off, so I fudged it . . . mmmmm fudge! }
void control(void) { reset_timer5(); uartFlushReceiveBuffer(1); a2dSetReference(ADC_REFERENCE_256V); delay_us(100); PORT_OFF(PORTB,7); while(1) { char read = uart1GetByte(); if(read == 'U') { //Rangefinder only for the Hand! We only have 3 uart ports! uart0SendByte(0x22); //sends 4 bytes with the command to read distance (0x22) uart0SendByte(0x00); uart0SendByte(0x00);uart0SendByte(0x22);delay_us(50); uart0GetByte(); //we don't care about this byte rprintf("%d\r\n", 255*uart0GetByte() + uart0GetByte()); uart0GetByte(); //we don't care about this byte } else if(read == 'L') { rprintf("%d\r\n", 255 - a2dConvert8bit(0)); } else if(read == 'R') { rprintf("%d\r\n", 255 - a2dConvert8bit(1)); } else if(read == 'D') { int buff='#'; uart2SendByte('#'); uart2SendByte('o'); uart2SendByte('s'); uart2SendByte('#'); uart2SendByte('f'); delay_ms(60); // Do not change this delay or you'll get in trouble! while(1) { buff = uart2GetByte(); if(buff==10 || buff==13 || buff==-1) { uart1SendByte('\r'); uart1SendByte('\n'); break; } uart1SendByte(buff); } while((buff=uart2GetByte()) != -1); } else if(read == 'E') { int buff='#'; uart3SendByte('#'); uart3SendByte('o'); uart3SendByte('s'); uart3SendByte('#'); uart3SendByte('f'); delay_ms(60); // Do not change this delay or you'll get in trouble! while(1) { buff = uart3GetByte(); if(buff==10 || buff==13 || buff==-1) { uart1SendByte('\r'); uart1SendByte('\n'); break; } uart1SendByte(buff); } while((buff=uart3GetByte()) != -1); } else if(read == 'M') { int buff='#'; uart2SendByte('#'); uart2SendByte('o'); uart2SendByte('t'); uart2SendByte('#'); uart2SendByte('f'); delay_ms(60); // Do not change this delay or you'll get in trouble! while(1) { buff = uart2GetByte(); if(buff==10 || buff==13 || buff==-1) { uart1SendByte('\r'); uart1SendByte('\n'); break; } uart1SendByte(buff); } while((buff=uart2GetByte()) != -1); } else if(read == 'N') { int buff='#'; uart3SendByte('#'); uart3SendByte('o'); uart3SendByte('t'); uart3SendByte('#'); uart3SendByte('f'); delay_ms(60); // Do not change this delay or you'll get in trouble! while(1) { buff = uart3GetByte(); if(buff==10 || buff==13 || buff==-1) { uart1SendByte('\r'); uart1SendByte('\n'); break; } uart1SendByte(buff); } while((buff=uart3GetByte()) != -1); } else if(read == 'P') { PORT_ON(PORTB,6); } else if(read == 'p') { PORT_OFF(PORTB,6); } else if(read == 'Q') { PORT_ON(PORTB,7); } else if(read == 'q') { PORT_OFF(PORTB,7); } else if(read == 'X') { PORT_ON(PORTB,4); } else if(read == 'x') { PORT_OFF(PORTB,4); } else if(read == 'Y') { PORT_ON(PORTB,5); } else if(read == 'y') { PORT_OFF(PORTB,5); } delay_us(50); } }
int main(void) { /****************INITIALIZATIONS*******************/ //other stuff Im experimenting with for SoR uartInit(); // initialize the UART (serial port) uartSetBaudRate(0, 9600); // set UARTE speed, for Bluetooth uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it uartSetBaudRate(2, 57600); // set UARTH speed uartSetBaudRate(3, 57600); // set UARTJ speed, for Blackfin //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx) // initialize rprintf system and configure uart1 (USB) for rprintf rprintfInit(uart1SendByte); configure_ports(); // configure which ports are analog, digital, etc. LED_on(); rprintf("\r\nSystem Warming Up"); // initialize the timer system (comment out ones you don't want) init_timer0(TIMER_CLK_1024); init_timer1(TIMER_CLK_64); init_timer2(TIMER2_CLK_64); init_timer3(TIMER_CLK_64); init_timer4(TIMER_CLK_64); init_timer5(TIMER_CLK_1024); //timer5Init(); a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage int i = 0, j = 0; //let system stabelize for X time for(i=0;i<16;i++) { j=a2dConvert8bit(i);//read each ADC once to get it working accurately delay_cycles(5000); //keep LED on long enough to see Axon reseting rprintf("."); } LED_off(); rprintf("Initialization Complete \r\n"); reset_timer0(); reset_timer1(); reset_timer2(); reset_timer3(); reset_timer4(); reset_timer5(); while(1) { control(); delay_cycles(100); //an optional small delay to prevent crazy oscillations } return 0; }
void prvSetupHardware(){ int i, j; //add 1.7s delay for potential power issues delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); delay_cycles(65535); uartInit(); // initialize the UART (serial port) uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection, up to 500k, try 115200 if it doesn't work uartSetBaudRate(2, 38400); // set UARTH speed uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx) rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf configure_ports(); // configure which ports are analog, digital, etc. LED_on(); //rprintf("\r\nSystem Warmed Up"); // initialize the timer system init_timer0(TIMER_CLK_1024); // init_timer1(TIMER_CLK_64); // Timer 1 is initialized by FreeRTOS init_timer2(TIMER2_CLK_64); init_timer3(TIMER_CLK_64); init_timer4(TIMER_CLK_64); init_timer5(TIMER_CLK_64); a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage //let system stabelize for X time for(i=0;i<16;i++) { j=a2dConvert8bit(i);//read each ADC once to get it working accurately delay_cycles(5000); //keep LED on long enough to see Axon reseting rprintf("."); } LED_off(); rprintf("Initialization Complete \r\n"); //reset all timers to zero reset_timer0(); reset_timer1(); reset_timer2(); reset_timer3(); reset_timer4(); reset_timer5(); /********PWM Setup***********/ prvPWMSetup(); }
// This routine is called once to allow you to set up any other variables in your program // You can use 'clock' function here. // The loopStart parameter has the current clock value in μS TICK_COUNT appInitSoftware(TICK_COUNT loopStart){ act_setSpeed(&servo_0,DRIVE_SPEED_CENTER); act_setSpeed(&servo_1,DRIVE_SPEED_CENTER); act_setSpeed(&servo_2,DRIVE_SPEED_CENTER); act_setSpeed(&servo_3,DRIVE_SPEED_CENTER); act_setSpeed(&servo_4,DRIVE_SPEED_CENTER); act_setSpeed(&servo_5,DRIVE_SPEED_CENTER); // starting values for trims. data[RX_SERVO_0_CH] = eeprom_read_byte(&data_eeprom[RX_SERVO_0_CH]); data[RX_SERVO_0_CL] = eeprom_read_byte(&data_eeprom[RX_SERVO_0_CL]); data[RX_SERVO_1_CH] = eeprom_read_byte(&data_eeprom[RX_SERVO_1_CH]); data[RX_SERVO_1_CL] = eeprom_read_byte(&data_eeprom[RX_SERVO_1_CL]); data[RX_SERVO_2_CH] = eeprom_read_byte(&data_eeprom[RX_SERVO_2_CH]); data[RX_SERVO_2_CL] = eeprom_read_byte(&data_eeprom[RX_SERVO_2_CL]); data[RX_SERVO_3_CH] = eeprom_read_byte(&data_eeprom[RX_SERVO_3_CH]); data[RX_SERVO_3_CL] = eeprom_read_byte(&data_eeprom[RX_SERVO_3_CL]); data[RX_SERVO_4_CH] = eeprom_read_byte(&data_eeprom[RX_SERVO_4_CH]); data[RX_SERVO_4_CL] = eeprom_read_byte(&data_eeprom[RX_SERVO_4_CL]); data[RX_SERVO_0_MUL] = eeprom_read_byte(&data_eeprom[RX_SERVO_0_MUL]); data[RX_SERVO_1_MUL] = eeprom_read_byte(&data_eeprom[RX_SERVO_1_MUL]); data[RX_SERVO_2_MUL] = eeprom_read_byte(&data_eeprom[RX_SERVO_2_MUL]); data[RX_SERVO_3_MUL] = eeprom_read_byte(&data_eeprom[RX_SERVO_3_MUL]); data[RX_SERVO_4_MUL] = eeprom_read_byte(&data_eeprom[RX_SERVO_4_MUL]); data[RX_AUTOP_X_MUL] = eeprom_read_byte(&data_eeprom[RX_AUTOP_X_MUL]); data[RX_AUTOP_Y_MUL] = eeprom_read_byte(&data_eeprom[RX_AUTOP_Y_MUL]); data[RX_AUTOP_X_TRIM] = eeprom_read_byte(&data_eeprom[RX_AUTOP_X_TRIM]); data[RX_AUTOP_Y_TRIM] = eeprom_read_byte(&data_eeprom[RX_AUTOP_Y_TRIM]); data[RX_GYRO_X_OFFSET_L] = eeprom_read_byte(&data_eeprom[RX_GYRO_X_OFFSET_L]); data[RX_GYRO_X_OFFSET_H] = eeprom_read_byte(&data_eeprom[RX_GYRO_X_OFFSET_H]); data[RX_GYRO_Y_OFFSET_L] = eeprom_read_byte(&data_eeprom[RX_GYRO_Y_OFFSET_L]); data[RX_GYRO_Y_OFFSET_H] = eeprom_read_byte(&data_eeprom[RX_GYRO_Y_OFFSET_H]); if ((data[RX_SERVO_1_CH] < 0x60) | (data[RX_SERVO_1_CH] > 0x80)){ reset_trims(); } if ((data[RX_SERVO_3_MUL] > 137) || (data[RX_SERVO_3_MUL] < 117)){ data[RX_SERVO_3_MUL] = 127;} if ((data[RX_SERVO_4_MUL] > 137) || (data[RX_SERVO_4_MUL] < 117)){ data[RX_SERVO_4_MUL] = 127;} // initialise RF module. cyrf6936_Initialise_soft(&cyrf_0); cyrf6936_Initialise_soft(&cyrf_1); // enable interrupt on pin connected to cyrf6936 interrupt pin. cyrfIntEnable(); frameStart=clockGetus(); data[RX_BAT_VOLT] = a2dConvert8bit(ADC_CH_ADC0); AtEst1.AYZ = AtEst0.AYZ = 0x2A7FF; AtEst1.AXZ = AtEst1.AXZ = 0x38DFF; return 0; // don't pause after }