superbrew
Member
I am trying to learn assembly and all was going well, until I tried to create a PWM signal. All I get is PORTD.1 blinking at about 10Hz.
Here is the code that I am using:
I know the A/D is good because I used it on another project that read out on 7seg displays. This program also works with the Oshonsoft sim using the 18F4550, although it does act funny at the extremes of the A/D range.
Thanks
Here is the code that I am using:
Code:
list p=18F4553
include <p18F4553.inc>
CONFIG FOSC=HS,WDT=OFF,MCLRE=ON,LVP=OFF
PWM1 RES 1
ORG 0x00
GOTO INIT
ORG 0x08
GOTO PWM_ISR
ORG 0x18
GOTO PWM_ISR
INIT:
MOVLW b'00000001'
MOVWF TRISA
CLRF PORTA
CLRF TRISD
CLRF PORTD
;AN0,AD OFF
MOVLW b'00000000'
MOVWF ADCON0
;Vss,Vdd,AN3-AN0
MOVLW b'00001011'
MOVWF ADCON1
;Left,16Tad,FOSC/16
MOVLW b'00110101'
MOVWF ADCON2
;Timer 1 on with Pre=2
MOVLW b'10010001'
MOVWF T1CON
MOVLW b'00001011' ;Special event trigger
MOVWF CCP1CON
MOVLW 0xFF
MOVWF CCPR1L
BSF ADCON0,ADON ;turn ad on
BSF PIE1,CCP1IE ;enable CCP1 interrupt
BSF INTCON,PEIE ;enable peripheral interrupts
BSF INTCON,GIE ;enable global interrupts
CLRF PWM1
LOOP:
GOTO LOOP
;*******************************
;PWM ISR *
;*******************************
PWM_ISR:
BTFSC LATD,1
GOTO TURN_OFF
BSF ADCON0,1
AD:
BTFSS ADCON0,1
GOTO AD
MOVF ADRESH,W
MOVWF CCPR1L
BSF LATD,1
GOTO ISR_END
TURN_OFF:
CLRF PWM1
MOVF ADRESH,W
SUBWF PWM1
MOVF PWM1,W
MOVWF CCPR1L
BCF LATD,1
ISR_END
BCF PIR1,CCP1IF ;clear int flag
RETFIE
END
I know the A/D is good because I used it on another project that read out on 7seg displays. This program also works with the Oshonsoft sim using the 18F4550, although it does act funny at the extremes of the A/D range.
Thanks