pic te komut ile tam 1sn gecikme yapmak??

Başlatan ramsess, 09 Ekim 2005, 19:48:38

ramsess

beyler pic16f628 in içinde bulunan 4 Mhz lik dahili osilatörü kullanıp komutlarla (assemblly dilinde) tam 1sn lik gecikme nasıl yaparız. formülle falan cok acık bisekilde anlatırmısınız.

transistor

timer1 kullanarak  her 1 saniyede led yakıp söndüren program

	list 	p=16F628	; işlemciyi belirle
	include <p16f628.inc>	; başlık dosyasını yükle
SAYICI	equ	h'20'
LED 	equ	h'21'
        org 	0x000   	; reset veya ilk enerji verilmesi durumunda 
	goto	ANA_PROG	; ANA_PROG etiketine dallan
	org 	0x0004		; kesme geldiğinde
	goto 	KESME		; KESME etiketine dallan
ANA_PROG
       	clrf  	PORTB         ; portb'nin bütün uçlarını 0 yap
       	clrf  	SAYICI        ; SAYICI'yı sıfırla
       	bsf 	STATUS,5    ; bank 1'e geç
	bsf	pcon,oscf	  ; timer1 osc= dahili 4 mhz
	clrf	TRISB	  ; portb'nin bütün uçları çıkış
	bsf	PIE1,tmr1ie  ; TMR1'in kesme oluşturabilmesi için sıfırla
       	bcf  	STATUS,5    ; bank 0'a geç
	bsf	PORTB,0	  ; LED'i yak.
	bsf	LED,0	  ; LED'in durumunu tutan değişken
	movlw	h'F0'	 ; 
	movwf	TMR1L	 ; TMR1'in 10ms'de bir kesme üretmesi 
	movlw	h'D8'	 ; için TMR1H ve TMR1L saklayıcılarına
	movwf	TMR1H	 ; gerekli sayıyı yükle
	bsf	t1con,t1oscen	; osc aktif
	bsf	INTCON,gie	; kesmelere izin ver
	bsf	INTCON,peie	; çevresel kesmelere izin ver
	bsf	T1CON,tm1on	; Zamanlayıcı-1'i çalıştır 
BAS	goto 	BAS		; BAS'a dön.
KESME	movlw	h'F0'		; 
	movwf	TMR1L	; TMR1'in 10ms'de bir kesme üretmesi 
	movlw	h'D8'	; için TMR1H ve TMR1L saklayıcılarına
	movwf	TMR1H	; gerekli sayıyı yükle
	bcf	PIR1,0	; TMR1 kesmesini kullanmak için sıfırla
	incf	SAYICI,F	; 10ms daha geçti, sayacı 1 artır
	movlw	d'100'	; W=100
	subwf	SAYICI,W	; W=SAYICI-W
	btfss	STATUS,Z	; SAYICI=100 oldu mu?
	retfie		; henüz 1sn olmadı, ana programa dön
	clrf	SAYICI		; 10ms'lik sayacı sıfırla
	btfsc	LED,0		; LED yanıyormu?
	goto	SONDUR	; evet, o zaman söndürmeye git.
	bsf	PORTB,0		; hayır, o zaman LED'i yak
	bsf	LED,0		; LED'in yeni konumunu sakla
	retfie			; ana programa dön
SONDUR
	bcf	PORTB,0		; LED'i söndür
	bcf	LED,0		; LED'in yeni konumunu sakla
	retfie			; ana programa dön	
       	end			; program kodlarının sonu


dahili osilatör kullanılarak yapılan zamanlayıcı uygulamalarında hiçbir zaman tam 1 saniyeye ayarlama yapılamaz. bunun sebebi kullanılan dahili osilatörün ortam sıcaklık besleme gerilimine göre tam istenilen frekansta çalışmamasıdır.
16f628in datasheetinde belirtilen dahili osilatör kullanımlarındaki 37 khz ve 4 mhz 5v çalışma gerilimi ve 25C ortam sıcaklığında geçerlidir.
Herşey Vatan İçin.

Erol YILMAZ

@Ramsess;

1.000.000 uS yerine 1.020.000 uS'de 1 sn olarak kabul edilirse internal RC OSC 'de olur.

peko

The interruption time can be calculated by the following formula.
The interruption time = (4/OSC freq) x Prescaler x Hard timer count x Soft count

= 0.4 x 10-6 x 256 x 217 x 45

= 0.999936 seconds

Above-mentioned value is a value with few errors and little interruption time.
When using 4.19 MHz as the oscillator, the precision at the time of the hard timer count value=186, the soft timer count value=22 was the best and was to be in 1.000049642 seconds.
The actual circuit doesn't become as the calculation in the frequency precision of the oscillator and the relation of the soft processing after interruption. It is necessary to adjust after making.

The error when count-downed in 99 minutes with the equipment which I made was to be in -20 seconds(The timer is faster).
It becomes 0.003367 seconds when converting to the error in 1 second. Therefore, I did to the hard timer count value=213, the soft timer count value=46. The interruption time in this case is as follows. After adjusting a value, it became an error in 1 second within 99 minutes.
The interruption time = (4/OSC freq) x Prescaler x Hard timer count x Soft count

= 0.4 x 10-6 x 256 x 213 x 46

= 1.0033152 seconds

The set value of hard timer (TMR0) becomes the value which subtracted the count value to want for from 256.
256-213=43(2Bh)
" Bazıları zeka'sını iş'i zorlaştırmak için, bazıları ise kolaylaştırmak için kullanır.. "

sertac2003

GCK1SN		
	MOVLW	0x45
	MOVWF	SYC1_3;
D1_3		
	MOVLW	0x45
	MOVWF	SYC2_3;
D2_3		
	MOVLW	0x44
	MOVWF	SYC3_3;
D3_3		
	DECFSZ	SYC3_3,F
	GOTO	D3_3
	DECFSZ	SYC2_3,F
	GOTO	D2_3
	DECFSZ	SYC1_3,F
	GOTO	D1_3
	;---buraya gelindiginde 990565 komut saykili,
	;ve geriye 9435 ks kalır...
	MOVLW	0x37
	MOVWF	SYC1_2;
D1_2		
	MOVLW	0x37
	MOVWF	SYC2_2;
D2_2		
	DECFSZ	SYC2_2,F
	GOTO	D2_2
	DECFSZ	SYC1_2,F
	GOTO	D1_2
	;buraya gelindiginde 990565 + 9296 = 999861 komut ( uS ).	
	;ve geriye 139 komut saykili kaldi.
	MOVLW	0x2C
	MOVWF	SYC1_1;
D1_1		
	DECFSZ	SYC1_1,F
	GOTO	D1_1
	;burası ise 990565 + 9296 + 133 = 999994 uS
	NOP	;999995
	NOP	;999996
	RETURN	;999998
	;ve ana programda CALL dedik. +2 daha eklenir ve
	;toplamda 1000000 komut saykili...
	; call ve return dahil toplam 1 sn gck elde edilmis
	;olur...
	
	/*
	...
	...
	call	gck1sn	; PC
	...		; PC + 1000000
	...		; PC + 1000001
	.
	.
	.
	*/
Şirketteki herkes en üst yöneticinin müşterisidir.

Pyrodigy

Persistance is the name of the game in this business....