Do eeprom read/writes require timing adjustments to 32MHz code operation?

wapo54001

Senior Member
My program, running on an 28X2 at 32MHz, is intended to take four readings and then average them using eeprom memory. It takes one reading, stores it in eeprom, then takes another reading, adds it to what is stored in eeprom, does the same two more times and then divides by four and stores that value in eeprom as an average of the four readings.

Problem is, my program fails in an inconsistent manner. I’ve looked at it in a spreadsheet, and a clean section would look like this (columns 1-4 are the successively increasing readings, column 5 is the average of the first four, and column six is the difference from the first reading to the average reading) Note the last column is all 0 or 1:

Code:
1020	 2040	  3060 4080 1020 0
789	 1577	 2366	 3152	 788	 1
1020	 2040	 3060	 4080	 1020	 0
662	 1325	 1989	 2653	 663	-1
909	 1817	 2727	 3637	 909	 0
553	 1105	 1657	 2209	 552	 1
957	 1916	 2874	 3834	 958	 -1
477	 955	 1434	 1913	 478	 -1
643	 1286	 1929	 2573	 643	 0
400	 800	 1200	 1599	 400	 0
607	 1215	 1824	 2433	 608	-1
This is what a bad section looks like, same columns:

Code:
116	 233	 118	 236	70	46
137	 136	 274	 412	96	41
109	 109	 218	 328	76	33
72	 145	 217	 290	72	0
93	 187	 282	 94	66	27
109	 218	 110	 220	66	43
89	 178	 268	 90	63	27
57	 114	 171	 229	57	0
77	 77	 154	 231	54	23
89	 179	 90	 90	45	44
73	 74	 74	 74	30	44
45	 90	 135	 181	45	0
These two sections were taken from the same run, so nothing changed while the testing was in progress. Note the last column with errors of twenty, thirty, and forty counts. These are caused by some of the readings not adding properly, and the failures seem to have no pattern.

I’m wondering if there is a timing problem since I’m using eeprom. Should I insert PAUSE commands in my program around the eeprom reads and writes? I can’t think of anything else that could be causing this.
 

hippy

Technical Support
Staff member
For internal WRITE you don't need any pauses, for HI2COUT you usually will.

Two things you can do - (1) Write a short bit of test code to prove you can do what you want to do, and (2) post your code, or part of it, to the forum and let others see if there's some obvious or even subtle problem.

One notable thing is that your first 'code' listing shows values all greater than byte values (>255), the second all byte values (<256). Perhaps that is playing some part in things ?
 

westaust55

Moderator
External i2c EEPROM needs a 5ms delay between each write instruction whether single or multibyte write format.
If you are performing writes in rapid succession your pauses will need a larger parameter. For example PAUSE 5 needs to become PAUSE 20 if speed increased from default 8MHz (for X2 parts) to 32 MHz and use the _32 suffix to the i2c setup command.
 

wapo54001

Senior Member
Thank you for the confirmation that timing was not an issue with reading/writing eeprom. With that assurance I went back through my program and found the glitch. Now works flawlessly.
 
Top