Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help me, 2 seconds time error in along delay time

Status
Not open for further replies.

fs789

New Member
hi,
i have written this program in assembly language, having two delays:
(5 seconds and 3595 seconds) , the sum of them equals 1 hour.
the program must turn on ALED for five seconds,then turning it off for 3595 seconds
then repeating the process.in other words,(( the led must turn on every 1 hour exactly)).
the problem is as follows: when connecting the circuit actually, the program goes well for the first 6 hours , but after that , the LED turns on 2 seconds before the expected time!!!!!!!!!!! having errors.
The tow delayshave been made by PIC_Delay program. and the crystal frequency 4MHZ,
with tow capacitors 22PF.
PLEASE EXPLAIN FOR ME WHAT IS THE REASON OF ERRORS?? I HAVE CALCULATED NUMBER OF MACHINE CYCLES WITH MPLAB STOP WATCH AND EVERY THING IS OK.

PROCESSOR 16f84a ; Defining processor
#include "p16f84a.inc" ; Microchip INC database
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
; frequency 4MHZ
CBLOCK 0X0C
COUNT,D1,D2,D3,D4
ENDC

org 0x00
goto first

first
bsf STATUS,5
CLRF TRISB
BCF STATUS,5
CLRF PORTB

DELAY BSF PORTB,0
movlw .1
movwf D1
movlw .86
movwf D2
movlw .26
movwf D3
decfsz D1,F
goto $-1
clrwdt
decfsz D2,F
goto $-4
decfsz D3,F
goto $-6
nop
nop
BCF PORTB,0

movlw .153
movwf D1
movlw .112
movwf D2
movlw .62
movwf D3
movlw .72
movwf D4
decfsz D1,F
goto $-1
decfsz D2,F
goto $-3
decfsz D3,F
goto $-5
decfsz D4,F
goto $-7
nop
nop
GOTO DELAY



END
 
please ,can any one help me???

hi,
Does the timer gain an additional 2 seconds every hour after the first 6 hours, 2, 4,6 or does it remain at 2 sec error.??
 
hi,
Does the timer gain an additional 2 seconds every hour after the first 6 hours, 2, 4,6 or does it remain at 2 sec error.??
hi,
i am noticing that the error is increasing!!!!
but note that the timer turns the led on before the expected time not after it !!!!!!!!!
 
hi,
i am noticing that the error is increasing!!!!
but note that the timer turns the led on before the expected time not after it !!!!!!!!!

hi,
OK, Is there any chance you could check the frequency stability of your crystal osc.??
You would require a frequency counter unit, its possible that the drift is due to a number of causes, temperature etc.?
 
1) You don't need the clrwdt instruction, it is disabled
2) Try disabling MCRL
3) (Minor) The goto first makes no sense, its the next instruction
4) Put decoupling capacitor across Vdd and Vss
 
hi,
OK, Is there any chance you could check the frequency stability of your crystal osc.??
You would require a frequency counter unit, its possible that the drift is due to a number of causes, temperature etc.?

Unfortunately, MY MULTIMETER measures frequency up to 200KHZ, AND THE CRYSTAL IS 4MHZ.
SO I CAN NOT measures frequency !!!!!!!!!!
SO ,WHAT IS THE SOLUTION YOU SUGGEST FOR ME??
 
1) You don't need the clrwdt instruction, it is disabled
2) Try disabling MCRL
3) (Minor) The goto first makes no sense, its the next instruction
4) Put decoupling capacitor across Vdd and Vss

How we can disable MCLR?
what is the value of decoupling capacitor across Vdd and Vss?
 
Unfortunately, MY MULTIMETER measures frequency up to 200KHZ, AND THE CRYSTAL IS 4MHZ.
SO I CAN NOT measures frequency !!!!!!!!!!
SO ,WHAT IS THE SOLUTION YOU SUGGEST FOR ME??

hi,
You could try to replace one of the crystal caps with a 3 to 35pF trimmer cap and trim to get close to correct timing.
That error is only about 400cycles in 4mHz, so it may be quite difficult to maintain an accurate timing over 24 hours.
Whats the purpose of the project.?

Have you covered the points posted by 'birdman'.?
 
The error you are seeing is within the limits for an "uncalibrated" crystal oscillator using a cheap crystal.

I also suggest that the frequency accuracy of your multimeter is not much better than the crystal, so would not really help if it did work at 4Mhz.

So, I think that you should try increasing the value of the "22pF" capacitors, try doubling the value by putting another 22pF in parallel and measure your timing error again.
This should make the clock run a bit slower.
The oscillator frequency is adjusted by varying the value of the capacitors.
You could also make one of the capacitors variable, (use a 68pF trimmer capacitor), to get a fine adjustment for your oscillator frequency.

JimB
 
Last edited:
hi,
You could try to replace one of the crystal caps with a 3 to 35pF trimmer cap and trim to get close to correct timing.
That error is only about 400cycles in 4mHz, so it may be quite difficult to maintain an accurate timing over 24 hours.
Whats the purpose of the project.?

Have you covered the points posted by 'birdman'.?
yes ,i covered the points.
this project is not the aim ,but it is for experiment purpose.
my original project is to turn on arelay for 5 seconds every one hour for 6 hours from six oclock to 12 oclock . then having arest time for 18 hours (( to next day)), and repeat it daily automatically.
which is more accurate : delay loops or timer zero??
 
Last edited:
The error you are seeing is within the limits for an "uncalibrated" crystal oscillator using a cheap crystal.

I also suggest that the frequency accuracy of your multimeter is not much better than the crystal, so would not really help if it did work at 4Mhz.

So, I think that you should try increasing the value of the "22pF" capacitors, try doubling the value by putting another 22pF in parallel and measure your timing error again.
This should make the clock run a bit slower.
The oscillator frequency is adjusted by varying the value of the capacitors.
You could also make one of the capacitors variable, (use a 68pF trimmer capacitor), to get a fine adjustment for your oscillator frequency.

JimB
thank you,
can i use two capacitors each of them 68PF??
and in this situation,is the accuracy acceptable?
remember that the circuit is working 24 hours continuously for ayear.
i am afraid of accumulating errors!!!
which is more accurate : delay loops or timer zero??
 
Last edited:
thank you,
can i use two capacitors each of them 68PF??
and in this situation,is the accuracy acceptable?
remember that the circuit is working 24 hours continuously for ayear.
i am afraid of accumulating errors!!!
which is more accurate : delay loops or timer zero??

hi,
The accuracy you are aiming for is not possible with standard crystals.

There are versions of the DSxxxx RTC which claim a few seconds a year.
 
hi,
The accuracy you are aiming for is not possible with standard crystals.

There are versions of the DSxxxx RTC which claim a few seconds a year.
i conclude from you that both of delay loops or timer zero may give the same errors in time. and the accuracy only depends on crystal stability .do you agree with me??
i have asmall crystal from awatch(( i think it is 32768 HZ)). can i use it for my project??
 
i conclude from you that both of delay loops or timer zero may give the same errors in time. and the accuracy only depends on crystal stability .do you agree with me??
i have asmall crystal from awatch(( i think it is 32768 HZ)). can i use it for my project??

You could use the 32kHz crystal with say TMR0 and generate a timed interrupt,
 
You could use the 32kHz crystal with say TMR0 and generate a timed interrupt,
can you please give me the code for a timed interrupt ??
and another question: is the 32kHz crystal ,usually,temperature compensated or not??
 
Last edited:
Get the PIC to measure the mains frequency, that should be quite stable. You can use your 50Hz or 60Hz mains frequency to control the clock.
EXECUSE ME,I DIDN'T UNDERSTAND YOU??
MY QUESTION IS : is the 32kHz crystal ,usually,temperature compensated or not??
 
Status
Not open for further replies.

Latest threads

Back
Top