Hi Everyone,
Talat from Istanbul here. Please help wıth my PWM problem.
My code is runnıng BUT I get only 1 or 2 output pulses from port B3 on startup then no output after that.
What am ı doıng wrong?
Thanks ın advance fo you help.
Talat
'************************************************* ***************
'* Name : *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 09.08.2014 *
'* Version : 1.0 *
'* Notes : 16F1827 *
'* : *
'************************************************* ***************
' DEVİCE 16F1827
ASM
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__config _CONFIG2, _PLLEN_ON & _LVP_OFF & _LVP_OFF & _STVREN_OFF; & _VCAPEN_OFF
ENDASM
CLEAR
DEFINE OSC 32
OSCCON=%01110000 '32
DEFINE INTHAND PWM_INT
PWM_VAL VAR WORD BANK0 SYSTEM
VALUE VAR WORD
INIT:
APFCON0 = 0 'SET PORTB.3 TO CCP1
T1CON = %00100000 'Prescaler 1:4
PIE1.0 = 1 'TMR1IE TMR1 Interrupt Enable
PIR1.0 = 0 'TMR1IF TMR1 Interrupt Flag
INTCON.7 = 1 'GIE Global Interrupt Enable
INTCON.6 = 1 'PEIE Peripheral Interrupt Enable
CCP1CON = 9 'compare mode
OUTPUT PORTB.3 'CCP PIN
T1CON.0 = 1 'TMR1ON SET TMR1
PAUSE 1000
VALUE=1000
MLOOP:
VALUE=VALUE+1
PWM_VAL = VALUE
Goto MLOOP
Asm
PWM_INT
movlw 9 ; compare mode
clrf CCP1CON ; clear reg
movwf CCP1CON ; Set reg
movf PWM_VAL+1,W ; hb
movwf CCPR1H ; put
movf PWM_VAL,W ; lb
movwf CCPR1L ; put
bsf INTCON,7 ;GIE = 1
bsf INTCON,6 ;PEIE = 1 Enable peripheral interrupts
bsf PIE1,0 ; TMR1IE= 1 Enable TMR1
bcf PIR1,0 ; TMR1IF = 0 Clear Timer1 Int Flag
RETFIE ; Return from Interrupt
EndAsm
END
Bookmarks