Hi, I'm new to this stuff and trying to build the 50$ Robot.
I'm using ATmega328P and Serial Dongle Programmer.
Before building the board I hooked everything up to a breadboard to see if everything would work so far and because the servos haven't arrived yet I made a small change in Photovore_v1.c to have the led go on or off depending on which photoresistor recieved more light. What happened was that the led just stayed on permenantly.
After trying all kinds of things it seems somehow starting the a2d conversion makes the program start from the beginning (or maybe resets the controller?). Is this possible?
What could I be doing wrong?
Here is the last code I used and pictures of the circuit.
The leds were supposed to go on one at a time, then together, and stay on. What I get is a continuous blinking back and forth.
The problem seems to be caused by the line:
sbi(ADCSRA, ADSC); // start conversion
#include "SoR_Utils.h" //includes all the technical stuff
int main(void)
{
int sensor_left=0;//left photoresistor
int sensor_right=0;//right photoresistor
configure_ports();
a2dInit();
// a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
// a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage
/**************************************************/
/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_off();
LEDy_on();
delay_cycles(11500);
LEDy_off();
LED_on();
delay_cycles(11500);
LED_off();
delay_cycles(11500);
//moved a2dconvert10bit to here to help debug
unsigned char ch = 4;
volatile unsigned char a2dCompleteFlag = FALSE; // clear conversion complete flag
outb(ADMUX, (inb(ADMUX) & ~ADC_MUX_MASK) | (ch & ADC_MUX_MASK)); // set channel
cbi(ADCSRA, ADIF); // clear hardware "conversion complete" flag
cbi(PRR, PRADC);
sbi(ADCSRA, ADSC); // start conversion
LEDy_on(); //lighting up both leds then delaying - to find the problematic line
LED_on();
delay_cycles(11500);
//while(!a2dCompleteFlag); // wait until conversion complete
// while( bit_is_clear(ADCSRA, ADIF) ); // wait until conversion complete
while( bit_is_set(ADCSRA, ADSC) ); // wait until conversion complete
// CAUTION: MUST READ ADCL BEFORE ADCH!!!
unsigned short a2dConvert10bit = (inb(ADCL) | (inb(ADCH)<<8)); // read ADC (full 10 bits);
unsigned char a2dConvert8bit= a2dConvert10bit>>2; // return ADC MSB byte
sensor_left=a2dConvert8bit;
while(1)
{
delay_cycles(22500);
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/
return 0;
}

