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.

atmega8 not working in circuit but in simulation

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Activity points
8,252
atmega8L is not working in circuit but working well in simulation. I'm using top win to program it. can anyone help me?
asf.png
as.png

- - - Updated - - -

Here is the circuit where I'm testing...
Untitled.png
 

You have to be more specific than that in order to get help, "not working" is a very generic expression.

What have you tried so far?
Did you check if the crystal oscillates?
Do you have any indication that the mcu is executing the code?
Have you changed the chip?
 

Can you zip and upload the proteus .dsn file and your source code?
 

At last it worked with internal crystal but becoming hanged with LCD program if more than one instruction is given.

Here is the code:
Code:
unsigned int adc_rd2;
unsigned char ch;
float temp;
int sample[20];
float average = 0;
// LCD module connections
sbit LCD_RS at PORTD7_bit;
sbit LCD_EN at PORTB0_bit;
sbit LCD_D4 at PORTB4_bit;
sbit LCD_D5 at PORTB3_bit;
sbit LCD_D6 at PORTB2_bit;
sbit LCD_D7 at PORTB1_bit;

sbit LCD_RS_Direction at DDD7_bit;
sbit LCD_EN_Direction at DDB0_bit;
sbit LCD_D4_Direction at DDB4_bit;
sbit LCD_D5_Direction at DDB3_bit;
sbit LCD_D6_Direction at DDB2_bit;
sbit LCD_D7_Direction at DDB1_bit;
// End LCD module connections
                       //
int i;
 char txt[10];
 char *text;
long tlong;
void main()
{
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  DDRC = 0b11111110;


 while(1)
 {
  for(i=0; i< 5; i++)
  {
   adc_rd2 = ADC_Read(0);
   sample[i] = adc_rd2;
   Delay_ms(20);
  }
  average = 0;
  for(i=0;i<5;i++)
  {
   average += sample[i];
  }
  average /= 5;
  average = ((1023 /(float)adc_rd2 )-1);;
  average = 10000/average; // get the resitror value
  temp = average/10000; // R/Ro
  temp = log(temp); // temp = log(R/Ro)
  temp /= 3950; // 1/B
  temp += 1.0/(25.00 + 273.15);
  temp = 1.00/temp;
  temp -= 273.15; // convert to C.

        tlong = temp*1000;
        ch = tlong/1000;           // Extract volts (thousands of millivolts)
        ch = (tlong / 100000) % 10;
        Lcd_Chr(2,9,48+ch);          // Write result in ASCII format
        ch = (tlong / 10000) % 10;
        Lcd_Chr_Cp(48+ch);          // Write result in ASCII format
        ch = (tlong / 1000) % 10;
        Lcd_Chr_Cp(48+ch);          // Write result in ASCII format
        Lcd_Chr_CP('.');
        ch = (tlong / 100) % 10;     // Extract hundreds of millivolts
        Lcd_Chr_CP(48+ch);           // Write result in ASCII format
        ch = (tlong / 10) % 10;      // Extract tens of millivolts
        Lcd_Chr_CP(48+ch);           // Write result in ASCII format
        Lcd_Chr_CP('C');

       Lcd_Out(1,2,"Recent Temp:");


       PORTC4_bit = ~PORTC4_bit;


 }// while
} // void

Also, I can't still work with external Crystal. I found a **broken link removed**

I did as their information for internal crystal. Here is my configuration with topwin :internal clock a.png internal clock b.png
I tried the same program with pic before with some modification before, program work fine there. Here is the proteus file of the project: and a image when the circuit worked with internal crystal when not working with more than one line of lcd word. Still can't work with external crystal.
 

Attachments

  • temp_atmega8.rar
    12.3 KB · Views: 103
  • 17082012413.jpg
    17082012413.jpg
    42.1 KB · Views: 111
  • 17082012415.jpg
    17082012415.jpg
    43.5 KB · Views: 141

Which compiler did you use?

- - - Updated - - -

Try the crystal with CKOPT=0
 

need to know , which crystal you using and the type of micro controller. btw now the commonly available UCs are atmega 8L s which have max crystal frequency of 8 Mhz. So if its above 8Mhz, chances of it working are dim.
 
need to know , which crystal you using and the type of micro controller. btw now the commonly available UCs are atmega 8L s which have max crystal frequency of 8 Mhz. So if its above 8Mhz, chances of it working are dim.

He did say atmega8L and the crystal is 8MHz as shown in the PCB
 

in pcb its MHz, that doesn't imply that he has one.. and add 22pf caps with the crystal and ground that for stabilize the thing. (in bread board it looks like a bit of crude arrangement)
 
According to the datasheet you should use 12-22pf caps, I use 15 or 22pf without problems.
Dis you set the CKOPT=0 to check if it fixes the problem?
 

Yes you have reported that previously but with the internal RC, does it work now with the crystal too?
Did the CKOPT fix the crystal problem?
 

Yes its working with internal RC. with CKOPT = 1;// disabled
But I found another problem. Can you find any fault in the program? I've noticed that compiler is creating the .hex file of only 128bytes. usually it become around 1~2KB. But can't understand.

- - - Updated - - -

As far as I found, the problem is in the ADC_Read(); without this its all ok now.

- - - Updated - - -

Update>> problem in the line where log is used. if its not used then the hex run.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top