Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

not getting the output from ATMega8

Status
Not open for further replies.

shubham_k

Newbie level 3
Joined
Jan 1, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,326
Hi,
I am making a project where I have to sense the light in the bot.
The analog output from the LDR must be converted to the digital form for the microcontroller to read.
Without using a comparator,I can do that.But for the same, I have to apply ADC conversion in my program.
I am posting the program.Plz check where's the error and why I am not getting the output.
I am using ATMega8 microcontroller.I am using PC1,PC2 and PC4 ports for sensor outputs.
These are also the ADC ports.This is the reason I am using these C ports.
PC0 to PC 5 are the ADC ports in ATMega8.
I am using 3 LDR sensors.








Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//there are 5 adc ports in atmega8( PC0 to PC5)
//I am using PC1,PC2 and PC4 for connecting the LDR sensors
 
 
 
 
 
 
 
#include <avr/io.h> 
#include<util/delay.h>
int a[3];    //Array to store the sensor voltages 
int main(void) 
{ 
  DDRC=0b0000000;       //Set port A to input 
  DDRB=0b00011110;   //Set port B to output 
 
   
    while(1) 
    { 
    ADMUX=0b00101000; 
    int i; 
    for(i=1;i<5;i++)    //Read values of the inputs //      PC1-centre,PC 2-left, PC4-right
    {   
      ADCSRA=0b00011111; 
      while(ADCSRA&(1<<ADSC)); 
      ADMUX++; 
      a[i]=ADCH;  //Values stored in ADCH transferred to the array 
    } 
         
        if(a[2]>a[4] && a[2]>a[1])   //left sensor highest 
       PORTB=0b00000010;  //Turn left 
       
  else 
  if(a[4]<a[1] && a[1]>a[2])    //Centre sensor highest 
      PORTB=0b00010010;  //Go straight 
       
  else 
  if(a[4]==a[1])  //Any two sensors getting same value, then go straight 
      PORTB=0b00010010;  
       
  else 
  if(a[1]==a[2]) 
      PORTB=0b00010010;  
       
  else 
  if(a[4]>a[1] && a[4]>a[2])      //Right sensor highest 
     PORTB=0b00010000;     //Turn right 
     
    } 
return 0; 
}

 
Last edited by a moderator:

did u check u are getting sufficient voltages at micro pins to trigger the logic?
 

some very critical points to check --

* ADMUX value is wrongly managed. for PC1, pC2, pC4 it must be 0010 0001, 0010 0010, 0010 0100 only. ADMUX++ statement will not do this.
* you should change ADMUX value only after reading the previous data
* your ADCSRA register management is wrong. read the manual carefully. ADEN (bit7) must be 1 to enable ADC. Also ADSC bit has to be set 1 first time to start conversion, and then later check it to wait for conversion complete.
* in ADCSRA you are not using adc_isr, but you are enabling ADIE (bit3). this will create trouble.
* ADSC bit goes to ZERO on conversion completion, but you are not waiting for this in While() loop. You are checking for ADSC to be 1 instead ?
* have you connected +5v to the AREF pin ? what is connected to AREF pin ?
* the LDR does not generate a voltage. what is the resistance range of your ldr, and what other series resistor have you connected ?

you must correct these first, then we will see results again
 
u might be correct..But I don't know how to do this programming like the one u said in ur post..Can u please do the modifications so that I can check dumping the modified code in my microcontroller to check it again??
 

Hi,
I am making a project where I have to sense the light in the bot.

u might be correct..But I don't know how to do this programming like the one u said in ur post..Can u please do the modifications so that I can check dumping the modified code in my microcontroller to check it again??

since you are making a project, i think you should at least to read the manual and try understand for your self. otherwise why not just go and buy a fully made line following robot ?
 

since you are making a project, i think you should at least to read the manual and try understand for your self. otherwise why not just go and buy a fully made line following robot ?

I know how to build a line-following robot by using a comparator..because in this,i don't need to do adc conversion in program.but in this one, i am not using a comparator..so i have to do adc conversion in program also..in manual,i have the process to do the adc conversion for atmega16..but here,i am using atmega8..here lies the problem..otherwise,i would have copied the entire program if i had an atmega16 microcontroller..
 

The only difference between m8 and m16 is an additional bit in m16 ADMUX register because there are may differential channel and gain options
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top