Pic 16f628a ile pwm üretme 36 khz ve 38 khz

Katılım
21 Kas 2011
Mesajlar
45
Puanları
1
Ben ir ledi 36 khz de ve 38 khz de süren iki program yapmaya çalıştım picbasicpro da yapamadım bu 36 - 38 khz nasıl üretiliyor.Devrem de ki kristal 4 mhz acaba bu mu sorun.Heralde 4 mhz yetmiyormuş 38 khz için 40 mhz lik kristal lazımmış bu doğru mu?:confused:
 
Elinizdeki pic muhtemelen 40 Mhz kristali desteklemez, zaten 38 Khz için de 10 mips çok abartılı bir hız olur, sonuçta karedalga üreteceksiniz.
Kodunuzu buraya eklerseniz yardımcı olunabilir.
 
PWM kristal frekansını bölerek çıkış verir.
PWM de 4Mhz kristal için; 4te biri yani 1milyon saykılın vardır. Bunu pwmde tam sayıya bölebilirsin.. Aşağıda 27 ve 28 değerleri için frekansları yazdım..

1.000.000 / 27 = 37.037,04 Hz
1.000.000 / 28 = 35.714,29 Hz

Gördüğün üzere tam 36 Khz elde edemezsin.. Size bahseden kimse bunu demiştir.. Bu frekansları alan cihazın toleransı önemli aslında.. Eğer 36khz deki toleransı +-0,3 khz vs ise 35,7 khz i algılar, çalışır..

Frekans çok daha hassas olsun dersen, 36khz in katı kristal kullanmalısın..
 
Ben ir ledi 36 khz de ve 38 khz de süren iki program yapmaya çalıştım picbasicpro da yapamadım bu 36 - 38 khz nasıl üretiliyor.Devrem de ki kristal 4 mhz acaba bu mu sorun.Heralde 4 mhz yetmiyormuş 38 khz için 40 mhz lik kristal lazımmış bu doğru mu?:confused:


ir ledmi süreceksiniz? eğer öyleyse 38-40khz üretmeniz gerekir. pic içerisinde donanımsal olarak bir ccp var ise burdan 4mhz ile rahatça üretirsiniz. yoksa soft olarak yapılması gerekir.
 
ir ledmi süreceksiniz? eğer öyleyse 38-40khz üretmeniz gerekir. pic içerisinde donanımsal olarak bir ccp var ise burdan 4mhz ile rahatça üretirsiniz. yoksa soft olarak yapılması gerekir.
Sayın;@MAIN_LOOP,bİldiğim kadarıyla 16f628'de bu port yok.Pwm yapılamaz. Yanılıyorsam özür..

12f683 için;



; CLOCK: Internal RC 4MHz (instruction execution time: 1usec)
;
; NOTE: PWM used for LED fade in/out. Positive sides locked to
; HI via 150-ohm resistors, while gnd side of LEDs is
; driven by a varying active-low PWM signal.
;
;==================================================================================
list P=12F683, ST=OFF ; Turnoff Symbol Table in List file.

errorlevel -302 ; Ignore error message when storing to Bank 1.
;==================================================================================

#include <p12f683.inc>

__config _INTOSCIO & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOD_NSLEEP & _IESO_OFF & _FCMEN_OFF

; ------------------------------------
; Configuration Bit Settings Explained
; ------------------------------------
; Internal RC Oscillator, No Clock Out
; Watch Dog Timer = OFF
; Power Up Timer = ON
; MCLR = INTERNAL
; Code Protect = ON
; Data EE Read Protect = OFF
; Brown Out Detect = Enabled in Run, Disabled in Sleep, SBOREN Disabled
; Internal External Switch Over Mode (2-speed Startup) = OFF
; Monitor Clock Fail-safe = OFF

;==========================================================================

;*****[ Data Storage Reg's ]*****
CBLOCK 0x20 ; Assign each reg. from Bank 0 RAM area.
;
DB1 ; Registers used for
DB0 ; number storage within
count1 ; the various delay/counter routines.
count2
count3
count4
count5
counter
speedcnt
init
DAT ; Calculations memory
;
ENDC ; Conclude Bank 0 RAM assignments.

;==================================================================================
ORG 0 ; Program origin at mem location 0.
;----------------------------------------------------------------------------------
Initialize
BANKSEL OSCCON ; Switch to Bank 1.
MOVLW b'01100001' ; 4MHz Clk, IntOsc, SysClk via IntOsc
MOVWF OSCCON
;
BANKSEL CMCON0 ; Switch to Bank 0.
MOVLW b'00000111' ; Turn off Comparator.
MOVWF CMCON0
BANKSEL ANSEL ; Switch to Bank 1.
CLRF ANSEL ; Set I/O pins to Digital.
;
MOVLW b'00011000' ; Define inputs & outputs.
MOVWF TRISIO
MOVLW b'11000011' ; Disable pull-ups, Prescaler -> TMR0
MOVWF OPTION_REG ; (TMR0 prescaler = 16).
;
BANKSEL GPIO ; Switch to Bank 0.
Starter movlw b'00011011' ; Set GPIO initial states.
movwf GPIO ; (Make GP0 & GP1 HI, HI side of LEDs)
;
; Set CCP1 as PWM
MOVLW B'00001111'
MOVWF CCP1CON ; Set bits 4-5 (2 LSB's of Duty Cycle) to 00.
;
; Set highest PWM value (resolution), 10-bit but only 256 discrete Duty Cycles.
BANKSEL PR2 ; Bank 1
MOVLW d'255' ; 10-bit res. but 256 Duty Cycles (Duty Cycle LSB = 00)
MOVWF PR2 ; Establishes Timer2 Period.
;
; Set prescaler to 16 for a PWM freq. of 244Hz (based on 4MHz clock).
; Since the human eye cannot perceive flicker above 120Hz, 244Hz is OK.
BANKSEL T2CON ; Bank 0
MOVLW B'00000010'
MOVWF T2CON ; Timer2 is now OFF & Prescaler is 16.
;
CLRF CCPR1L ; Clear PWM Reg.1 LO Byte (sets PWM Duty Cycle to zero)
; (CCPR1L contains the 8 MSB's of the Duty Cycle.)
BSF T2CON, TMR2ON ; Turn on Timer2.
;
;==================================================================================

Begin ; Fade Duration: 3.9ms x 255 = 1s
CALL Del_4 ; Wait 3.9ms.
INCF CCPR1L, F ; Increase Duty Cycle (make LED brighter).
MOVLW b'11111111'
XORWF CCPR1L, W
SKPZ ; Have we incremented up to 255 yet?
GOTO Begin ; No. Keep incrementing (increasing brightness).
;
CALL Del_200 ; Keep LED at max brightness for 200ms.
Fadeout
CALL Del_4 ; Wait 3.9ms.
DECFSZ CCPR1L, F ; Decrease Duty Cycle (make LED dimmer).
GOTO Fadeout ; Keep decrementing until 0 (LED OFF).
;
;LED OFF, so kill PWM output to save power.
MOVLW b'00011000' ; Make GP0 & GP1 LO (HI side of LEDs).
movwf GPIO
BCF T2CON, TMR2ON ; Turn OFF Timer2.
CLRF CCP1CON ; Turn OFF PWM module.
;
CALL Del_2s ; Hold LED OFF for 2 seconds.
;
GOTO Starter ; Power PWM back up & Restart program.



Hesaplama için
 
Moderatör tarafında düzenlendi:
Sayın;@MAIN_LOOP,bİldiğim kadarıyla 16f628'de bu port yok.Pwm yapılamaz. Yanılıyorsam özür..

12f683 için;



; CLOCK: Internal RC 4MHz (instruction execution time: 1usec)
;
; NOTE: PWM used for LED fade in/out. Positive sides locked to
; HI via 150-ohm resistors, while GND side of LEDs is
; driven by a varying active-low PWM signal.
;
;==================================================================================
list P=12F683, ST=OFF ; Turnoff Symbol Table in List file.

errorlevel -302 ; Ignore error message when storing to Bank 1.
;==================================================================================

#include <p12f683.inc>

__config _INTOSCIO & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOD_NSLEEP & _IESO_OFF & _FCMEN_OFF

; ------------------------------------
; Configuration Bit Settings Explained
; ------------------------------------
; Internal RC Oscillator, No Clock Out
; Watch Dog Timer = OFF
; Power Up Timer = ON
; MCLR = INTERNAL
; Code Protect = ON
; Data EE Read Protect = OFF
; Brown Out Detect = Enabled in Run, Disabled in Sleep, SBOREN Disabled
; Internal External Switch Over Mode (2-speed Startup) = OFF
; Monitor Clock Fail-safe = OFF

;==========================================================================

;*****[ Data Storage Reg's ]*****
CBLOCK 0x20 ; Assign each reg. from Bank 0 RAM area.
;
DB1 ; Registers used for
DB0 ; number storage within
count1 ; the various delay/counter routines.
count2
count3
count4
count5
counter
speedcnt
init
DAT ; Calculations memory
;
ENDC ; Conclude Bank 0 RAM assignments.

;==================================================================================
ORG 0 ; Program origin at mem location 0.
;----------------------------------------------------------------------------------
Initialize
BANKSEL OSCCON ; Switch to Bank 1.
MOVLW b'01100001' ; 4MHz Clk, IntOsc, SysClk via IntOsc
MOVWF OSCCON
;
BANKSEL CMCON0 ; Switch to Bank 0.
MOVLW b'00000111' ; Turn off Comparator.
MOVWF CMCON0
BANKSEL ANSEL ; Switch to Bank 1.
CLRF ANSEL ; Set I/O pins to Digital.
;
MOVLW b'00011000' ; Define inputs & outputs.
MOVWF TRISIO
MOVLW b'11000011' ; Disable pull-ups, Prescaler -> TMR0
MOVWF OPTION_REG ; (TMR0 prescaler = 16).
;
BANKSEL GPIO ; Switch to Bank 0.
Starter movlw b'00011011' ; Set GPIO initial states.
movwf GPIO ; (Make GP0 & GP1 HI, HI side of LEDs)
;
; Set CCP1 as PWM
MOVLW B'00001111'
MOVWF CCP1CON ; Set bits 4-5 (2 LSB's of Duty Cycle) to 00.
;
; Set highest PWM value (resolution), 10-bit but only 256 discrete Duty Cycles.
BANKSEL PR2 ; Bank 1
MOVLW d'255' ; 10-bit res. but 256 Duty Cycles (Duty Cycle LSB = 00)
MOVWF PR2 ; Establishes Timer2 Period.
;
; Set prescaler to 16 for a PWM freq. of 244Hz (based on 4MHz clock).
; Since the human eye cannot perceive flicker above 120Hz, 244Hz is OK.
BANKSEL T2CON ; Bank 0
MOVLW B'00000010'
MOVWF T2CON ; Timer2 is now OFF & Prescaler is 16.
;
CLRF CCPR1L ; Clear PWM Reg.1 LO Byte (sets PWM Duty Cycle to zero)
; (CCPR1L contains the 8 MSB's of the Duty Cycle.)
BSF T2CON, TMR2ON ; Turn on Timer2.
;
;==================================================================================

Begin ; Fade Duration: 3.9ms x 255 = 1s
CALL Del_4 ; Wait 3.9ms.
INCF CCPR1L, F ; Increase Duty Cycle (make LED brighter).
MOVLW b'11111111'
XORWF CCPR1L, W
SKPZ ; Have we incremented up to 255 yet?
GOTO Begin ; No. Keep incrementing (increasing brightness).
;
CALL Del_200 ; Keep LED at max brightness for 200ms.
Fadeout
CALL Del_4 ; Wait 3.9ms.
DECFSZ CCPR1L, F ; Decrease Duty Cycle (make LED dimmer).
GOTO Fadeout ; Keep decrementing until 0 (LED OFF).
;
;LED OFF, so kill PWM output to save power.
MOVLW b'00011000' ; Make GP0 & GP1 LO (HI side of LEDs).
movwf GPIO
BCF T2CON, TMR2ON ; Turn OFF Timer2.
CLRF CCP1CON ; Turn OFF PWM module.
;
CALL Del_2s ; Hold LED OFF for 2 seconds.
;
GOTO Starter ; Power PWM back up & Restart program.



Hesaplama için


16 bit capture ve compare 10 bit çözünürlüktede pwm modülü varmış 16f628 de. pin portb.3
 
Moderatör tarafında düzenlendi:
yahu altu ustu bir frekans elde edecen.illada pbp ya neden kitleniyorsunuz.yapacagınız set yap bekle reset yap bekle basa don.sadece hesaplamanız gereken bekleme surelerı.40 khz ise 1/40 000 den periyodu bulursun ve yarısını set yarısınıda reset yaparsın oldu sana 40khz.
mainloop (bak bizim mainin her yerde adı geciyor.....:) )
bsf portb,0
call wait
bcf portb,0
goto mainloop


wait mowlw .100 (kafadan attım simulatorde olcup tam degerını bulursun)
movwf temp
bekle nop ;bekleme suresı az gelirse birkactane daha np eklersin
decfsz temp,f
goto bekle
return
 
Yardımlarınız için çok teşekkürler.36-38 khz'i ürettim bunun için pic kullanmadım.Pic programını çalıştıramadım.Bende 555 entegreli bir devre yaptım.Sorunum çözüldü.:)
 

Yeni mesajlar

Forum istatistikleri

Konular
127,964
Mesajlar
913,940
Kullanıcılar
449,609
Son üye
cherrywine

Yeni konular

Geri
Üst