+ Post New Thread
Results 1 to 16 of 16
  1. #1
    Member level 1
    Points: 478, Level: 4

    Join Date
    Nov 2016
    Posts
    32
    Helped
    0 / 0
    Points
    478
    Level
    4

    EEPROM Write When Power Loss PIC18F2520

    I want to store the data when POWER loss or Down.
    So I connected to the interrupt Pin with help of diode
    I used 1000uf/25V capacitor to store the power to write EEPROM DATA.
    But interrupt working only when Gnd to VCC trigger but in my case trigger will be VCC to GNd.
    I attached My circuit and code also.Please Find it,

    Example Code:

    Code:
    void interrupt zero()
    {
    if(INT0IE && INT0IF)
    {
    eeprom_write(5,s);
    }
    }
    void main() 
    {
    ADCON0=0x00;
    ADCON1=0x0F;
    PORTB=0X00;
    PORTA=0X00;
    TRISC=0X00;
    TRISA=0X00;
    TRISB=0X03;
    INT0IE=1;
    PEIE=1;		//Enable Peripheral Interrupt
    GIE=1;		//Enable INTs globally
    INTEDG0=0;
    while(1) 
    {
    address(0x80);
    dispstr("____ME___________");
    s++;
    _delay_ms(100);_delay_ms(100);_delay_ms(100);_delay_ms(100);_delay_ms(100);_delay_ms(100);_delay_ms(100);_delay_ms(100);_delay_ms(100);
    }
    }

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

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

    Re: EEPROM Write When Power Loss PIC18F2520

    Why did you opened another thread for the same project ?

    What is your FOSC. I will write a code for you. You test my code. Maybe problem is in software.



    •   AltAdvertisment

        
       

  3. #3
    Member level 1
    Points: 478, Level: 4

    Join Date
    Nov 2016
    Posts
    32
    Helped
    0 / 0
    Points
    478
    Level
    4

    Re: EEPROM Write When Power Loss PIC18F2520

    Fosc 20mhz



  4. #4
    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: EEPROM Write When Power Loss PIC18F2520

    Proteus will not simulate that. Power is always connected. Power pins are local.
    And it is bad idea to impement writing inside interrupt.
    Love me or hate me. All infractions will be ignored.



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

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

    Re: EEPROM Write When Power Loss PIC18F2520

    It works. See attached video if you don't have Proteus 8.5 SP1. I also tested the project with PIC18F46K22 on hardware and it works fine. Test the attached .hex file on hardware. The power supply of PIC circuit if not battery operated should have atleast 1000 uF at input and output of LM7805.



    •   AltAdvertisment

        
       

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

    Join Date
    Apr 2014
    Posts
    12,932
    Helped
    2986 / 2986
    Points
    63,245
    Level
    61

    Re: EEPROM Write When Power Loss PIC18F2520

    Hi,

    It's better to connect the high value capacitor at the voltage regulator input.
    Then use a comparator to detect when this input voltage goes below 9V (or any other useful level).

    This ensures a valid VCC level during Eeprom write operation.

    Klaus



    •   AltAdvertisment

        
       

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

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

    Re: EEPROM Write When Power Loss PIC18F2520

    Yes, it is better to do a KlausST mentions. Use a 10000uF 50V capacitor at the input of 7805. 10000uF 50V is easily available. Then use a voltage divider and scale the 7805 input voltage to adc input pin. If power goes then capacitor voltage slowly decays and when ADC input goes below 4V then start writing to eeprom. During this time there will be still 5V power for PIC.



  8. #8
    Member level 1
    Points: 478, Level: 4

    Join Date
    Nov 2016
    Posts
    32
    Helped
    0 / 0
    Points
    478
    Level
    4

    Re: EEPROM Write When Power Loss PIC18F2520

    I checked this program in PIC18F452 , the program working perfectly ,I don't known why this program concept not working in PIC18F2520.
    Please give any suggestion to me. I think any problem in IC is there I want to buy new IC and want to check it..........



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

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

    Re: EEPROM Write When Power Loss PIC18F2520

    If it has INT0, INT1 and INT pins then check with INT1 or INT2 pin.



  10. #10
    Member level 1
    Points: 478, Level: 4

    Join Date
    Nov 2016
    Posts
    32
    Helped
    0 / 0
    Points
    478
    Level
    4

    Re: EEPROM Write When Power Loss PIC18F2520

    I checked those pins also INT0 , INT1 , INT2 but same problem...........



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

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

    Re: EEPROM Write When Power Loss PIC18F2520

    Maybe you need to buy a new PIC18F2520 and try the code with proper pulse detection circuit. Don't connect to high current circuit. Maybe it has damaged the INT module inside the PIC.



  12. #12
    Advanced Member level 5
    Points: 13,698, Level: 28
    schmitt trigger's Avatar
    Join Date
    Apr 2013
    Posts
    2,306
    Helped
    745 / 745
    Points
    13,698
    Level
    28

    Re: EEPROM Write When Power Loss PIC18F2520

    Get yourself one of the many regulators which have an output flag which will tell the microcontroller of an impending voltage drop.

    Most of the major semiconductor vendors offer such regulators. Perform a web search.
    My batteries are recharged by "Helpful Post" ratings.
    If you feel that I've helped you, please indicate it as a Helpful Post



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

    Re: EEPROM Write When Power Loss PIC18F2520

    Quote Originally Posted by nis2311 View Post
    I checked this program in PIC18F452 , the program working perfectly ,I don't known why this program concept not working in PIC18F2520.
    The above routine is just part of the whole code, and it hasn't any directive to handle the fuse of the brown-out-detector, which sugests that you likely programmed it differently on each device.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  14. #14
    Member level 1
    Points: 478, Level: 4

    Join Date
    Nov 2016
    Posts
    32
    Helped
    0 / 0
    Points
    478
    Level
    4

    Re: EEPROM Write When Power Loss PIC18F2520

    Same Problem in New IC PIC18F2520. It is working well in 40 Pin PIC18F452 but is not working PIC18F2520 .
    My problem is when Interrupt Program want to run when RB0 is 5 volt to GND connected.
    But my concept is working well in PIC18F452.
    Help me to solve the Problem.

    Code:
    #include
    #define led1 RA0
    #define led2 RA1
    void delay(unsigned int a)
    {
    while(a--);
    }
    void interrupt zero()
    {
    if(INT0IE && INT0IF)
    {
    led2=1;
    }
    }
    void main() 
    {
    ADCON0=0x00;
    ADCON1=0x0F;
    PORTB=0X00;
    PORTA=0X00;
    TRISC=0X00;
    TRISA=0X00;
    TRISB=0X0F;
    delay(65000);delay(65000);delay(65000);delay(65000);delay(65000);delay(65000);delay(65000);delay(65000);delay(65000);
    INT0IE=1;
    PEIE=1;		//Enable Peripheral Interrupt
    GIE=1;		//Enable INTs globally
    INTEDG0=0;
    while(1) 
    {
    address(0xC0);
    dispstr("____ON___________");
    led1=1;
    delay(65000);delay(65000);delay(65000);delay(65000);delay(65000);delay(65000);
    led1=0;
    delay(65000);delay(65000);delay(65000);delay(65000);delay(65000);delay(65000);
    }
    }



    •   AltAdvertisment

        
       

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

    Re: EEPROM Write When Power Loss PIC18F2520

    It is working well in 40 Pin PIC18F452 but is not working PIC18F2520
    Did you even read the previous post ?
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



  16. #16
    Member level 1
    Points: 478, Level: 4

    Join Date
    Nov 2016
    Posts
    32
    Helped
    0 / 0
    Points
    478
    Level
    4

    Re: EEPROM Write When Power Loss PIC18F2520

    Problem Solved by using Optocoupler.
    Led side is given to 5V power using 1K resistor.
    Transistor side I connected one for GND and other to RB0.
    If 5v is off means RB0 goes to null state and Interrupt is working.



--[[ ]]--