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:
This is what a bad section looks like, same columns:
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.
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
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
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.