+ Post New Thread
Results 1 to 10 of 10
  1. #1
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    125 / 125
    Points
    5,417
    Level
    17

    Issue with Eeprom of AVR

    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 ?

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 5
    Points: 8,573, Level: 22
    Easyrider83's Avatar
    Join Date
    Oct 2011
    Location
    Tallinn, Estonia
    Posts
    1,525
    Helped
    348 / 348
    Points
    8,573
    Level
    22

    Re: Issue with Eeprom of AVR

    We should guess the schematic and code I suppose?
    Love me or hate me. All infractions will be ignored.



  3. #3
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    125 / 125
    Points
    5,417
    Level
    17

    Re: Issue with Eeprom of AVR

    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.



  4. #4
    Super Moderator
    Points: 27,503, Level: 40
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,215
    Helped
    1038 / 1038
    Points
    27,503
    Level
    40
    Blog Entries
    5

    Re: Issue with Eeprom of AVR

    Can't post the code.
    So, are you still expecting to get some help ?
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisment

        
       

  5. #5
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    125 / 125
    Points
    5,417
    Level
    17

    Re: Issue with Eeprom of AVR

    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.



  6. #6
    Super Moderator
    Points: 63,277, Level: 61
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    12,934
    Helped
    2986 / 2986
    Points
    63,277
    Level
    61

    Re: Issue with Eeprom of AVR

    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


    1 members found this post helpful.

  7. #7
    Super Moderator
    Points: 27,503, Level: 40
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,215
    Helped
    1038 / 1038
    Points
    27,503
    Level
    40
    Blog Entries
    5

    Re: Issue with Eeprom of AVR

    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.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )


    1 members found this post helpful.

  8. #8
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    125 / 125
    Points
    5,417
    Level
    17

    Re: Issue with Eeprom of AVR

    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.



  9. #9
    Super Moderator
    Points: 27,503, Level: 40
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,215
    Helped
    1038 / 1038
    Points
    27,503
    Level
    40
    Blog Entries
    5

    Re: Issue with Eeprom of AVR

    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.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  10. #10
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    125 / 125
    Points
    5,417
    Level
    17

    Re: Issue with Eeprom of AVR

    Init() function is same. that is both codes should be merged.



--[[ ]]--