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 problem in hardware

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
Atmega8 problem in hardware. It works fine in simulation but if ADC is used it become hang in hardware. I don't understand why this is happening.

here is the code I used:
Code:
  // LCD module connections
sbit LCD_RS at PORTB0_bit;
sbit LCD_EN at PORTB1_bit;
sbit LCD_D4 at PORTB2_bit;
sbit LCD_D5 at PORTB3_bit;
sbit LCD_D6 at PORTB4_bit;
sbit LCD_D7 at PORTB5_bit;

sbit LCD_RS_Direction at DDB0_bit;
sbit LCD_EN_Direction at DDB1_bit;
sbit LCD_D4_Direction at DDB2_bit;
sbit LCD_D5_Direction at DDB3_bit;
sbit LCD_D6_Direction at DDB4_bit;
sbit LCD_D7_Direction at DDB5_bit;
// End LCD module connections
 unsigned char ch;
long tlong,sample,position,row,sign;
unsigned int adc_rd0, adc_rd1;




void main()
{
  Lcd_Init();                        // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  DDRC = 0b11111110;
  
 while(1)
 {
    
    adc_rd0 = ADC_Read(0);
    
    adc_rd1 = ADC_Read(1);
   
     
     Lcd_Out(2,1,"Atmega8   ");
     Delay_ms(50);

 }// while
} // void


But if I remove the line where ADC is mentioned it works as usual with LCD. But whenever I add the line again, it become hang. Why?????????????
 

What are the current fuse settings of the AVR?

It appears you are using the MikroC Compiler for AVR, is this correct?

Also, can you elaborate by what you mean by "hang?"

BigDog
 

Yes, I use MicroC Compiler. Recent fuse bits are:
CKSEL0---0
CKSEL1---0
CKSEL2---1
CKSEL3---0
SUT0-----0
SUT1-----1
BODEN----1
BODLEV---1
BOOTRST--1
BOOTSZ0--0
BOOTSZ1--0
EESAVE----1
CKOPT-----1
SPIEN------0
WDTON----1
LB1---------0
LB2---------0
BLB01-------0
BLB02-------0
BLB11-------0
BLB12-------0


Hang means MCU don't work a little bit. each of the pins give 2.5V. Nothing in LCD screen.
 

LB1---------0
LB2---------0
BLB01-------0
BLB02-------0
BLB11-------0
BLB12-------0

Set all these to 1
 

How can there fuses prevent the ADC function from working properly?
All these control flash/eeprom/bootloader locks.
 

I'm divorcing atmega8 from my work bench. Its a bad one. PIC is much better.

The chances of this being m8 fault are close to none unless you have a faulty device.
You can blame your code or your compiler, your choice ...
 

I don't understand. It works fine in simulation. But in hardware it frequently become hanged. May be my MCUs are not the original one. But its costs much to me now. Thats why I don't wanna use this MCU again. PIC is much cheaper and never hang like this.
 

I don't understand. It works fine in simulation. But in hardware it frequently become hanged. May be my MCUs are not the original one. But its costs much to me now. Thats why I don't wanna use this MCU again. PIC is much cheaper and never hang like this.

My friend You cant compare simulator like toy with real life scenario. Get some nice development board.

In my country Atmel uC is cheaper then Microchip uC (I dont count 8-pin bugs). :wink:
 

I suppose it is possible you might have a counterfeit AVR, they do exist.

However, I would tend to agree with Alex, the issue most likely lies in the code or possibly in the circuit design.

Can you post a schematic of the circuit?

Are you ensuring the ADC input does not exceed its allowable range? Exceeding the devices ADC input range can easily, using your term, "hang" a microcontroller, particularly negative voltages.

BigDog
 

Here is direct PCB diagram. Please tell me if I've done any mistake that may hang the MCU. avsd.png
 

Post the circuit diagram. We want to see how you are giving input to adc.
 

post your proteus file and also hex file. Try to add ADC_Init(); before the while(1) loop.
 

Here is the files.

- - - Updated - - -

It dosen't work with ADC_Init();. Waste of time and money.
 

Attachments

  • av.rar
    13.8 KB · Views: 64
  • AV.rar
    3 KB · Views: 45

I think you've not understand the problem yet. If the MCU runs it must show characters on LCD screen. Isn't it? It shows characters on LCD screen only then when I remove the "adc_rd0 = ADC_Read(0);" or similar adc conversion lines. But if "adc_rd0 = ADC_Read(0);" is written the MCU get hanged. Each of the pins (without VCC, GND and similar pins) give 2.5V. And don't show any character on LCD screen. If the adc not working then just it should show characters but can't calculate any adc value. isn't it?

I think my problem is now clear to you.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top