12f675 40 khz yardım..

Başlatan mas, 08 Temmuz 2012, 15:34:39

mas

merhaba arkadaşlar aşağıdaki kodu yanlızca 40 khz verecek şekilde editlemem gerekiyor. programdaki hangi satırları silmeliyim? şimdiden teşekkrler..

; Ultrasonic driver for anti fouling of boats


	ERRORLEVEL -302
	ERRORLEVEL -306

	list P=12F675
	#include P12F675.inc

;Program Configuration Register 
		__CONFIG    _CPD_OFF & _CP_OFF & _BODEN_OFF& _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _HS_OSC	

; bank 0 RAM 

STORE1			equ	H'22'	; delay counter	
STORE2			equ	H'23'	; delay counter
STORE3			equ	H'24'	; delay counter
FREQ_SET		equ	H'25'	; frequency set value
STATE			equ	H'26'	; push pull port output selector
CYCLE1			equ	H'27'	; cycle counter ms
CYCLE2			equ	H'28'	; cycle counter ls	
SWEEP_STEP		equ	H'29'	; sweep steps counter
SWEEP_BAND		equ	H'2A'	; sweep bands
DEAD_TIME		equ	H'2B'	; dead time counter	
GAP				equ	H'2C'	; gap flag
		
; ******************************************************************

; start at memory 0

	org		0			; reset vector
	goto	MAIN
	nop
	nop
	nop		; 
	org     4			; interrupt vector
	nop

; ***********************************************************************

;lookup table for frequency sweep including overlapping

SWEEP
	addwf	PCL,f		; add w to program counter
 
; 14 bands as per this table. Values are for timer 1 counter. Within each band are 
; 12 frequencies at 200ns apart. 									
; one sequence
	retlw	D'148'		; 19.08 to 20.0kHz ~83Hz spacing
	retlw	D'173'		; 23.58 to 25.00kHz
	retlw	D'158'		; 20.66 to 21.7kHz ~94Hz spacings
	retlw	D'168'		; 22.5 to 23.8kHz ~118Hz spacings
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'163'		; 21.55 to 22.7kHz
	retlw	D'208'		; 35.21 to 38.46kHz
	retlw	D'178'		; 24.75 to 26.31kHz ~141Hz spacings
	retlw	D'183'		; 26.04 to 27.77kHz
	retlw	D'153'		; 19.8 to 20.8kHz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'188'		; 27.47 to 29.41kHz ~175Hz spacings 
	retlw	D'193'		; 29.06 to 31.25kHz
	retlw	D'198'		; 30.86 to 33.33kHz ~224Hz
	retlw	D'203'		; 32.89 to 35.71kHz ~256Hz 
	retlw	D'208'		; 35.21 to 38.46kHz
; two sequence	
	retlw	D'188'		; 27.47 to 29.41kHz ~175Hz spacings 
	retlw	D'193'		; 29.06 to 31.25kHz
	retlw	D'198'		; 30.86 to 33.33kHz ~224Hz
	retlw	D'203'		; 32.89 to 35.71kHz ~256Hz 
	retlw	D'208'		; 35.21 to 38.46kHz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'168'		; 22.5 to 23.8kHz ~118Hz spacings
	retlw	D'173'		; 23.58 to 25.00kHz
	retlw	D'178'		; 24.75 to 26.31kHz ~141Hz spacings
	retlw	D'208'		; 35.21 to 38.46kHz
	retlw	D'183'		; 26.04 to 27.77kHz
	retlw	D'148'		; 19.08 to 20.0kHz ~83Hz spacing
	retlw	D'153'		; 19.8 to 20.8kHz
	retlw	D'158'		; 20.66 to 21.7kHz ~94Hz spacings
	retlw	D'163'		; 21.55 to 22.7kHz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
; Three sequence
	retlw	D'198'		; 30.86 to 33.33kHz ~224Hz
	retlw	D'203'		; 32.89 to 35.71kHz ~256Hz 
	retlw	D'148'		; 19.08 to 20.0kHz ~83Hz spacing
	retlw	D'183'		; 26.04 to 27.77kHz
	retlw	D'153'		; 19.8 to 20.8kHz
	retlw	D'208'		; 35.21 to 38.46kHz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'158'		; 20.66 to 21.7kHz ~94Hz spacings
	retlw	D'163'		; 21.55 to 22.7kHz
	retlw	D'173'		; 23.58 to 25.00kHz
	retlw	D'208'		; 35.21 to 38.46kHz
	retlw	D'168'		; 22.5 to 23.8kHz ~118Hz spacings
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'178'		; 24.75 to 26.31kHz ~141Hz spacings
	retlw	D'188'		; 27.47 to 29.41kHz ~175Hz spacings 
	retlw	D'193'		; 29.06 to 31.25kHz
; Four sequence
	retlw	D'158'		; 20.66 to 21.7kHz ~94Hz spacings
	retlw	D'163'		; 21.55 to 22.7kHz
	retlw	D'168'		; 22.5 to 23.8kHz ~118Hz spacings
	retlw	D'148'		; 19.08 to 20.0kHz ~83Hz spacing
	retlw	D'208'		; 35.21 to 38.46kHz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'183'		; 26.04 to 27.77kHz
	retlw	D'188'		; 27.47 to 29.41kHz ~175Hz spacings 
	retlw	D'193'		; 29.06 to 31.25kHz
	retlw	D'198'		; 30.86 to 33.33kHz ~224Hz
	retlw	D'173'		; 23.58 to 25.00kHz
	retlw	D'203'		; 32.89 to 35.71kHz ~256Hz 
	retlw	D'208'		; 35.21 to 38.46kHz
	retlw	D'153'		; 19.8 to 20.8kHz
	retlw	D'178'		; 24.75 to 26.31kHz ~141Hz spacings

MAIN
	bcf		STATUS,RP0	; select memory bank 0

; set inputs/outputs
	clrf	GPIO		; outputs low
	movlw	B'00000111'	; comparators off
	movwf	CMCON
	bsf		STATUS,RP0	; select memory bank 1
	movlw	B'00000000'	; pullups off
	movwf	WPU
	movlw	B'00101100'	; outputs/inputs set 
	movwf	TRISIO		; port data direction register
	movlw	B'10000000'	; settings (pullups disabled) 
	movwf	OPTION_REG

; analog inputs, A/D
	movlw	B'01100100'	; AN2 analog input 
	movwf	ANSEL
	bcf		STATUS,RP0	; select memory bank 0
	movlw	B'00001000'	; channel2 left justified, VDD ref etc
	movwf	ADCON0
	bsf		ADCON0,ADON	; A/D on
	clrf	T1CON
	bsf		T1CON,0		; timer 1 on
	bcf		PIR1,TMR1IF	; clear timer 1 overflow
	
TIME_0
	bcf		INTCON,T0IF

; initial conditions
	movlw	B'00000000'	; port low
	movwf	GPIO
	movlw	D'11'	
	movwf	SWEEP_STEP	; sweep step counter 
	movlw	D'63'
	movwf	SWEEP_BAND	; number of frequency bands	14, used bands 16 (2 repeated) 4 sequences

; start up delay ~2s
	movlw	D'70'		; delay extension
	movwf 	STORE3
DEL_CONT
	movlw	H'FF'		; delay routine
	call	DELAYX
	decfsz	STORE3,f	; when delay extension is 0 exit
	goto	DEL_CONT

	bcf		PIR1,TMR1IF	; timer 1 interrupt flag clear

; measure battery Voltage. No drive if below 11.5V
; channel 2 
BATT
	call	ACQUIRE_AD
	movf	ADRESH,w	; look at value 11.5V = 3.83V and D195
	sublw	D'195'		; if negative then drive ok
	btfss	STATUS,C
	goto	DRIVE
NO_DRV
	bcf		GPIO,GP0
	bcf		GPIO,GP1	; ensure drive is off
	call	DELAYms
	call	ACQUIRE_AD
	movf	ADRESH,w	; look at value 12V = 4V and D204
	sublw	D'204'		; if negative then drive ok
	btfsc	STATUS,C
	goto	NO_DRV		; no output when battery low

DRIVE

; sweep cycle
	incf	SWEEP_BAND,f; frequency band
	movf	SWEEP_BAND,w
	sublw	D'63'		; 14 bands plus two duplicated and 4 sequences
	btfsc	STATUS,C
	goto	IN_SWEEP
; if > set at 0 again
	clrf	SWEEP_BAND
IN_SWEEP
	movf	SWEEP_BAND,w
	call	SWEEP		; lookup value (sweep is frequency range for each burst)
; Total frequency range 
	movwf	FREQ_SET	; frequency set value

; Set cycle counter for number of cycles delivered per tone burst
	movlw	H'3'		; D1000 
	movwf	CYCLE1
	movlw	H'E8'
	movwf	CYCLE2

DUTY ; duty period

	bcf		PIR1,TMR1IF	; clear flag
; check pulse counters
	decf	CYCLE2,f
	movf	CYCLE2,f 	; check ls
	btfsc	STATUS,Z	; if zero decrease ms byte
	decfsz	CYCLE1,f	; if zero end of cycles
	goto	OUT_DRV		; output driver

; check sweep steps 
	movf	SWEEP_STEP,w
	btfsc	STATUS,Z	; when zero end of bursts
	goto	END_BURST	; end of cycle burst

; Set cycle counter for number of cycles delivered per tone burst
	movlw	H'3'		; 
	movwf	CYCLE1
	movlw	H'E8'
	movwf	CYCLE2
; count down sweep steps 
	decf	SWEEP_STEP,f; next frequency 
	goto	OUT_DRV		; output driver

; end of cycle burst period
END_BURST
	movlw	D'11'		; 
	movwf	SWEEP_STEP	; reset sweep step value
; cycle till end of frequency half period
WAIT1
	btfss	PIR1,TMR1IF	; timer flag
	goto	WAIT1
; cycle loop

	clrf	GPIO		; driver cleared
;
; Alternate gap or next burst
	incf	GAP,f
	btfss	GAP,0
	goto	DRIVE
					
; end of cycle burst
	movlw	D'20'		; D20 delay extension
	movwf 	STORE3
DEL_CONT1
	movlw	H'FF'		; delay routine
	call	DELAYX
	decfsz	STORE3,f	; when delay extension is 0 exit
	goto	DEL_CONT1
	goto	BATT

CHK_COUNT; divide into steps for a frequency sweep

; output driver
OUT_DRV
	incf	STATE,f		; toggle output selector for GP0 or GP1 using bit 0

;**** following 14 instructions must not cross page boundary **** 
; Check addresses in listing file.

INCREMENT
	movf	SWEEP_STEP,w; allows 200ns changes to frequency
	addwf	PCL,f
	goto	ONE
	goto	TWO
	goto	THREE
	goto	FOUR
	goto	FIVE
	goto	SIX
	goto	SEVEN
	goto	EIGHT
	goto	NINE
	goto	TEN
	goto	ELEVEN
	goto	TWELVE
; ** end of page boundary restriction
TWELVE
	btfss	PIR1,TMR1IF	; timer flag
	goto	TWELVE
	nop
	nop
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET12
	nop					; extra frequency adjust
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET12
; end of dead time
	goto	RESET_TIMER1
ELEVEN
	btfss	PIR1,TMR1IF	; timer flag
	goto	ELEVEN
	nop
	nop
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET11
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET11
; end of dead time
	goto	RESET_TIMER1
TEN
	btfss	PIR1,TMR1IF	; timer flag
	goto	TEN
	nop
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET10
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET10
	nop					; extra frequency adjust
; end of dead time
	goto	RESET_TIMER1
NINE
	btfss	PIR1,TMR1IF	; timer flag
	goto	NINE
	nop
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET9
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET9
; end of dead time
	goto	RESET_TIMER1
EIGHT
	btfss	PIR1,TMR1IF	; timer flag
	goto	EIGHT
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET8
	nop
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET8
; end of dead time
	goto	RESET_TIMER1
SEVEN
	btfss	PIR1,TMR1IF	; timer flag
	goto	SEVEN
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET7
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET7
; end of dead time
	goto	RESET_TIMER1
SIX
	btfss	PIR1,TMR1IF	; timer flag
	goto	SIX
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET6
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET6
	nop					; extra frequency adjust
	goto	RESET_TIMER1
FIVE
	btfss	PIR1,TMR1IF	; timer flag
	goto	FIVE
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET5
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET5
; end of dead time
	goto	RESET_TIMER1

FOUR
	btfss	PIR1,TMR1IF	; timer flag
	goto	FOUR
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET4
	nop					; extra frequency adjust
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET4
; end of dead time
	goto	RESET_TIMER1

THREE
	btfss	PIR1,TMR1IF	; timer flag
	goto	THREE
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET3
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET3
; end of dead time
	goto	RESET_TIMER1

TWO
	btfss	PIR1,TMR1IF	; timer flag
	goto	TWO
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET2
	nop					; equalise dead time
; end of dead time

	goto	RESET_TIMER0
SET2
	nop					; extra frequency adjust
; end of dead time
	goto	RESET_TIMER1 ;  

ONE	btfss	PIR1,TMR1IF	; timer flag
	goto	ONE
	clrf	GPIO		; driver cleared after wait period
; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET1
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET1
; end of dead time
	goto	RESET_TIMER1	; (required instruction for cycle timing)

; reset timer
RESET_TIMER0
	
	comf	TMR1H,f		; ms byte set
	movf	FREQ_SET,w	; ls byte set
	bcf		T1CON,0		; timer 1 off
	movwf	TMR1L
	bsf		T1CON,0		; timer 1 on
; add extra dead time
	movlw	D'5'
	movwf	DEAD_TIME
DEC_DEAD1
	decfsz	DEAD_TIME,f
	goto	DEC_DEAD1
	bsf		GPIO,GP0	; set 0 output 
	goto	DUTY

; reset timer
RESET_TIMER1
	
	comf	TMR1H,f		; ms byte set
	movf	FREQ_SET,w	; ls byte set
	bcf		T1CON,0		; timer 1 off
	movwf	TMR1L
	bsf		T1CON,0		; timer 1 on
; add extra dead time
	movlw	D'5'
	movwf	DEAD_TIME
DEC_DEAD2
	decfsz	DEAD_TIME,f
	goto	DEC_DEAD2
	bsf		GPIO,GP1	; set 1 output 
	goto	DUTY

 ; ***************************************************************************	

; Subroutines

; delay loop 

DELAYms
	movlw	D'23'		; delay value
DELAYX
	movwf	STORE1		; STORE1 is number of loops value
LOOP8	
	movlw	H'B0'
DELDSP
	movwf	STORE2		; STORE2 is internal loop value	
LOOP9
	decfsz	STORE2,f
	goto	LOOP9
	decfsz	STORE1,f
	goto	LOOP8
	return

; subroutine to wait for A/D conversion
ACQUIRE_AD
	bsf		ADCON0,GO_DONE	; GO/DONE bit start conversion
WAIT_CONV
	btfsc	ADCON0,GO_DONE	; conversion complete when cleared ~11 cycles
	goto	WAIT_CONV
	return



	end

bulut_01

bu kod ne işe yarıyor ilginc bir code benziyor. bunu 40 khz cevırmek yerıne yenıden yazmak daha mantıklı gibi
YENİLMEZ..

mas

bu kod ultrasonik yosun temizleme cihazını kontrol ediyor. kçük teknelerin şasesine bağlanan bir piezo transdüser i çalıştırıyor. arada trafo vs var. bir çok frekansta sinyaller üreterek küçük deniz canlılarının teknenin alt yüzeyine tutunmasını engelliyor. çalışma frekanslarının içinde 40khz de var. benim yapmak istediğim diğer frekansları silip sadece 40 khz civarında sinyal almak. programı jal ile yeniden yazmayı denedim. yazdığım flip flop programında 1mikrosaniyenin altına inemediğimden transdüseri sürmek için gerekli gücü ve sinyali elde edemedim. kısaca a0 ve a1 nolu pinlerden 40 khz lik sinyal verecek bir program gerekiyor. assembly den anlamıyorum. orjinal program da besleme hattındaki voltajı ölçmek için adc kullanılmış. buna gerek yok. basit bir flip flop programı işimi fazlasıyla görür. ilgilenenler için kaynak site

https://320volt.com/tekneler-icin-koruyucu-ultrasonik-anti-fouling-devresi/


bulut_01

SANA ıkı port 40 khz lazımsa sadece basıt bır kod yazılabılır.
YENİLMEZ..

mas

evet işte ben de öyle yaptım ama kullandığım dil buna izin vermiyor. dediğim gibi assembly veya c den anlamıyorum. yazdığım program aşağıda. bu programla devreyi çalıştırdığımda hem trafo hem de transdüser yüksek bir sesle ötüyor. cihaz işlevini yapmıyor.. program konusunda yardımlarınızı bekliyorum. teşekkürler

include 12f675_20
include jlib

pin_a0_direction = output
pin_a1_direction = output

forever loop
pin_a0 = high
pin_a1 = low
delay_1us ( 1 )
pin_a0 = low
pin_a1 = high
delay_1us ( 1 )
end loop

OG

40KHz = 25uSn
1 periyot = 12,5usn

20MHz çalışırken 1 komut 0,2uSn

1 NOP = 0,2us
1 GoTo $+1 = 0,4usn

GPIO.0=0
GPIO.1=0

------
Basla:
GPIO.0=1  ' 0,2 usn
GoTo $+1  ' 0,6 usn
GoTo $+1  ' 1,0 usn
GoTo $+1  ' 1,4 usn
GoTo $+1  ' 1,8 usn
GoTo $+1  ' 2,2 usn 
GoTo $+1  ' 2,6 usn
GoTo $+1  ' 3,0 usn
GoTo $+1  ' 3,4 usn
GoTo $+1  ' 3,8 usn
GoTo $+1  ' 4,2 usn
GoTo $+1  ' 4,6 usn
GoTo $+1  ' 5,0 usn
GoTo $+1  ' 5,4 usn
GoTo $+1  ' 5,8 usn
GoTo $+1  ' 6,2 usn
GoTo $+1  ' 6,6 usn
GoTo $+1  ' 7,0 usn
GoTo $+1  ' 7,4 usn
GoTo $+1  ' 7,8 usn
GoTo $+1  ' 8,2 usn
GoTo $+1  ' 8,6 usn
GoTo $+1  ' 9,0 usn
GoTo $+1  ' 9,4 usn
GoTo $+1  ' 9,8 usn
GoTo $+1  ' 10,2 usn
GoTo $+1  ' 10,6 usn
GoTo $+1  ' 11,0 usn
GoTo $+1  ' 11,4 usn
GoTo $+1  ' 11,8 usn
GoTo $+1  ' 12,2 usn
GPIO.0=0  ' 12,4 usn
GPIO.1=1  ' 12,6 usn
GoTo $+1  ' 13,0 usn
GoTo $+1  ' 13,4 usn
GoTo $+1  ' 13,8 usn
GoTo $+1  ' 14,2 usn
GoTo $+1  ' 14,6 usn
GoTo $+1  ' 15,0 usn
GoTo $+1  ' 15,4 usn
GoTo $+1  ' 15,8 usn
GoTo $+1  ' 16,2 usn
GoTo $+1  ' 16,6 usn
GoTo $+1  ' 17,0 usn
GoTo $+1  ' 17,4 usn
GoTo $+1  ' 17,8 usn
GoTo $+1  ' 18,2 usn
GoTo $+1  ' 18,6 usn
GoTo $+1  ' 19,0 usn
GoTo $+1  ' 19,4 usn
GoTo $+1  ' 19,8 usn
GoTo $+1  ' 20,2 usn
GoTo $+1  ' 20,6 usn
GoTo $+1  ' 21,0 usn
GoTo $+1  ' 21,4 usn
GoTo $+1  ' 21,8 usn
GoTo $+1  ' 22,2 usn
GoTo $+1  ' 22,6 usn
GoTo $+1  ' 23,0 usn
GoTo $+1  ' 23,4 usn
GoTo $+1  ' 23,8 usn
GoTo $+1  ' 24,2 usn
GoTo $+1  ' 24,6 usn
nop           ' 24,8 usn
GPIO.1=0  ' 25,0 usn
Goto Basla' 25,2 usn
FORUMU İLGİLENDİREN KONULARA ÖM İLE CEVAP VERİLMEZ.

mas

hocam çok teşekkürler emek vermişsin. dediğiniz 25us olayını yazdığım programda denedim. durum yine aynı. transdüser ve trafo ötüyor. acaba ben mi yanlış birşeyler yapıyorum? transdüseri sürmek için 40 khz den fazlasımı grekli? yukarıdaki programda transdüser sürmek için tam olarak ne yapılmış açıklayabilirmisiniz rica etsem? teşekkürler..

OG

Trafo deyince sorun başlar, nispeten zor iştir, bu sebeple smps işleri zordur. Uzmanlık ister, iyi bilgi ister, iyi ölçüm cihazları ister.
FORUMU İLGİLENDİREN KONULARA ÖM İLE CEVAP VERİLMEZ.

mas

hocam aslında buradaki trafo basit birşey. smps ile bir ilgisi yok. programın nasıl çalıştığını tam olarak anlayabilsem uygun zamanlamayı yapıcam. orjinal programın bir bölmünde piezo tam istediğim sinyali veriyor. ama piezo yu sürmek için ne yapmam gerektiğini hala tam olarak anlayamadım..

mozkan87

Trafonun SMPS trafosu ile aynı özellikleri taşıması lazım çünki frekans 40 kHz. O nedenle trafonun nüvesininde uygun olması lazım.

OG

40KHz üretmek basit iş. Gerisi önemli.
mozkan87 yazmış, ayrıca piezo kapasitif yük, trafo ile uyumlu olmalı. Güç, endüktans, frekans, kapasite, voltaj, periyot aktif süresi vs vs. İş beni aşıyor. Belki deneme yanılma.
FORUMU İLGİLENDİREN KONULARA ÖM İLE CEVAP VERİLMEZ.

mozkan87

Eğer size tek frekans yeterli ise yapın bir 555 devresi, çıkışada iki çıkış elde etmek için bir tane not kapısı koyarsınız ve istediğinizi elde edersiniz. Ancak sizin verdiğiniz kodlara bir göz attım, hem timer0 hem timer1 kullanılmış, anladığım kadarıyla mosfetlerin ikisininde ON konumda ve OFF konumda olduğu durumlar var eğer birebir aynı yapmak istiyorsanızi mosfeti süren pinlerin durumunu logic analizör ile kaydedip inceleyin.

mas

trafo etd29. sarımı yukarıda verdiğim linkde anlatılıyor. programdan anladığım kadarıyla frekans tanımlamaları yapılmış ana program bunları sırasıyla uyguluyor. eğer tanımlanan frekanslar çinden 40khz dışındakileri silersem sorun çözülecek gibi. tabi ana programda da değişiklik yapmak gerekecek.derlemek için mpasm yi mi kullanmalıyım? assembly için de farklı derleyiciler varmıdır veya bu program hangi platformda yazılmış olabilir?

sadece frekans sanırım yetmiyor. kend yazdığım programda 40 khz lik sinyal ürettim ama ultrasonik etkiyi yakalayamadım. farklı bir program yazdım, sonuç yine değişmedi..

include 12f675_20
include jlib

pin_a0_direction = output
pin_a1_direction = output

forever loop
for 100 loop
pin_a0 = high
pin_a1 = low
delay_1us ( 10 )
pin_a0 = low
pin_a1 = high
delay_1us ( 10 )
end loop
delay_1us ( 25 )
end loop

z

Transducer'i yüzlerce volt genlikle sürüp yüksek akımlar akıtman gerekir.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

mas

#14
Bülent hocam bilgi için teşekkür ederim. bildiğim kadarıyla siz assembly den anlıyordunuz. yukarıdaki programın hangi satırını silersem 40 khz de sabit kalır acaba? veya o programla bunu yapmam mümkün mü?

mesaj birleştirme:: 09 Temmuz 2012, 20:53:29

yokmu arkadaşlar assembly den anlayan?

mesaj birleştirme:: 10 Temmuz 2012, 00:16:56

kodu biraz değiştirerek istediğim frekansda çalışmasını sağladım. şimdiki sorun vuruşlar arasındaki süre çok uzun. her defasında 2 kez sinyal veriyor yaklaşık yarım saniyede bir bunu tekrarlıyor. ben aradaki boşlukların tamamını silmek istiyorum. yeni kod aşağıda. tanımlanan frekansların hepsine D213 yazdım.

; Ultrasonic driver for anti fouling of boats


	ERRORLEVEL -302
	ERRORLEVEL -306

	list P=12F675
	#include P12F675.inc

;Program Configuration Register 
		__CONFIG    _CPD_OFF & _CP_OFF & _BODEN_OFF& _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _HS_OSC	

; bank 0 RAM 

STORE1			equ	H'22'	; delay counter	
STORE2			equ	H'23'	; delay counter
STORE3			equ	H'24'	; delay counter
FREQ_SET		equ	H'25'	; frequency set value
STATE			equ	H'26'	; push pull port output selector
CYCLE1			equ	H'27'	; cycle counter ms
CYCLE2			equ	H'28'	; cycle counter ls	
SWEEP_STEP		equ	H'29'	; sweep steps counter
SWEEP_BAND		equ	H'2A'	; sweep bands
DEAD_TIME		equ	H'2B'	; dead time counter	
GAP				equ	H'2C'	; gap flag
		
; ******************************************************************

; start at memory 0

	org		0			; reset vector
	goto	MAIN
	nop
	nop
	nop		; 
	org     4			; interrupt vector
	nop

; ***********************************************************************

;lookup table for frequency sweep including overlapping

SWEEP
	addwf	PCL,f		; add w to program counter
 
; 14 bands as per this table. Values are for timer 1 counter. Within each band are 
; 12 frequencies at 200ns apart. 									
; one sequence
	retlw	D'213'		; 20.66 to 21.7kHz ~94Hz spacings
	retlw	D'213'		; 21.55 to 22.7kHz
	retlw	D'213'		; 22.5 to 23.8kHz ~118Hz spacings
	retlw	D'213'		; 19.08 to 20.0kHz ~83Hz spacing
	retlw	D'213'		; 35.21 to 38.46kHz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'213'		; 26.04 to 27.77kHz
	retlw	D'213'		; 27.47 to 29.41kHz ~175Hz spacings 
	retlw	D'213'		; 29.06 to 31.25kHz
	retlw	D'213'		; 30.86 to 33.33kHz ~224Hz
	retlw	D'213'		; 23.58 to 25.00kHz
	retlw	D'213'		; 32.89 to 35.71kHz ~256Hz 
	retlw	D'213'		; 35.21 to 38.46kHz
	retlw	D'213'		; 19.8 to 20.8kHz
	retlw	D'213'		; 24.75 to 26.31kHz ~141Hz spacings
; two sequence	
	retlw	D'213'		; 20.66 to 21.7kHz ~94Hz spacings
	retlw	D'213'		; 21.55 to 22.7kHz
	retlw	D'213'		; 22.5 to 23.8kHz ~118Hz spacings
	retlw	D'213'		; 19.08 to 20.0kHz ~83Hz spacing
	retlw	D'213'		; 35.21 to 38.46kHz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'213'		; 26.04 to 27.77kHz
	retlw	D'213'		; 27.47 to 29.41kHz ~175Hz spacings 
	retlw	D'213'		; 29.06 to 31.25kHz
	retlw	D'213'		; 30.86 to 33.33kHz ~224Hz
	retlw	D'213'		; 23.58 to 25.00kHz
	retlw	D'213'		; 32.89 to 35.71kHz ~256Hz 
	retlw	D'213'		; 35.21 to 38.46kHz
	retlw	D'213'		; 19.8 to 20.8kHz
	retlw	D'213'		; 24.75 to 26.31kHz ~141Hz spacings
; Three sequence
	retlw	D'213'		; 20.66 to 21.7kHz ~94Hz spacings
	retlw	D'213'		; 21.55 to 22.7kHz
	retlw	D'213'		; 22.5 to 23.8kHz ~118Hz spacings
	retlw	D'213'		; 19.08 to 20.0kHz ~83Hz spacing
	retlw	D'213'		; 35.21 to 38.46kHz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'213'		; 26.04 to 27.77kHz
	retlw	D'213'		; 27.47 to 29.41kHz ~175Hz spacings 
	retlw	D'213'		; 29.06 to 31.25kHz
	retlw	D'213'		; 30.86 to 33.33kHz ~224Hz
	retlw	D'213'		; 23.58 to 25.00kHz
	retlw	D'213'		; 32.89 to 35.71kHz ~256Hz 
	retlw	D'213'		; 35.21 to 38.46kHz
	retlw	D'213'		; 19.8 to 20.8kHz
	retlw	D'213'		; 24.75 to 26.31kHz ~141Hz spacings
; Four sequence
	retlw	D'213'		; 20.66 to 21.7kHz ~94Hz spacings
	retlw	D'213'		; 21.55 to 22.7kHz
	retlw	D'213'		; 22.5 to 23.8kHz ~118Hz spacings
	retlw	D'213'		; 19.08 to 20.0kHz ~83Hz spacing
	retlw	D'213'		; 35.21 to 38.46kHz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz
	retlw	D'213'		; 37.87 to 41.66kHz ~344Hz 
	retlw	D'213'		; 26.04 to 27.77kHz
	retlw	D'213'		; 27.47 to 29.41kHz ~175Hz spacings 
	retlw	D'213'		; 29.06 to 31.25kHz
	retlw	D'213'		; 30.86 to 33.33kHz ~224Hz
	retlw	D'213'		; 23.58 to 25.00kHz
	retlw	D'213'		; 32.89 to 35.71kHz ~256Hz 
	retlw	D'213'		; 35.21 to 38.46kHz
	retlw	D'213'		; 19.8 to 20.8kHz
	retlw	D'213'		; 24.75 to 26.31kHz ~141Hz spacings

MAIN
	bcf		STATUS,RP0	; select memory bank 0

; set inputs/outputs
	clrf	GPIO		; outputs low
	movlw	B'00000111'	; comparators off
	movwf	CMCON
	bsf		STATUS,RP0	; select memory bank 1
	movlw	B'00000000'	; pullups off
	movwf	WPU
	movlw	B'00101100'	; outputs/inputs set 
	movwf	TRISIO		; port data direction register
	movlw	B'10000000'	; settings (pullups disabled) 
	movwf	OPTION_REG

; analog inputs, A/D
	movlw	B'01100100'	; AN2 analog input 
	movwf	ANSEL
	bcf		STATUS,RP0	; select memory bank 0
	movlw	B'00001000'	; channel2 left justified, VDD ref etc
	movwf	ADCON0
	bsf		ADCON0,ADON	; A/D on
	clrf	T1CON
	bsf		T1CON,0		; timer 1 on
	bcf		PIR1,TMR1IF	; clear timer 1 overflow
	
TIME_0
	bcf		INTCON,T0IF

; initial conditions
	movlw	B'00000000'	; port low
	movwf	GPIO
	movlw	D'11'	
	movwf	SWEEP_STEP	; sweep step counter 
	movlw	D'63'
	movwf	SWEEP_BAND	; number of frequency bands	14, used bands 16 (2 repeated) 4 sequences

DEL_CONT
	movlw	H'FF'		; delay routine
	call	DELAYX
	decfsz	STORE3,f	; when delay extension is 0 exit
	goto	DEL_CONT

	bcf		PIR1,TMR1IF	; timer 1 interrupt flag clear

; measure battery Voltage. No drive if below 11.5V
; channel 2 
BATT
	call	ACQUIRE_AD
	movf	ADRESH,w	; look at value 11.5V = 3.83V and D195
	sublw	D'195'		; if negative then drive ok
	btfss	STATUS,C
	goto	DRIVE
NO_DRV
	bcf		GPIO,GP0
	bcf		GPIO,GP1	; ensure drive is off
	call	DELAYms
	call	ACQUIRE_AD
	movf	ADRESH,w	; look at value 12V = 4V and D204
	sublw	D'204'		; if negative then drive ok
	btfsc	STATUS,C
	goto	NO_DRV		; no output when battery low

DRIVE

; sweep cycle
	incf	SWEEP_BAND,f; frequency band
	movf	SWEEP_BAND,w
	sublw	D'01'		; 14 bands plus two duplicated and 4 sequences
	btfsc	STATUS,C
	goto	IN_SWEEP
; if > set at 0 again
	clrf	SWEEP_BAND
IN_SWEEP
	movf	SWEEP_BAND,w
	call	SWEEP		; lookup value (sweep is frequency range for each burst)
; Total frequency range 
	movwf	FREQ_SET	; frequency set value

; Set cycle counter for number of cycles delivered per tone burst
	movlw	H'3'		; D1000 
	movwf	CYCLE1
	movlw	H'E8'
	movwf	CYCLE2

DUTY ; duty period

	bcf		PIR1,TMR1IF	; clear flag
; check pulse counters
	decf	CYCLE2,f
	movf	CYCLE2,f 	; check ls
	btfsc	STATUS,Z	; if zero decrease ms byte
	decfsz	CYCLE1,f	; if zero end of cycles
	goto	OUT_DRV		; output driver

; check sweep steps 
	movf	SWEEP_STEP,w
	btfsc	STATUS,Z	; when zero end of bursts
	goto	END_BURST	; end of cycle burst

; Set cycle counter for number of cycles delivered per tone burst
	movlw	H'3'		; 
	movwf	CYCLE1
	movlw	H'E8'
	movwf	CYCLE2
; count down sweep steps 
	decf	SWEEP_STEP,f; next frequency 
	goto	OUT_DRV		; output driver

; end of cycle burst period
END_BURST
	movlw	D'11'		; 
	movwf	SWEEP_STEP	; reset sweep step value
; cycle till end of frequency half period
WAIT1
	btfss	PIR1,TMR1IF	; timer flag
	goto	WAIT1
; cycle loop

	clrf	GPIO		; driver cleared
;
; Alternate gap or next burst
	incf	GAP,f
	btfss	GAP,0
	goto	DRIVE
					
; end of cycle burst
	movlw	D'20'		; D20 delay extension
	movwf 	STORE3
DEL_CONT1
	movlw	H'FF'		; delay routine
	call	DELAYX
	decfsz	STORE3,f	; when delay extension is 0 exit
	goto	DEL_CONT1
	goto	BATT

CHK_COUNT; divide into steps for a frequency sweep

; output driver
OUT_DRV
	incf	STATE,f		; toggle output selector for GP0 or GP1 using bit 0

;**** following 14 instructions must not cross page boundary **** 
; Check addresses in listing file.

INCREMENT
	movf	SWEEP_STEP,w; allows 200ns changes to frequency
	addwf	PCL,f
	goto	ONE
	goto	TWO
	goto	THREE
	goto	FOUR
	goto	FIVE
	goto	SIX
	goto	SEVEN
	goto	EIGHT
	goto	NINE
	goto	TEN
	goto	ELEVEN
	goto	TWELVE
; ** end of page boundary restriction
TWELVE
	btfss	PIR1,TMR1IF	; timer flag
	goto	TWELVE
	nop
	nop
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET12
	nop					; extra frequency adjust
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET12
; end of dead time
	goto	RESET_TIMER1
ELEVEN
	btfss	PIR1,TMR1IF	; timer flag
	goto	ELEVEN
	nop
	nop
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET11
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET11
; end of dead time
	goto	RESET_TIMER1
TEN
	btfss	PIR1,TMR1IF	; timer flag
	goto	TEN
	nop
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET10
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET10
	nop					; extra frequency adjust
; end of dead time
	goto	RESET_TIMER1
NINE
	btfss	PIR1,TMR1IF	; timer flag
	goto	NINE
	nop
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET9
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET9
; end of dead time
	goto	RESET_TIMER1
EIGHT
	btfss	PIR1,TMR1IF	; timer flag
	goto	EIGHT
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET8
	nop
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET8
; end of dead time
	goto	RESET_TIMER1
SEVEN
	btfss	PIR1,TMR1IF	; timer flag
	goto	SEVEN
	nop
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET7
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET7
; end of dead time
	goto	RESET_TIMER1
SIX
	btfss	PIR1,TMR1IF	; timer flag
	goto	SIX
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET6
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET6
	nop					; extra frequency adjust
	goto	RESET_TIMER1
FIVE
	btfss	PIR1,TMR1IF	; timer flag
	goto	FIVE
	nop
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET5
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET5
; end of dead time
	goto	RESET_TIMER1

FOUR
	btfss	PIR1,TMR1IF	; timer flag
	goto	FOUR
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET4
	nop					; extra frequency adjust
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET4
; end of dead time
	goto	RESET_TIMER1

THREE
	btfss	PIR1,TMR1IF	; timer flag
	goto	THREE
	nop
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET3
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET3
; end of dead time
	goto	RESET_TIMER1

TWO
	btfss	PIR1,TMR1IF	; timer flag
	goto	TWO
	clrf	GPIO		; driver cleared after wait period
	; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET2
	nop					; equalise dead time
; end of dead time

	goto	RESET_TIMER0
SET2
	nop					; extra frequency adjust
; end of dead time
	goto	RESET_TIMER1 ;  

ONE	btfss	PIR1,TMR1IF	; timer flag
	goto	ONE
	clrf	GPIO		; driver cleared after wait period
; add 'nop's for extra dead period
; set output	
	btfsc	STATE,0		; if 0 was set set 1
	goto	SET1
	nop					; equalise dead time
; end of dead time
	goto	RESET_TIMER0
SET1
; end of dead time
	goto	RESET_TIMER1	; (required instruction for cycle timing)

; reset timer
RESET_TIMER0
	
	comf	TMR1H,f		; ms byte set
	movf	FREQ_SET,w	; ls byte set
	bcf		T1CON,0		; timer 1 off
	movwf	TMR1L
	bsf		T1CON,0		; timer 1 on
; add extra dead time
	movlw	D'5'
	movwf	DEAD_TIME
DEC_DEAD1
	decfsz	DEAD_TIME,f
	goto	DEC_DEAD1
	bsf		GPIO,GP0	; set 0 output 
	goto	DUTY

; reset timer
RESET_TIMER1
	
	comf	TMR1H,f		; ms byte set
	movf	FREQ_SET,w	; ls byte set
	bcf		T1CON,0		; timer 1 off
	movwf	TMR1L
	bsf		T1CON,0		; timer 1 on
; add extra dead time
	movlw	D'5'
	movwf	DEAD_TIME
DEC_DEAD2
	decfsz	DEAD_TIME,f
	goto	DEC_DEAD2
	bsf		GPIO,GP1	; set 1 output 
	goto	DUTY

 ; ***************************************************************************	

; Subroutines

; delay loop 

DELAYms
	movlw	D'23'		; delay value
DELAYX
	movwf	STORE1		; STORE1 is number of loops value
LOOP8	
	movlw	H'B0'
DELDSP
	movwf	STORE2		; STORE2 is internal loop value	
LOOP9
	decfsz	STORE2,f
	goto	LOOP9
	decfsz	STORE1,f
	goto	LOOP8
	return

; subroutine to wait for A/D conversion
ACQUIRE_AD
	bsf		ADCON0,GO_DONE	; GO/DONE bit start conversion
WAIT_CONV
	btfsc	ADCON0,GO_DONE	; conversion complete when cleared ~11 cycles
	goto	WAIT_CONV
	return



	end