[help] power control pwm module - pic18f4331
Mình đang có rắc rối với con PIC18F4331 về phần điều khiển động cơ dùng chức năng POWER CONTROL PWM MODULE.
Mình có đoạn code sau, ko hiểu sao lại ko chạy, có cao thủ nào biết xin chỉ giáo với, thanks nhiều!
#define OSCILLATOR d'20000000'
#define PWM_TIMER_PRESCALE d'01'
#define PWM_FREQUENCY d'16000'
PTPER_VALUE = (OSCILLATOR/(4*PWM_FREQUENCY*PWM_TIMER_PRESCALE))-1
;================================================= ====
;=============== PCPWM CONFIGURATION ===================
;================================================= ====
CLRF TRISB ; Port B is output
CLRF LATB
CLRF PORTB
;PCPWM outputs initialized in independent mode.
;PWM<0:5> are enabled
CLRF PTMRH
CLRF PTMRL
CLRF PDC0L ;Clear all PWM duty cycle registers
CLRF PDC1L
CLRF PDC2L
CLRF PDC3L
CLRF PDC0H
CLRF PDC1H
CLRF PDC2H
CLRF PDC3H
MOVLW b'00000000' ;PWM timer is in free running mode(Edge aligned) with Fosc/4 input clock
MOVWF PTCON0 ; Postscale = 1:1 , Prescale = 1:1
MOVLW b'10000000' ; PWM Time base is ON
MOVWF PTCON1 ; PWM Time base count UP
MOVLW LOW(PTPER_VALUE) ; 20KHz = 0xFA ;20KHz of PWM frequency
MOVWF PTPERL ;16KHz = 0x137
;12KHz = 0x1A0
MOVLW HIGH(PTPER_VALUE)
MOVWF PTPERH
MOVLW b'01001111' ; PWM0 to PWM5 Enable
MOVWF PWMCON0 ; Independent mode
MOVLW b'00000001' ; Output overrides via the OVDCON register are synchronized to the PWM time base
MOVWF PWMCON1 ; 1:1 Postscale
; A Special Event Trigger will occur when the PWM time base is counting upwards
; Updates from Duty Cycle and Period Buffer registers are enabled
MOVLW b'00000000' ;No dead time inserted
MOVWF DTCON
MOVLW b'00000000' ;PWM<0:5> PWM Duty cycle on overide
MOVWF OVDCOND
MOVLW b'00111000' ; All PWMs = 0 on init
MOVWF OVDCONS
MOVLW b'10110011' ;FaultA = Over current,cycle by cycle mode
MOVWF FLTCONFIG ;FaultbB = Over voltage,cycle by cycle mode
MOVLW 0x00 ;Special event not used
MOVWF SEVTCMPL
MOVLW 0x00
MOVWF SEVTCMPH
Nhân tiện cho hỏi luôn, thanh ghi LAT như LATA. LATB,.. để làm gì ? Mình mới chuyển qua PIC18 nên chưa rõ lắm
|