lcd question with 18m2

klaasje

Member
Hello,

I want to make an hour meter.
I want to put a fixed text on line 1
i want to put a variable (hours) on line 2

I do not now how to put a variable on the display

I want to count the hours in the 18m2 chip

Can anyone give me a little support in it?

Thanks in advance
 

Attachments

klaasje

Member
i do not need a accurate time counter. i only count pro hour ( operating hours) i count on the timebase of the chip. i only need to display it as variable on the display on the second row. i do not now how to do that.
 

hippy

Technical Support
Staff member
You will need to use an appropriate sequence of commands -
Code:
high/low rs		; data/command mode
let pinsB = ?		; move to line 2, instruction 192
pulsout enable,1  	; pulse the enable pin to send data.
To position the display cursor where you want the time counter to be displayed, and similar to actually output the numbers themselves.
 

Flenser

Senior Member
I do not now how to put a variable on the display
This modified version of your program uses the 18M2 TIME system variable to display the number of hours elapsed since startup.
The TIME system variable counts up to 65535 seconds (a little over 18 hours) and then wraps around to 0.
Keeping track of hours > 18 is a different problem so I've posted this version of your program to answer your original question of how to show a variable as a number on the display.
 

Attachments

klaasje

Member
Hi Flenser,

it is working but i need to store it in the eeprom and get it back when starting the machine again. I also need to store at least 5000h

Can you help me a little with the code?

Thanks in advance
 

erco

Senior Member
Hi Flenser,

it is working but i need to store it in the eeprom and get it back when starting the machine again. I also need to store at least 5000h

Can you help me a little with the code?

Thanks in advance
You'll WRITE the value to EEPROM and READ it back. Word variables will get split into two bytes, per Manual 2. I suggest you start your program with byte variables. Get that working first, then expand to Word variables.
 

AllyCat

Senior Member
Hi,
I need a 4 digit on the display. I now only get 2 digits
You need to use a Word variable and store it in Non-volatile memory with WRITE and READ commands. However, these commands work only with individual bytes (or the WORD qualifier) , so you need to split the Words into individual bytes, e.g. using w1 = b3 * 256 + b2 or WRITE b2 , b3 or WRITE WORD w1.

But you need to be careful not to "wear out" the EEPROM memory which is limited to perhaps 100,000 WRITEs (there is no limit on READs) for each byte location. Various strategies are possible, depending on the hardware/program structure:

- If the program itself can control the power-down, then it can store the time in EEPROM before doing this.

- The PICaxe can have its own "large" decoupling capacitor, detect the external power failure and store the time when necessary.

- The PICaxe can update the elapsed time, for example each hour (but not less than every 10 or 6 minutes), then count the shorter periods in Variables/RAM which are "lost" if the power fails.

Cheers, Alan.
 

Flenser

Senior Member
klaasje,

This modified version should display the elapsed hours up to 65535 (after which the value in variable w3 will wrap around to 0).

I've never saved values in EEPROM so that they are not lost when the power is lost so I'm not certain I can give you the best advice about this.
I've seen posts discussing the issues with this so perhaps someone else on the forum can point you to a post with code you can use.
 

Attachments

neiltechspec

Senior Member
I use an FRAM (MB85RC256V) in my electronic speedo / odo.
Make sure it's a genuine Fujitsu chip and not a cheap chinese clone.

Writes to FRAM every 1/10 of a mile.
Good for 10 to 12th power of write cyles - lotsa miles.
 

marks

Senior Member
Hi Klaasje,
you probaly will require at least a 200uf cap to hold up your oled 1602 display
it can be trickly to save variables with the supply collapsing
I assumed you are using a 5v regulated supply

a better method may be to seperate the supply to the 18m2 with a diode and its own decouplin.

another method would be to moniter the supply on the input of the regulator(12v)and use readadc10 instead
here's some code to experiment with .

Rich (BB code):
#picaxe 18m2  '  AXE132 8Bit marks
#terminal 38400
'           DB7  = B.7
'           DB6  = B.6
'           DB5  = B.5
'           DB4  = B.4
'           DB3  = B.3
'           DB2  = B.2
'           DB1  = B.1
'           DB0  = B.0
SYMBOL Rx  = C.5
SYMBOL  E  = C.6
SYMBOL RS  = C.7
SYMBOL senddata    = pinsb
SYMBOL index       = b0
SYMBOL Hours =W2
SYMBOL H00=W3
SYMBOL CALIB_ADC10 = W4
SYMBOL supplytest = b27
      SETFREQ M32 ' time in 0.5sec increments
     dirsB = %11111111
     dirsC = %11001111

Initialise:
DO : CALIBADC10 CALIB_ADC10 :  LOOP until  CALIB_ADC10 < 220   ' Reach 4.76v  (1047.5/220) 

    FOR  index = 0 to 7
          LOOKUP index, ($38,$38,$38,$08,$01,$02,$06,$0C),senddata : PULSOUT E,1 ' Initialise LCD/OLED
          '(8bit/2line/5x8)*3(Display Off)(Clear Display)(Return Home)(Entry Mode Set)(Display On)
     NEXT index : PAUSE 10

      Display:
            LOW  RS                                     ' commandmode
            senddata = 128 : PULSOUT E,1                ' (128-147) Line 1 Cursor Position

           HIGH RS                                      ' charactermode
           FOR  index = 0 TO 15
               LOOKUP index,("18M2 Picaxe! ",b12,b11,b10),senddata : PULSOUT E,1 
           NEXT index

PAUSE 10000  
CALIBADC10 CALIB_ADC10 : supplytest=CALIB_ADC10+10 :sertxd(#CALIB_ADC10,32,#supplytest,cr)'supplyV=1047.5/supplytest

     LOW  RS                                            ' commandmode
     senddata = $01 : PULSOUT E,1  : PAUSE 12           ' Clear Display
                  
     Start:
     read 0,word H00 : read 2,word Hours : Time=H00
            
     HourMeter:
        LOW  RS                                                                      ' commandmode
            senddata = 192 : PULSOUT E,1                ' (192-211) Line 2 Cursor Position
            HIGH RS                                                                      ' charactermode

    IF time = 7200 then : Time=0 : INC Hours : IF Hours=10000 THEN :Hours=0: ENDIF : write 2,word Hours : ENDIF                                
           BinToAscii Hours,b13,b13,b12,b11,b10
           FOR  index = 0 TO 11                                                          ' sending characters
           LOOKUP index,("Hours : ",b13,b12,b11,b10),senddata : PULSOUT E,1                
           NEXT index
     
CALIBADC10 CALIB_ADC10 : IF CALIB_ADC10 >supplytest THEN remember 'attempt to detect poweroff

      H00=time*5/36
          BinToAscii H00,b12,b11,b10
           FOR  index = 0 TO 3                                                           ' sending characters
           LOOKUP index,(".",b12,b11,b10),senddata : PULSOUT E,1                
           NEXT index   

CALIBADC10 CALIB_ADC10 : IF CALIB_ADC10 >supplytest THEN remember

     goto hourmeter
         
     Remember:
write 0,word Time
 
Last edited:

AllyCat

Senior Member
Hi,

Over 280 "views" of this thread so far, but the attachments have been downloaded by only 3 - 8 members, which shows why it's generally better to post Program details within [code ] [/code] tags !

From the code attached to post #1, it appears that the program already has a "timing" loop which changes the display in a repeating pattern? So it would be "sensible" to incorporate all the basic required (timing) functions into one main program loop (which currently starts as follows) :
Code:
main:
  inc b10
  debug     ; ** Is / will this be in the "final" program ?
  wait 10    ; ** Currently 2.5 seconds ?
  if b10>5 then : b10=1 endif
  if b10=1 then
....    ; **  Lots of stuff probably better within a SELECT ... CASE structure :-)
However, the above section of program is partially being timed by the DEBUG command (approximately equivalent to a PAUSE 200), that also can "defeat" the correct operation of the time variable :( .

Incidentally, the DS1307 RTC suggested in post #2 happens to contain battery-backed non-volatile memory (but sadly not the more recent DS3231) which could "kill two birds with one stone" (i.e. easily keep accurate time but not wear out the EEPROM). However, eventually the battery in a RTC will run down...... :(

Therefore, IMHO there is no point in continuing with the detailed "design" of this project until a "Specification" is available, with information such as for example how many years the product is expected to operate, and a strategy is defined for updating the EEPROM values (if used) without "wearing out" the memory (e.g. as in #13).

Cheers, Alan.
 

Flenser

Senior Member
Therefore, IMHO there is no point in continuing with the detailed "design" of this project until a "Specification" is available, with information such as for example how many years the product is expected to operate, and a strategy is defined for updating the EEPROM values (if used) without "wearing out" the memory (e.g. as in #13).
AlleyCat,

Klaasje has already given us his spec for "how many years" in post #9:
I also need to store at least 5000h
To your second point about saving values in EEPROM to protect from a power outage, my impression is that Klaasje is asking for advice from the forum on how he might go about this so the implications of choosing different strategies without wearing out the EEPROM would be a part of the advice from someone recommending a particular strategy (which advice could then be reviewed by other forum members.)
Klaasje, pls correct me if I have misunderstood about this point.
 

Flenser

Senior Member
Klaasje,

Have you thought how you expect saving the hours value in EEPROM to work?
If you save the hours value immediately after it is incremented and the power goes off 1 sec after the value is saved then:
- If you turn the power back on 5 minutes later then your hours count will have lost 5 min.
- If you don't notice that the power is off for 24 hours then when you turn the power back on your hours count will have lost 24 hours.
- If you don't notice that the power is off for 48 hours then ..., and so on

The only way you can cater for this is if you have a clock working on a separate battery like the DS1307 or DS3231 Real Time Clock chips that AlleyCat refered to (and which are available cheaply as PCB modules with a coin cell backup battery on Ebay)

Running the PICAXE with a 2nd battery backup power supply could also work as the program would continue to run for as long as the backup battery lasted giving you time to fix the power supply problem.
 

AllyCat

Senior Member
Hi,
Klaasje has already given us his spec for "how many years" in post #9:
I don't think so. The program listed in #1 appears to be for an "automobile" type of application, or similar, for which a target lifetime might be 10 or 20 years (or more). The "5000 hours" appears to apply to parameters such as " Hydr. oil low " , " Dynamo off " or " Dynamo Hours " , etc. but we have no indication whether the "engine" might run for separate periods of minutes, or hours or days?
choosing different strategies without wearing out the EEPROM would be a part of the advice from someone recommending a particular strategy
Personally, I wouldn't "recommend" any particular strategy until I know how the software and/or hardware will be used. That's why I proposed 3 possibilities in #13, for the OP to choose or to reject.

Cheers, Alan.
 

hippy

Technical Support
Staff member
I was one of those who downloaded the original code and would agree with the assessment that it cycles the display through five different displays,, as best I can tell -
Code:
.----------------.
| Pickstar  4.0  | b10=1
| Hydr. oil low  |
`----------------'
Code:
.----------------.
| Pickstar  4.0  | b10=2
| Hours          |
`----------------'
Code:
.----------------.
| Inventtech.nl  | b10=3
| Emergency stop |
`----------------'
Code:
.----------------.
| Pickstar  4.0  | b10=4
| Dynamo off     |
`----------------'
Code:
.----------------.
| Inventtech.nl  | b10=5
| Dynamo Hours   |
`----------------'
I wasn't sure where the elapsed hours display was meant to be included, as part of 'b10=2' or 'b10=5'. Hence the reason for asking for code where the two-digit display had been implemented as that would show where and how to change that for four digits.

There are four separate parts to the project; whatever it does overall, how to count elapsed time, how to store that, and how and where to display it.

I would personally start by refactoring the code to make a two line display much easier to implement. Then one can start adding code to display that and provide live data where required. But, without knowing fully what is to be displayed, it's hard to say what the best way to do that is.

As for having 'elapsed hours' that might be a bit trickier than first appears. If one only keeps track of those the data will only update once an hour. Run for 50 minutes, turn off, repeat that, and it will never accumulate any elapsed hours. One probably needs to track an number of elapsed minutes, even seconds, depending on how much inaccuracy and time loss on power loss one is willing to tolerate.

In many ways it's the familiar problem of trying to provide a solution without knowing what solution is actually required. An overview of what it is that is to be achieved would probably help move things on.
 

Flenser

Senior Member
Hippy,

My assumption has been that Klaasje is using an incremental approach to developing his application.
- First modify a copy of AXE133.bas as a skeleton that is just writing two messages for each case. His initial version doesn't display anything useful because it doesn't measure anything, the messages are all hardcoded, however he now has a working skeleton of his program where the code to drive the LCD works.
- Then progressively expand each the cases so that they display updated information on each cycle.

Coding a 2 line LCD to continually cycle in this way appears to be the technique that Klaasje is using to allow the program to continuously report the state of several measurements that might be too much information to comfortably fit in 32 or 40 characters on just 2 lines.

So the next incremental steps sounds like they will be to display the elapsed hours as a part of the appropriate case and save the current elapses hours in EEPROM:
- i want to put a variable (hours) on line 2. I do not now how to put a variable on the display
- I want to count the hours in the 18m2 chip
- i need to store it in the eeprom and get it back when starting the machine again. I also need to store at least 5000h

As both you and AlleyCat have already pointed out, simply saving the current hours in EEPROM may not be as useful as he expects and for that particular function Klaasje will need to expand for the forum how he expects having a saved value will work for him.
 

Flenser

Senior Member
Two minutes after my last post the penny just dropped.
We've all assumed that Klaasje wants to record the elapsed time since the program was started, because that is what we typically see requested on the forum, but if Klaasje is recording operating hours then simply saving the variable in EEPROM could do exactly what he requires.
i.e If you want to know when the 1000 hour service is due then you want to record operating hours, not elapsed time. You actually don't want the hours value to be updated while the machine is turned off.
 

hippy

Technical Support
Staff member
Two minutes after my last post the penny just dropped.
I don't think it really matters which it is; whether the hours operated count is zeroed at the start or loaded from EEPROM and updated and stored as time progresses. "Operating" may also be something other than when the PICAXE is powered up., for example how long a fan or something has been turned on.

That divides the problem in two; display and keeping track of what is to be displayed, the later which itself may have multiple aspects to it..
 
Top