Eprom question

buntay

Senior Member
Chip = 08m2
Purpose= water meter monitor
code:
Code:
'c.0= USB out
'c.1= meter input
'c.2= serout
'c.3= serin
'c.4= water valve
'c.5= USB in



setfreq m16
read b15,WORD w0
b4=1

pause 10000
main:
b7=0
if w0> 9999 then let w0=0
end if
SERIN [1000], c.3,t9600_16,#b7
if b7=22 then goto control
w1=w0
if pinc.1 =1 then let w0=w1+b4: write b15,WORD w0:goto safe
else goto main
end if
safe:
pause 500
if pinc.1 =0 then goto main
goto safe

control:
b7=0
serout c.2,t9600_16,("ok",cr)

again:
SERIN [1000], c.3,t9600_16,#b6
if b6=2 then goto readout 
if b6=3 then goto wateroff
if b6=4 then goto wateron
if b6=5 then goto logout

goto again

readout:
serout c.2,t9600_16,(w0,cr)
serout c.2,t9600_16,("ok",cr)
b6=0
goto again

wateroff:
high c.4
serout c.2,t9600_16,("Water Off",cr)
serout c.2,t9600_16,("ok",cr)
b6=0
goto again

wateron:
 low c.4
serout c.2,t9600_16,("Water ON",cr)
serout c.2,t9600_16,("ok",cr)
b6=0
goto again

logout:
serout c.2,t9600_16,("LOGGGED OUT",cr)
serout c.2,t9600_16,("ok",cr)
b6=0
goto main
Greetings all!!

So, I have a water meter I am installing for a renter that uses roughly 1500 gallons a month. The purpose for this project is so I can get that meter reading from my house through a ttl to Ethernet connection for billing purposes, that part is not the problem I need help with.The water meter has a pulse for each gallon that passes through it and I am counting those pulses. I decided to put each new count into the eprom in case the power drops out or some type of reset happens.

I am aware of the 100,000 cycles to a single address on the eprom. My question is how do I maximize eprom use by writing to a different address of the eprom at a given point, say at 75,000 cycles.


Thanks in advance for any suggestions :)
 

lbenson

Senior Member
I am aware of the 100,000 cycles to a single address on the eprom. My question is how do I maximize eprom use by writing to a different address of the eprom at a given point, say at 75,000 cycles.
An easy way might be to use the first byte of onchip eeprom to save which 2-byte word you are recording to (initialize with "write 0,2:write 2,WORD 0"). Then write a count. When the count is near to exceeding a word size, say 65,000, increment the pointer and move to the next word:
Code:
increment_count:
  read 0, b4
  read b4, WORD w13
  if w13 >= 65000 then
    b4 = b4 + 2
    write 0,b4
    w13 = 0
  endif
  inc w13
  write b4, WORD w13
  return
This gives you 127 * 65000 writes, or over 8 million gallons, and you haven't come close to reaching the limits of the eeprom.
(Not tested.)

Alternatively, you could let each of the 128 words of eeprom represent a month. Then you could record monthly totals for over 10 years. This would require having a real-time-clock, so you might need to step up to a 14M2 if you are actually using all the pins on the 08M2.
 
Last edited:
Top