Estoy intentando que funcione un código PWM muy básico. Sin embargo, todas las salidas PWM parecen estar atascadas en + 5V sin una salida PWM adecuada. Funciona perfectamente en el simulador pero no en el chip. ¿Alguna idea bienvenida?
include <P18f4431.INC>
CONFIG OSC = IRC
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRTEN = OFF
CONFIG BOREN = ON
CONFIG BORV = 20
CONFIG WDTEN = OFF
CONFIG WDPS = 1
CONFIG WINEN = OFF
CONFIG PWMPIN = OFF
CONFIG LPOL = LOW
CONFIG HPOL = LOW
CONFIG T1OSCMX = OFF
CONFIG FLTAMX = RC1
CONFIG SSPMX = RD1
CONFIG PWM4MX = RB5
CONFIG EXCLKMX = RC3
CONFIG MCLRE = ON
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CPD = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRTC = OFF
CONFIG WRTB = OFF
CONFIG WRTD = OFF
CONFIG EBTR0 = OFF
CONFIG EBTR1 = OFF
CONFIG EBTR2 = OFF
CONFIG EBTR3 = OFF
CONFIG EBTRB = OFF
CONFIG STVREN = OFF
CONFIG DEBUG = OFF
CONFIG CPB = OFF
CONFIG WRT0 = OFF
CONFIG LVP = OFF
;***********VARIABLE DEFINITIONS******************
Timer res 1
Timer2 res 1
;*******************************************************************************
; Reset Vector
;*******************************************************************************
STARTUP CODE 0x00 ; processor reset vector
GOTO START ; go to beginning of program
;*******************************************************************************
; MAIN PROGRAM
;******************************************************************************
PROG1 code
START:
;; Initialise PORTB
; CLRF PORTB
; CLRF LATB
; movlw 0x00
; movwf TRISB
;movlw 0xff
;movwf PORTB
movlw b'10111110'
movwf TRISC
; bsf PORTC, 0
movlw b'11010000'
movwf TRISD
bcf PORTD, 0
;***********SET UP OSCILLATOR**************
bsf OSCCON, IRCF0
bsf OSCCON, IRCF1
bsf OSCCON, IRCF2
call INIT_PCPWM
;***********MAIN ROUTINE **********************************
;turn on lamp to show power
bsf PORTD, 1
movlw d'88'
movwf PDC0L ;'set the PWM duty cycle
movlw d'00'
movwf PDC0H
bcf INTCON, RBIF
bcf INTCON, RBPU
Loop:
call Delay
GOTO Loop ; loop forever
;*********DELAY ROUTINES**********************
Delay
movlw d'5'
movwf Timer
movwf Timer2
Loop2:
nop
Loop1:
nop
decfsz Timer, f
goto Loop1
decfsz Timer2, f
goto Loop2
return
;***********************************************
;***********SET UP PWM***********************
INIT_PCPWM
movlw b'01000000' ; deadtime
movwf DTCON
movlw b'00000000'
movwf PTCON0 ; Postcale 1:1, PWM time base input is Fosc/4
; PWM time base mode is free-running for edge-aligned operation
movlw b'10000000'
movwf PTCON1 ; Count up, timer on
movlw d'99' ;PTPERL and PTPERH are set up for a XX PWM frequency
movwf PTPERL
movlw d'00'
movwf PTPERH
movlw b'01000000' ;configure PWMCON0
movwf PWMCON0 ; enable PWM 0 to 5, all PWM I/O pairs set to complimentary
movlw b'00000000' ;configure PWMCON0
movwf PWMCON1 ; Special event postscaler set to 1
; Special event trigger occurs when time-base is counting upward
; Updates from duty cycle and period buffer registers are enabled
; Ouput overides via OVDCON are synchronous to the PWM timebase
movlw b'11111111' ; no output override
movwf OVDCOND
movlw b'00000000' ;OVDCONS is configured such that all PWM outputs are 0 on power up
movwf OVDCONS
movlw b'10010001' ;FAULT A and B enabled in catastrophic mode
movwf FLTCONFIG
movlw 0x00 ;SECTCMPL and SEVTCMPH are cleared
movwf SEVTCMPL
movlw 0x00
movwf SEVTCMPH
bcf FLTCONFIG, FLTAEN ; disable fault condition
bcf FLTCONFIG, FLTBEN ; disable fault condition
bsf PTCON1, PTEN ; enable the PWM time base
return
;***********************************************
END