Timeclock

Tony P

Member
I have made a heating time clock which is working fine with the exception of the following line.

Code:
IF DAY=$1 OR DAY=$7 AND HOUR>=$09 AND HOUR <=$17 THEN LET HEAT=19:RETURN:END IF
This only works for day $7 (Saturday) and not day $1 (Sunday)
 

Aries

New Member
I've run this through the simulator (with 20x2 and 28x2):
Code:
#picaxe 20m2
symbol DAY = b0
symbol HOUR = b1
symbol HEAT = b2

for b0 = 1 to 7
    sertxd(13,10,"D",#b0)
    for b1 = 1 to 24
        b2 = 0
        IF DAY=$1 OR DAY=$7 AND HOUR>=$09 AND HOUR <=$17 THEN 
            LET HEAT=19
        END IF
        sertxd(" ",#b2)
    next b1
next b0
and it produces
Code:
D1 0 0 0 0 0 0 0 0 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 0
D2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
D3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
D4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
D5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
D6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
D7 0 0 0 0 0 0 0 0 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 0
Superficially this looks right to me - HEAT is 19 between HOURs 9 and 23 on DAYs 1 and 7. In what way is it not working?
 

tmfkam

Senior Member
I might write that as:
If Day=$1 Or Day=$7 Then
If Hour>=$09 And Hour <=$17 Then
Let Heat =19
Return
EndIf
EndIf

It is possible your version is not being interpreted in that way.
 

Tony P

Member
It jumps to the next line of code which turns the HEAT up to 20 after 17:00 hours.
It too works in my simulator but not in 'real life'
 

Tony P

Member
SORRY i may have just posted the wrong line of code. This line is the one I meant to post
Code:
IF DAY=$1 OR DAY=$7 AND HOUR>=$18 AND HOUR <=$23 THEN LET HEAT=20:RETURN:END IF
This mixes AND and OR but works fine
 

Aries

New Member
I'm intrigued as to why your HOUR would ever be >= $18 (=24 decimal) and anything other than <= $23 (=35 decimal).

As tmfkam and InglewoodPete imply, it is better not to write complicated mixed conditionals. It is clearer (and safer) to break them up into smaller bits which have no ambiguity.
 

Tony P

Member
I might write that as:
If Day=$1 Or Day=$7 Then
If Hour>=$09 And Hour <=$17 Then
Let Heat =19
Return
EndIf
EndIf

It is possible your version is not being interpreted in that way.
I have re-written all of my lines as you suggest. It works fine in the simulator. I will download the code to my thermostat and give it a try
 

Tony P

Member
I'm intrigued as to why your HOUR would ever be >= $18 (=24 decimal) and anything other than <= $23 (=35 decimal).

As tmfkam and InglewoodPete imply, it is better not to write complicated mixed conditionals. It is clearer (and safer) to break them up into smaller bits which have no ambiguity.
It is something I have always done using the following code. I can enter actual time (0-23) and date values (0 to 31)
Code:
    i2cslave %11010000, i2cslow, i2cbyte
    hi2cin 0,(SECONDS,MINS,HOUR,DAY,DATE,MONTH,YEAR)
    BCDTOASCII DATE,DATE_T,DATE_U
    BCDTOASCII HOUR,HR_T,HR_U
    BCDTOASCII MINS,MIN_T,MIN_U
    BCDTOASCII SECONDS,SEC_T,SEC_U
 

Aries

New Member
It jumps to the next line of code which turns the HEAT up to 20 after 17:00 hours.
It too works in my simulator but not in 'real life'
Are you sure? If so, this is a bug in the simulator and ought to be reported. You will need to put in SERTXDs to show that the same "inputs" produce different "outputs" for the chip and the simulator.
 

lbenson

Senior Member
I'm intrigued as to why your HOUR would ever be >= $18 (=24 decimal) and anything other than <= $23 (=35 decimal).
Most RTCs which picaxers play with return values as BCD (Binary Coded Decimal), so the hex value $18 means 18 hours, not the 24 you would expect if looking at the decimal value.
 
Top