Author Topic: CAN'T WRITE EEPROM ON P16F628A. PLS HELP  (Read 1147 times)

0 Members and 1 Guest are viewing this topic.

Offline quaternion00Topic starter

  • Contributor
  • Posts: 15
  • Country: ph
CAN'T WRITE EEPROM ON P16F628A. PLS HELP
« on: February 03, 2019, 02:11:41 am »
I can't write to EEPROM of 16f628a. the code is in assembly. I hope you guys can help.
thanks in advance.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: CAN'T WRITE EEPROM ON P16F628A. PLS HELP
« Reply #1 on: February 03, 2019, 05:03:46 am »
In future, when posting code please use SMF BBCode code tags, or attach it as a text file.

There are two non-obvious things wrong with that code,  There is no delay after startup or wait for a user button press before starting to write to EEPROM, and there is nothing to stop the processor at the end of the program.  (END is a MPASM directive, it doesn't generate code.) It has 2048 instruction words so if running at 1 MIPS from a 4MHz crystal, it will blow through the unprogrammed instruction locations in about 2 ms, then execution will wrap back to the start.  As writing to EEPROM typically takes 4ms, worst case 8ms there's a less than 33% chance you'll cut power after the write has finished, before it repeats it, and even lower odds at higher crystal frequencies.   If you interrupt a write that's in progress the usual result is failure to program, either unprogramed 0xFF or corrupted data.

Additionally, the programmer typially briefly powers the chip and releases /MCLR during the process of identifying it.  If you don't have a short delay after powerup (1/4 sec will do), or wait for user intervention on a non-ICSP pin, its fairly certain that it will run your code as far as the EEPROM write when you try to read the EEPROM contents, and interrupt the write by raising /MCLR to Vpp before it can complete, leaving the EEPROM location unprogrammed or corrupted.
« Last Edit: February 03, 2019, 12:23:24 pm by Ian.M »
 

Offline quaternion00Topic starter

  • Contributor
  • Posts: 15
  • Country: ph
Re: CAN'T WRITE EEPROM ON P16F628A. PLS HELP
« Reply #2 on: February 03, 2019, 05:25:29 am »
Thanks for the reply,Sir. Is the EELOOP not enough to ensure the program waits until the write is done?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12875
Re: CAN'T WRITE EEPROM ON P16F628A. PLS HELP
« Reply #3 on: February 03, 2019, 05:49:27 am »
That loop waits till the write is done but you need to stop the execution continuing past the END directive and wrapping back to the start. 
The simplest fix is adding an endless loop before the end directive.
Code: [Select]
halt: GOTO halt
As the min EEPROM write endurance is only 100K write cycles (typ. 1M) and, as is, it takes about 6ms to write and wrap back to the start at 4MHz clock speed,  your code could have damaged that EEPROM location in as little as ten minutes of power-on time.  After 100 minutes, its  even odds that location has failed.  The times are  shorter at higher clock speeds, dropping to 7 1/2 minutes and 73 minutes respectively at 20MHz.  Therefore you should either change the address or use a brand new PIC once you fix your code.  (If you know how to edit EEPROM memory in the IPE or 3rd party programmer software, you could also test the location and if its OK carry on using the same PIC and address.)

Don't forget to add a delay after startup or enable /RBPU and wait for a pin on port B (not RB6,7 the ICSP pins) to go low before starting the write to avoid the programmer corrupting the EEPROM when you attempt to read it.
« Last Edit: February 03, 2019, 05:52:13 am by Ian.M »
 

Offline quaternion00Topic starter

  • Contributor
  • Posts: 15
  • Country: ph
Re: CAN'T WRITE EEPROM ON P16F628A. PLS HELP
« Reply #4 on: February 03, 2019, 12:06:53 pm »
I added halt before the END and it worked. I checked the EEPROM if it's damage, glad that its not. :D
I'm wondering how the mikroC eeprom library write to EEPROM, now i know. It's exciting to know the assembly language behind
library codes . Thanks for your time Sir.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf