Programming picaxe 18x

rabag

New Member
Hi,

I am nearly there with my program for my picaxe clock using a a 4 digit display and pic 18 x chip. I can get my program to display the time in 24 hour clock setting. But the problem is the timing of the clock, I am slow by 2 to 3 mins of real time over 24 hours. I cannot get the clock to run this accuratley going fast. My idea was if I could get the clock running fast by 2 - 3 mins then I could just pause the program for this amount of time at midnight, which I would be happy with. I have spent a long time trying to get around this any help would be very welcome. Here is my program.

main:
let b0= 31 ' %00011111
let b1= 47 ' %00101111
let b2= 79 ' %01001111
let b3= 143 ' %10001111
label_3A: for b6= 1 to 84
for b5= 1 to 85 ' Pins nare repeated to get even brightness on display
let pins =b3
let pins =b0
let pins =b1
let pins =b2
let pins =b1
let pins =b2
let pins =b3
let pins =b0
let pins =b2
let pins =b3
let pins =b0
let pins =b1
let pins =b3
let pins =b2
let pins =b0
let pins =b1
let pins =b0
let pins =b2
next b5
next b6
label_14: if b0= 22 then label_41
let b0=b0- 1
'pause 1000
goto label_3A

label_41: let b0= 31
if b1= 42 then label_51
let b1= b1-1
'pause 1000
goto label_3A

label_51: let b1= 47
if b2= 70 then label_52
let b2= b2-1
if b2= 75 then label_100

goto label_3A

label_52: let b2= 79
if b3= 141 then label_53
let b3= b3-1
'pause 1000
goto label_3A


label_53: goto main:

label_100: pause 174000
if b3= 141 then main
goto label_3A
 

hippy

Ex-Staff (retired)
Without using an accurate timer the time will drift, run slow or fast. Running fast is easier than running slow to fix as all you need to do is add suitable delays to slow the program down.

You could add a pause to fix the problem at midnight ( or any other particular time ), but you can also add more smaller pauses elsewhere. If you need to delay 360 seconds every day, you could equally delay 15 seconds every hour (15x24=360). You could also use very small delays every second, and this will keep the clock more accurate throughout the entire day.

I haven't studied your code to see exactly where such delays would need adding or of what size. You can use PAUSE but you can also use PULSOUT on an unused pin to set very small delays.
 

BCJKiwi

Senior Member
Haven't studied the code in full but at label_100: you have a pause of 174000,
A pause cannot be more than 65535 (Manual2 page 106) - the same as the max value of a word variable.
You can put one pause after another or create nested for next loops to generate longer delays.

It is also not clear what is controlling the time,
At label_3A there are nested loops which will take a (hopefully) fixed amount of time each cycle,
and
at Label_100, the delay of 174000 which is probably rolling over to 174000 - 65535 - 65535 = 42930, or, is indeterminate.

Try reducing the delay at label_100 to say 30000 (which should be ~ 30 secs) and time how long it takes your clock to reach an hour (~30 seconds for the delay plus a bit for the rest of the program execution).

From this you should be able to calculate what the delay should be to get an accurate time.
 
Top