Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
int main(void) { //declare variables here //int i=250;//a 'whatever' variable int sensor_left=0;//left photoresistor int sensor_right=0;//right photoresistor int threshold=8;//the larger this number, the more likely your robot will drive straight /****************INITIALIZATIONS*******************/ configure_ports(); // configure which ports are analog, digital, etc. a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage /**************************************************/ /*********ADD YOUR CODE BELOW THIS LINE **********/ LED_off();//turn LED on while(1) { //store sensor data sensor_left=a2dConvert8bit(5); sensor_right=a2dConvert8bit(4); servo_left(25); servo_right(44); delay_cycles(500);//a small delay to prevent crazy oscillations } /*********ADD YOUR CODE ABOVE THIS LINE **********/ return 0; }
If this is your fourth attempt and all tries have shown the same behaviour it is unlikely to be related to your soldering. If the programmer reports it is working ok but you don't see stable logic voltages on the output pins it is likely there is some factor preventing proper code execution.Worth a try would be: Using separate supplies for the processor and the servos. 6.4V gives a very small drop out margin for the typical 5V regulator so it is possible that under load you simply don't have a regulated supply for your processor and are seeing brown out. Try feeding the regulator with 7.5V - 12V, or use 3 AA/AAA batteries to make a 4.5V supply and bypass the regulator completely (connect them in series using wire and insulating tape). Use the 6.4V battery to feed the servos only. Take care not to feed the servos with a higher voltage, or connect supply positives in any way.Adding a 10KOhm pull-up resistor from the reset pin (pin 1) to VCC/+5V. If this pin sees a logic low it will reset the processor so pull it up to logic 1 (and test it) to make sure.
#include <avr/io.h>#include <util/delay.h>#include "global.h"#include "a2d.h"void delay_ms( unsigned long int ms ) { _delay_ms( ms );}void delay_cycles( unsigned long int cycles ) { while( cycles > 0 ) cycles--;}void PORTD_HIGH( int position ) { PORTD |= (1 << position); }void PORTD_LOW( int position ) { PORTD &= ~(1 << position);}void LED_ON( void ) { PORTD_LOW(4);}void LED_OFF( void ) { PORTD_HIGH(4);}void servo_left( signed long int speed ) { PORTD_HIGH( 0 ); delay_cycles( speed ); PORTD_LOW( 0 );//keep off delay_cycles(200);}void servo_right( signed long int speed ) { PORTD_HIGH( 1 ); delay_cycles( speed ); PORTD_LOW( 1 );//keep off delay_cycles(200);}void configure_ports( void ) { DDRD = 0xFF; // Set Port D pins as all outputs DDRC = 0x00; // Set all C ports for input PORTC = 0x00; // Make sure pull-up resistors are turned off}int main( void ) { // Setup input and output ports as such configure_ports(); // Turn on the LED for visual effect LED_ON(); while(1) { //go straight servo_left(25); servo_right(44); // Delay to avoid "crazy" oscillations delay_cycles(500); } return 1;}
sensor_left=a2dConvert8bit(5);sensor_right=a2dConvert8bit(4)+62;