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.

[PIC] MikroC EEPROM_Write breaking my programme

Status
Not open for further replies.

anishpsla

Member level 2
Member level 2
Joined
Dec 15, 2013
Messages
44
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
402
I am writing a firmware for my project using PIC16F877A and Mikroc. In this firmware, I want to change values stored in EEPROME of PIC. The circuit have 6 buttons for selecting and changing values. The buttons are connected to various pins of PORT D. All of the functions are worked without any problem. When I add EEPROM_Write function on Button 6 pressed, it stops working. After that, the LCD is blank. No response from any of the buttons.

I do lot of experiments with EEPROM_Write. If I add EEPROM_Write in any part of the firmware, it stops working. I am using button library in MikroC. Here is the sample code, I want to work perfectly.

Code:
 while(menu==1)
{
         if (Button(&PORTD, 4, 150, 0))
          {

            //Temp
            Delay_ms(500);
            Eeprom_Write(0x00,new_temp_mem);
            Delay_ms(100);

            //Fan1 RPM
            Eeprom_Write(0x02,new_rpm0_mem); //lower byte
            Delay_ms(200);
            Eeprom_Write(0x01,new_rpm0_mem>>8); //upper byte
            Delay_ms(200);
            
            //Fan2 RPM
            Eeprom_Write(0x04,new_rpm1_mem); //lower byte
            Delay_ms(200);
            Eeprom_Write(0x03,new_rpm1_mem>>8); //upper byte
            Delay_ms(200);
 
          }
}
 

Without knowing how each variable is declared it's difficult to tell what is wrong.

As 'new_rpm0_mem' and 'new_rpm1_mem' are shifted 8 places I guess they must start as integer types so maybe writing 16 bits to an 8-bit wide EEPROM address is responsible for the failure. Try changing the lines to be like:

Eeprom_Write(0x01,(unsigned char)(new_rpm0_mem >> 8));

Brian.
 
If you are using INT0 or Counter or CCP module for RPM measurement using interrupts then you have to disable GIE_bit during eerom operations. Maybe you are consuming too much RAM. Are you getting "IRP_bit must be set manually to access abc_variable" warning in Compiler ? If yes, then it is better to use PIC18F device.
 
In addition, I would also recommend to perform a Read-after-Write test just to check if the EEPROM itself could have some problem. Perhaps the Eeprom_Write() funcion on the MikroC library make a check of a specific condition not achieved within a low level closed loop routine.
 
Without knowing how each variable is declared it's difficult to tell what is wrong.

As 'new_rpm0_mem' and 'new_rpm1_mem' are shifted 8 places I guess they must start as integer types so maybe writing 16 bits to an 8-bit wide EEPROM address is responsible for the failure. Try changing the lines to be like:

Eeprom_Write(0x01,(unsigned char)(new_rpm0_mem >> 8));

Brian.

Thanks for the reply. new_rpm0_mem is a 16bit int value. As you can see, I want to write the values to EEPROM on button press. But the LCD is blank even before the program entering into the menu loop. That's causing headache for me.

If you are using INT0 or Counter or CCP module for RPM measurement using interrupts then you have to disable GIE_bit during eerom operations. Maybe you are consuming too much RAM. Are you getting "IRP_bit must be set manually to access abc_variable" warning in Compiler ? If yes, then it is better to use PIC18F device.

I am using counter in PIC for counting the RPM. The counter part is working perfectly. I am struggling for changing the error threshold value stored in EEPROM.
 

Zip and post the complete mikroC PRO PIC project files. Post your circuit in PDF, PNG or Proteus format.
 

Sorry, I can't post all the details here. As I posted in the first post, I am experiencing problem with Eeprom_Write function. When I add the function, the LCD will blank, even before executing it. Otherwise, the entire program is working fine.
 

TRISD.B4 set as input for eeprom write button ?
 

What about you reduce delay times by a factor of 1:50 for example? The above routine is doing absolutely nothing for 1.4 seconds (even w/o accounting debounce time), and writing in 6 memory locations in perhaps no more than a hundred millisecond. The whole funcion at all is masking the read of the Button() exectution for a long period.
 

Do you know that mikroC has the following functions.

Code:
Lo();
Hi();
Higher();
Highest();

?
 

TRISD.B4 set as input for eeprom write button ?

Already done. My problem was after adding Eeprom_Write to the program, it's look like the program hanged. There is no response from buttons and nothing in LCD screen.


What about you reduce delay times by a factor of 1:50 for example? The above routine is doing absolutely nothing for 1.4 seconds (even w/o accounting debounce time), and writing in 6 memory locations in perhaps no more than a hundred millisecond. The whole funcion at all is masking the read of the Button() exectution for a long period.

For testing, I just put the function outside of the main loop. Still same problem. There is no response from any buttons and LCD screen is blank.
 

For testing, I just put the function outside of the main loop. Still same problem. There is no response from any buttons and LCD screen is blank.

Not clear what function you're referring...the code within 'while', the code within 'if' ?
BTW, this does not minimize at all the problem mentioned above.
 

I put the following code out side of main loop. Still I have same problem.


Code:
            Eeprom_Write(0x00,new_temp_mem);
            Delay_ms(100);

            //Fan1 RPM
            Eeprom_Write(0x02,new_rpm0_mem); //lower byte
            Delay_ms(200);
            Eeprom_Write(0x01,new_rpm0_mem>>8); //upper byte
            Delay_ms(200);
            
            //Fan2 RPM
            Eeprom_Write(0x04,new_rpm1_mem); //lower byte
            Delay_ms(200);
            Eeprom_Write(0x03,new_rpm1_mem>>8); //upper byte
            Delay_ms(200);
 

Also, not clear if you made the test proposed above.
Your reply mentions another test, not the one mentioned.

- - - Updated - - -

To be honest, it is too hard to help you when you are giving just partial information, and seems not following recommendations exactly as proposed.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top