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.

24 hour delay ? is this correct

Status
Not open for further replies.

Darkstar64

New Member
Well I tried to get as close to 24 hours I could but I got to around 23.93 and thats pretty fine for me its using the 509 by the way just bc its small and there is a size concern anyone know if this is correct or not ?

Code:
delay_23.9					; Delay 24.9 hours
		movlw	.250		; Outer loop : 250x (999+999+999+999+999+999+999+999+3) -1+3+4
		movwf	dc2			; = 1,998,000 = 2 second
		movlw	.250
		movwf	dc1
		movlw	.173
		movwf	dc3
dly1	nop					; Inner loop 1 = 250 x 4-1 = 999 cycles
		decfsz	dc1,f
		goto	dly1
dly2	nop					; Inner loop 2 = 999 cycles	
		decfsz	dc1,f
		goto	dly2
dly3	nop					; Inner loop 3 = 999 cycles
		decfsz	dc1,f
		goto	dly3
dly4	nop					; Inner loop 4 = 999 cycles
		decfsz	dc1,f
		goto	dly4
dly5	nop					; Inner loop 5 = 999 cycles
		decfsz	dc1,f
		goto	dly5
dly6	nop					; Inner loop 6 = 999 cycles
		decfsz	dc1,f
		goto	dly6
dly7	nop					; Inner loop 7 = 999 cycles
		decfsz	dc1,f
		goto	dly7
dly8	nop					; Inner loop 8 = 999 cycles
		decfsz	dc1,f
		goto	dly8
		decfsz	dc2,f
		goto	dly1
		decfsz	dc2,f		; 2 x 250 = 8.3 min's
		goto	dly1
		decfsz	dc3,f		; 8.3 min's x 173 = 1435.9  min's/60 = 23.93 hours
		goto	dly1
		retlw	0
 
Last edited:
Why would you call it 1440 times why not just loop it that makes no sense at all ? unless you loop the call 1440 times and that mean you would need to loop it 5 times if you set the decfsz to 250 and then 1 loop of decfsz of 190 too make a total of 24 hours am I correct on this as well ? and I wasn't asking if my math was correct I was asking if the code was correct ?
 
Last edited:
Why would you call it 1440 times why not just loop it that makes no sense at all ? unless you loop the call 1440 times and that mean you would need to loop it 5 times if you set the decfsz to 250 and then 1 loop of decfsz of 190 too make a total of 24 hours am I correct on this as well ? and I wasn't asking if my math was correct I was asking if the code was correct ?

Presumably he meant to loop it, certainly that's how I read his post.

For creating delays, why not use the Delay Code Generator on the PICList?.
 
I can't use that it doesn't seem to be making the right code everytime I use it to make the code and then write it to the 509 then test it it just stays on forever I wanted a 10 sec delay it gave me a unknown delay I stopped it at 30 seconds so im not sure whats going on also I don't know if its limited to 256 since the 509 is only 8-bit
 
The delay calculator on PICLIST makes it easy
Here's a 24Hr delay.

Code:
; Delay = 86400 seconds
; Clock frequency = 4 MHz

; Actual delay = 86400 seconds = 86400000000 cycles
; Error = 0 %

	cblock
	d1
	d2
	d3
	d4
	d1_4
	endc

			;86399999992 cycles
	movlw	0x2D
	movwf	d1
	movlw	0xDB
	movwf	d2
	movlw	0x2B
	movwf	d3
	movlw	0xD5
	movwf	d4
	movlw	0x02
	movwf	d1_4
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	$+2
	decfsz	d4, f
	goto	$+2
	decfsz	d1_4, f
	goto	Delay_0

			;8 cycles
	goto	$+1
	goto	$+1
	goto	$+1
	goto	$+1
 
The problem with this is I don't know what the variables are they need to be under 256 since the PIC is a 8-bit only and therefore can only count up to 256
 
I'm still confused haha I know that looping a loop casues the whole thing to multiply by the outside so if I had one loop thats 256 and added another loop around that it would be 256 cycles times 256 cycles right ?
 
ok thanks Ive tried using the PICList before but what ends up happening on a 10 second delay I have the 10 second delay then it turns the pin to high then delay again then turn the pin low but it takes forever to turn it high over 30 seconds before I removed the power and just forgot about using the PICList code any help ?
 
Last edited:
where is the stopwatch function ? nvm found it Was wondering though anyway to make the code go any faster or do I have to wait it out ?
 
Last edited:
ok thanks Ive tried using the PICList before but what ends up happening on a 10 second delay I have the 10 second delay then it turns the pin to high then delay again then turn the pin low but it takes forever to turn it high over 30 seconds before I removed the power and just forgot about using the PICList code any help ?

The PICList generates perfect delay code for you - but you need to incorporate it in a program of your own, and do it correctly - it's dead simple. If it's not working, then you're doing something wrong - I presume you are aware that it doesn't produce a subroutine for you?, you need to make it one (assuming you want a subroutine of course).
 
ok so to put it into a subroutine just like everything all I need to do is this right ? then I would just call Delay like you normally would for a subroutine

Code:
; Delay = 86400 seconds
; Clock frequency = 4 MHz

; Actual delay = 86400 seconds = 86400000000 cycles
; Error = 0 %

			;86399999992 cycles
Delay
	movlw	0x2D
	movwf	d10
	movlw	0xDB
	movwf	d11
	movlw	0x2B
	movwf	d12
	movlw	0xD5
	movwf	d13
	movlw	0x02
	movwf	d14
	decfsz	d10, f
	goto	$+2
	decfsz	d11, f
	goto	$+2
	decfsz	d12, f
	goto	$+2
	decfsz	d13, f
	goto	$+2
	decfsz	d14, f
	goto	Delay_0

			;8 cycles
	goto	$+1
	goto	$+1
	goto	$+1
	goto	$+1
	retlw	0
 
Last edited:
Yes, that's pretty well all you need to do - bear in mind you obviously have the extra time involved in the call and return, so you may like to reduce the delay by 4uS (although it's hardly significant in such a long delay).
 
One point that seems to be forgotten is that the internal oscillator is factory calibrated only to an accuracy of +/- 1%, which amounts to about +/- 14 minutes over the course of a day. You may try to improve this by modifying the contents of OSSCAL, but I'm not sure what resolution can be obtained using the OSSCal register. I think in order to obtain better accuracy it will be necessary to tune the program by trial and error by varying the nominal time delay from 86400 seconds. The frequency of the internal oscillator will still vary with changing temperature, and an external crystal will be more stable. Of course, the crystal will takeup two pins of an already limited resource. Crystals typically have a stated accuracy of 50 ppm so it may be necessary to tune the program even when using a crystal.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top