A bit of a brick wall !!

manie

Senior Member
From the Mosfet switching saga:rolleyes: I have a program running on the 28x1, approx. 2500 bytes. Basic functions (and subs) are:

1a Read preset alternator capacity (4 pin DIP switch) on 4 input pins
(do once only at power up)
1 Monitor battery V (anal.pin), initiate charge if V below preset level
2 Read throttle position (simple pot/R V-divider) on anal. pin
3 Read current (LEM HASS 50-400A) closed loop Hall Effect on anal. pin
4 From 1a and 1-2 above (max capacity,% bat., % throt) calculate new required Amps
5 Compare current Amps with required and Increase/Decrease PWM accordingly
6 Go back and do it all again.

This all works very well, untill the real world happens and strange unexplicable things occur to mess up gas production.:confused:

I would like to store in non-vol. memory the following:
Max bat.V, Min bat V, Max total Amps (min=0), Max Amps per cell(up to 6).

How would I go about reading(and storing) individual cell Amps without doing it EVERY cycle over and over which seems unneccessary, but still get that "something has gone wrong" :eek:type of moment. Along with analogue reads and pausing, a cycle is approx. every second.

Is it "another brick in the wall" or "we don't need no education" ? It feels like I'm under a Lead Zepelin !
Manie
 
Last edited:

Andrew Cowan

Senior Member
I pressume you know about the 'read' and 'write' commands. I'm not sure why you need to store individual cell amps every cycle, and I don't see how you could not have to read them every cycle.

I think I'm a little confused about this.

A
 

manie

Senior Member
Andrew: Yes, the actual "read/write" part is not the problem. Some good logic to execute it more occasionally is....
At present its done every cycle, but thats data overkill ! Also, it means that once every cycle you select one of the cells and switch the others off for a short period in order to monitor that one cell. That means production loss as well as some in-rush current on the other cells when you switch them back on. All not very desirable...
Manie
 

manie

Senior Member
Thats why I said "brickwall" ! Except I'll also have to read/write "b0" as it is used in the other subs etc. etc. Yes, can do that, and extend to say once every 10-20 cycles. WOW, that was easy, thanks mate. Now to determine the best/worst delay between reads/writes....
Manie
 

Andrew Cowan

Senior Member
I wouldn't write to EEPROM that regularly, as it does wear out (after about 1,000,000 writes) (That's 11 days at once a second). Do you not have any variables left? I'm not sure, but it may be possible to use variables elsewhere (eg scratchpad or something).

A
 
Last edited:

manie

Senior Member
I was going to ask that question, "How many writes/reads" can I do to EEPROM memory. You've just answered it, Thanks. Heck, it aint ever THAT easy is it ?
Manie
 

lbenson

Senior Member
>"How many writes/reads"

You can use peek/poke and not worry about eeprom writes--same durability as using b0, etc.
 

manie

Senior Member
Ibenson: Thanks,yes then one can write to EEPROM every 500 or 1000 cycles etc. See why I asked ? Sometimes one just hits that wall, I need a break I think....
 

Dippy

Moderator
Have a nice cuppa coffe Manie. Give the cerebellum a rest :)

EEPROM lifetime (in general) and speed.
Two important points that deserve a couple of highlighted lines in the BASIC Manual methinks?

For lifetime, perhaps something along the lines of:-
"The EEPROM can only accept a finite number of write cycles per location before it wears out. The table above indicates the guaranteed number of writes before failure. If a program frequently writes to the same EEPROM location, it makes sense to estimate how long it might take to exceed the guaranteed maximum."
- plus a small WestAust Table.

Also note, that where possible, you can write to different EEPROM locations to 'spread the load' and increase overall lifetime.

As you have now found out; rapid/regular write/reads to RAM, not-so-frequent-write-and-if-you need-it-stored-during-power-cycle to EEMPROM , and even-less-frequent to Flash.

Manie, if you are having a long coffee break, have a read of Microchip's PIC Data Sheet which will provide you with many of the useful hardware parameters/specifications and limitations. Seriously, 30 minutes now could save hours later.
 

manie

Senior Member
Manie, if you are having a long coffee break, have a read of Microchip's PIC Data Sheet which will provide you with many of the useful hardware parameters/specifications and limitations. Seriously, 30 minutes now could save hours later.
Dippy: Mucho Gratias (or words to that effect). There is still SO MUCH in the old 28x1, I doubt I will EVER outgrow its capabilities. I will have a look at the sheet after downloading. At present I'm just amazed by Jenson's performance in Malaysia ! Now THAT was a coffee break.....

It would be good to detect a "power down" situation and write to EEPROM all the variables you need to store JUST THEN, once per trip... possible ? Maybe with an 08M acting as delay/mosfet switch driver, instructing 28x1 to write data now, then shut down power ?
 

lbenson

Senior Member
If you are running out of "bx" variables on the 28X1 there are a couple of things you can do.

First do any of those have values of only 1 or 0? If so, store them in the bit0-bit15 variables (which are a remapping of b0 and b1).

Next if you need to "double-up", pick the slowest changing variables--not a loop counter but something which is tested or changed at the bottom of nested "if"s. Then you can poke the current value in, say, b13, peek the new value you want, test or change it, poke it back if changed, and peek the original back again.
Code:
if pin3 = 1 then
  if pin 5 = 0 then
    poke 0x50,b13  ' replace with symbolic names, of course
    peek 0x51,b13
    inc b13
    poke 0x51,b13
    b13 = b13//10
    if b13 = 0 then       ' do something every 10th time
    endif
    peek 0x50,b13
  endif
endif
 

Andrew Cowan

Senior Member
It's easy enough to detect power down and save other data.

Supply = 12V ish
Large capacitor (4700uF?)
5V Voltage regulator
PICAXE

Make the PICAXE read the battery voltage via READADC and a voltage divider. If the voltage falls to 7 or 8 volts after the capacitor, the regulator will still give out 5V, however, it means the supply has been disconnected. Write to EEPROM.

A
 

manie

Senior Member
Ibenson & Andrew: That is the type of code I had in mind BUT.... as always hoped there is a "smarter" way. Alas ! There is no such thing as free energy ! Yup, I will do that kind of code.

I have EXACTLY the electricals described, including 4700uF on main input plus some 100uF's after.. and I have one ADC pin spare, so will use your good idea to detect voltage drop and do quick save.

What about a divider arrangement from the raw +-12V(before the 4700uF) to give say 2.5V to 3V on one input ? This should drop low fairly quickly, generating an interupt on the pin going low ? Yes/No ?
Manie
 

hippy

Ex-Staff (retired)
Don't forget that one easy option for extending life of an Eeprom is to simply not write to it unless you have to; if it's the same as you are about to write - don't - if it's not changed much you may again choose not to.

You can also choose to write less frequently or put the data in different places rather than write to the same locations each time. More are more complicated techniques as well.

It took me a while to work out what the 'brick wall' issue was as there's quite a lot of superfluous information in the initial post which is largely irrelevant to the problem at hand, yet it's still not clear what the saved data is being used for, how or why.

This is a common problem; "this is what I have, how do I make it work ?", whereas a better question could be, "this is what I need, how can I achieve it ?"

You say you need to "still get that "something has gone wrong" type of moment", though I have no idea what that means in practice. Detailing what the data is you are storing and how you need to use that can go a long way to getting a best answer. How that then integrates with other requirements is really the second phase of implementation.
 

manie

Senior Member
Hippy: True what you say. Here is what I said I wanted to store:
I would like to store in non-vol. memory the following:
Max bat.V, Min bat V, Max total Amps (min=0), Max Amps per cell(up to 6).
The reason why ? I've had occasional problems with a Browns Gas cell going beserk/overheating and even a loud BANG !(read ecplode !). By the time the truck gets back to base, the cause of the mishap is not so obvious anymore. This way I can see the trip history data as listed above and maybe figure out what went wrong or what the cause was. Does this help ?
 

Dippy

Moderator
Something along the lines of Andrew's suggestion has been used by the Old Lags for years.

Sometimes a little care has to be used as this method assumes the power supply never goes low impedance.
Possibly a more reliable arrangement would be Battery+ -- Diode --- Fat capacitor --- etc.
And tap off betweem Bat+ & diode with your pot div. either to ADC or an input pin.

As I said before, you can extend the life of the EEPROM by writing to different locations, it's the individual EEPROM 'cells' that have the lifetime issue. At the point of battery failure you could write the 'last cell written to' number (i.e. the last location number) so you don't get muddled.

And obviously you'll realise that as battery droops then the amount of time your capacitor can provide power will be reduced.
Ideally your PICAXE section of the circuit should use as little power as possible.
 

manie

Senior Member
Dippy: My power connection looks like this:

+12V------|>|--------|)------7812
..............1n5408......4700uF

which is basically what you describe. So take off between +12V and diode to input/adc pin then. Will try and see what happens. Maybe add another 4700uF cap for extra backup ?
Manie
 
Last edited:

manie

Senior Member
Why not?
Have a go.
Be brave.
Try it.
Dippy, was it not you that once said (to me) "going straight to artwork before breadboarding is........ errr, BRAVE " ? But since then, I've tried to follow more conventional lines.....:rolleyes: Don't worry, I'll be brave and WILL try it as you well know... ?

Andrew, no, first 7812, then to the 7805. I use the 7812 regulated power on transistors/relays etc.
 
Last edited:
Top