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.

Issue with Eeprom of AVR

Status
Not open for further replies.

Okada

Banned
Joined
Jun 16, 2016
Messages
1,159
Helped
129
Reputation
252
Reaction score
129
Trophy points
63
Activity points
0
Hi

I am using ATMega8A for my project. It is working fine in Proteus but not in hardware. There are 4 Status Leds and 4 Relays and all are working in Proteus but in hardware no Leds and Relays are working. I am sure this is because of eeprom. I have provided demo firmware to my client in which eeprom is used for demo limit checking. In proteus as I have used eeprom.bin it works fine.

If eeprom byte is 0xFF then device will not work. I want to know if chip is erased then will the eeprom also erase to 0x00 ?
 

Here is the circuit. It is a stabilizer. The PIC version has exact same code except Timer1 Initialization code and it works fine on hardware. AVR version and PIC version is working fine in Proteus also.

Can't post the code. Client asked not to post the code.

Project is simple. If voltage is normal then Green Led turns ON if nor normal then Low V / High V and Delay Led Turns ON. If voltage becomes normal then Low V / High V Led turns OFF and Delay Led blinks for 10 sec / 3 min based on Delay Switch position and then Green Led turns ON.

Eeprom is used for demo limit. UIf demo limit is 20 or 50 then device stops functioning and the symptoms will be as mentioned in post #1.

In Proteus if you press the reset button 20 or 50 times the device stops functioning and you have to restart the simulation.
 

Attachments

  • Stabilizer.rar
    67.1 KB · Views: 55

This is the ADC code I am using.


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
char str[23];
unsigned int raw_adc_value = 0, previous_raw_adc_value = 10;
double mains_voltage = 0.0;
 
void main() {
    
    DDRB = 0xFF;
    DDRC = 0b00111100;
    DDRD = 0xFE;
           
    PORTB = 0x00;
    PORTC = 0x00;
    PORTD = 0x00;
    
    ADMUX = 0x00;
    ADCSRA = 0x05;
       
    UART1_Init(9600);
    Delay_ms(200);
       
    while(1) {    
          
              raw_adc_value = (unsigned int)ADC_Read(1);
              Delay_ms(5);    
    
              if(previous_raw_adc_value != raw_adc_value) {
                  mains_voltage = (double)raw_adc_value * 5.0 / 1023.0;                 
                  
                  FloatToStr(mains_voltage, str);
                  strcat(str, " V\r\n");
                  UART1_Write_Text(str);
                  
                  previous_raw_adc_value = raw_adc_value;
              }
                                                                   
                  
    }
}



There are if()...elseif() conditions based on the adc voltages to control the relay and Leds. All those conditions are correct.

I am using EasyAVR v7 development board and I see a strange problem. If I connect POT Output to ADC input pin then adc reading stops and if I float the adc input pin then I get random values between 10 mV and 12 mV.
 

Hi,

I want to know if chip is erased then will the eeprom also erase to 0x00 ?

Datsheet says:
The Chip Erase operation turns the content of every memory location in both the
Program and EEPROM arrays into 0xFF.


Note: 1. The EEPRPOM memory is preserved during chip erase if the EESAVE Fuse is programmed

Klaus
 
  • Like
Reactions: Okada

    Okada

    Points: 2
    Helpful Answer Positive Rating
Your questions are as usual a bit confusing. You complained from the start that you are having issues with the EEPROM, which is apparently being updated after each booting of the uC, however there is no access to this memory in the code above.

if you press the reset button 20 or 50 times the device stops functioning and you have to restart the simulation
Anyway, your problem is likely related to some issue with Proteus interacting with the operational system, not necessarily a problem with the code itself.
 
  • Like
Reactions: Okada

    Okada

    Points: 2
    Helpful Answer Positive Rating
This is the eeprom related code.


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
#define MAX_DEMO_LIMIT_ADDRESS 0x01
#define MAX_DEMO_LIMIT           20
 
unsigned char demo_limit = 0;
 
void main() {
    
    demo_limit = EEPROM_Read(MAX_DEMO_LIMIT_ADDRESS);
    Delay_ms(50);
    
    if(demo_limit <= MAX_DEMO_LIMIT) {
        ++demo_limit;
        EEPROM_Write(MAX_DEMO_LIMIT_ADDRESS, demo_limit);
        Delay_ms(50);
        
        InitTimer1();
    }
    
    while(1) {
    
          if(demo_limit <= MAX_DEMO_LIMIT) {
 
      }
}



- - - Updated - - -

I suspect eeprom and adc problems. If eeprom data at address 0x01 is > 20 then device will not work and all Leds and Relays will be OFF. This is the symptom and this is what client is seeing.

If adc doesn't work then adc value will be zero and Low V Led and Delay Led will be ON. Varying the adc input will not then show any changes to the Leds and Relays state.

- - - Updated - - -

I am testing on EasyAVR v7 development board. In Proteus it is working fine but not on development board.
 

Finally, you were able to provide almost all the necessary information we need to assess the issue as a whole, from code to schematic, so that now we are able to help you.

I suspect eeprom and adc problems

The problem you are facing is certainly due to the fact that you are performing consecutive reset at a very short intervals, which we agree, it is not a regular operation. Considering that the EEPROM is accessed immediately after the reset, this is therefore related to EEPROM, not to A/D as you suspected. Note that it is still somewhat a guess, because you did not provide the Init() function, but instead, you have spread initializations along the main().

To solve this, you can either add a long-running Delay immediately after starting ( before calling any other functions ) in the range of a second, as well as add a Diode at the MCLR pin - anode on the reset and katode on the Vcc - so that the capacitor will be discharged immediately when power turn down. In addition, could increase both the capacitor and resistor so that the time base rises to something in the range of a second.
 
  • Like
Reactions: Okada

    Okada

    Points: 2
    Helpful Answer Positive Rating
Init() function is same. that is both codes should be merged.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top