pwm signal with 16F877A please help

Status
Not open for further replies.

amerotke

New Member
Hi to all,
I try to make a servo driver with pic16F877A . I use pic asm. I cant get any signal in mplabsim from portc with this code. Could anybody say me what problem is
I used 40 KHz chrystal
LIST P=16F877A
INCLUDE "P16F877A.INC"

ORG h'000'
GOTO BASLA
;
;
;
;
BASLA
BANKSEL ADCON1
MOVLW h'06'
MOVWF ADCON1
BANKSEL TRISC
CLRF TRISC
BANKSEL PR2
MOVLW b'00110001'
MOVWF PR2
BANKSEL CCP1CON
MOVLW b'00011100'
MOVWF CCP1CON
MOVLW b'00000010'
MOVWF CCPR1L
MOVLW b'00000101'
MOVWF T2CON
END
 
Here you a sample to get your feet wet

Code:
CLRF CCP1CON ; CCP Module is off
CLRF TMR2 ; Clear Timer2
MOVLW 0x7F ;
MOVWF PR2 ;
MOVLW 0x1F ;
MOVWF CCPR1L ; Duty Cycle is 25% of PWM Period
CLRF INTCON ; Disable interrupts and clear T0IF
BSF STATUS, RP0 ; Bank1
BCF TRISC, PWM1 ; Make pin output
CLRF PIE1 ; Disable peripheral interrupts
BCF STATUS, RP0 ; Bank0
CLRF PIR1 ; Clear peripheral interrupts Flags
MOVLW 0x2C ; PWM mode, 2 LSbs of Duty cycle = 10
MOVWF CCP1CON ;
BSF T2CON, TMR2ON ; Timer2 starts to increment
;
; The CCP1 interrupt is disabled,
; do polling on the TMR2 Interrupt flag bit
;
PWM_Period_Match
BTFSS PIR1, TMR2IF
GOTO PWM_Period_Match
;
; Update this PWM period and the following PWM Duty cycle
;
BCF PIR1, TMR2IF
And the rest of story can be found here https://www.electro-tech-online.com/custompdfs/2011/12/31014a.pdf
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…