I builded this codes,
PROCESSOR PIC18F1220
RADIX HEX
; Enhancing the CCP/ECCP frequency resolution for lighting applications
;
; This technique allows a very high frequency PWM (100kHz) signal to be generated
; while providing extremely small frequency increments (60Hz)
;
INCLUDE "p18f1220.inc"
;------------------------------------------------
; timing definitions in kH
#define CLOCK .10000 ; Tcy = 40MHz/4 = 10MHz
#define NFREQ .100 ; nominal frequency 100kHz
#define IPERIOD (CLOCK/NFREQ)-1 ; calculating the base period
#define IFRAC .5 ; 4 bit(0-15)augmented resolution
;------------------------------------------------
; RAM allocation
CBLOCK 0
PERIOD ; integer period
FRAC ; fractional period (0-15)
FACC ; fractional accumulator
ENDC
;------------------------------------------------
; port definitions
#define OUT PORTB,0 ; for demonstration only
;------------------------------------------------
ORG 0 ; reset vector
resetv
goto init
;------------------------------------------------
ORG 08 ; high priority interrupt vector
isr
bcf CCP1CON,DC1B1
bcf PIR1,TMR2IF ; clear the interrupt flag
movf FRAC,W
addwf FACC,F ; add the FRAC to the accumulator
movf PERIOD,W ; get the base period value in W
btfss FACC,4 ; if there was a carry in the fractional accumulator
goto setpr2
incf WREG,W ; increase the period by 1
bsf CCP1CON,DC1B1 ; increase duty by 2xTq to keep it 50%
setpr2
movwf PR2 ; update the next period value
; <<< for demonstration only
btfsc FACC,4
bsf OUT ; signal longer period (T1)
btfss FACC,4
bcf OUT ; signal shorter period (T2)
; >>> for demonstration only
bcf FACC,4 ; clear the carry bit
isre
retfie 1 ; return (fast) restoring the shadow registers
; total ISR time = 13 cycles or 13% MCU load @100kHz/40MHz
;------------------------------------------------
setPWM
; save the required PWM period value
movwf PERIOD
; set the initial period register value PR2
movwf PR2
; set the duty cycle to 50%
incf WREG,W ; PERIOD+1 is the actual total cycle count
bcf STATUS,C ; divide by 2
rrcf WREG,F ; shifting right
movwf CCPR1L ; set the duty cycle
return
;------------------------------------------------
init
; init the output port
movlw b'00000000'
movwf TRISB
; disable analog inputs
setf ADCON1
; set CCP module in PWM mode
movlw b'00001100'
movwf CCP1CON
; set the tmr2 to generate the desired frquency and 50% duty
movlw b'00000100' ; prescale 0, postscale 0, tmr2 ON
movwf T2CON
; init the period value
movlw IPERIOD
call setPWM ; set the PWM and duty cycle
; then init the FRACTIONAL divider for the demo
movlw IFRAC
movwf FRAC ; init the fractional period part
; clear the fractional accumulator
clrf FACC ; clear the accumulator
; then init the interrupt on CCP1/TMR2
bcf PIR1,TMR2IF
bsf PIE1,TMR2IE
; init gloabal and peripheral interrupts
bsf INTCON,PEIE
bsf INTCON,GIE
;------------------------------------------------
main
goto main
end
and i got the error:
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Projects32\mytest.o".
Clean: Deleted file "C:\Projects32\mytest.ERR".
Clean: Deleted file "mytest.lst".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p18F1220 "mytest.asm" /l"mytest.lst" /e"mytest.err" /o"mytest.o"
Warning[205] C:\PROJECTS32\MYTEST.ASM 1 : Found directive in column 1. (PROCESSOR)
Warning[205] C:\PROJECTS32\MYTEST.ASM 2 : Found directive in column 1. (RADIX)
Warning[205] C:\PROJECTS32\MYTEST.ASM 8 : Found directive in column 1. (INCLUDE)
Warning[205] C:\PROJECTS32\MYTEST.ASM 17 : Found directive in column 1. (CBLOCK)
Warning[205] C:\PROJECTS32\MYTEST.ASM 21 : Found directive in column 1. (ENDC)
Warning[205] C:\PROJECTS32\MYTEST.ASM 26 : Found directive in column 1. (ORG)
Warning[203] C:\PROJECTS32\MYTEST.ASM 28 : Found opcode in column 1. (goto)
Warning[205] C:\PROJECTS32\MYTEST.ASM 30 : Found directive in column 1. (ORG)
Warning[203] C:\PROJECTS32\MYTEST.ASM 32 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 33 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 34 : Found opcode in column 1. (movf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 35 : Found opcode in column 1. (addwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 36 : Found opcode in column 1. (movf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 37 : Found opcode in column 1. (btfss)
Warning[203] C:\PROJECTS32\MYTEST.ASM 38 : Found opcode in column 1. (goto)
Warning[203] C:\PROJECTS32\MYTEST.ASM 39 : Found opcode in column 1. (incf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 40 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 42 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 44 : Found opcode in column 1. (btfsc)
Warning[203] C:\PROJECTS32\MYTEST.ASM 45 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 46 : Found opcode in column 1. (btfss)
Warning[203] C:\PROJECTS32\MYTEST.ASM 47 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 49 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 51 : Found opcode in column 1. (retfie)
Warning[203] C:\PROJECTS32\MYTEST.ASM 56 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 58 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 60 : Found opcode in column 1. (incf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 61 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 62 : Found opcode in column 1. (rrcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 63 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 64 : Found opcode in column 1. (return)
Warning[203] C:\PROJECTS32\MYTEST.ASM 68 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 69 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 71 : Found opcode in column 1. (setf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 73 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 74 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 76 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 77 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 79 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 80 : Found opcode in column 1. (call)
Warning[203] C:\PROJECTS32\MYTEST.ASM 82 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 83 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 85 : Found opcode in column 1. (clrf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 87 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 88 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 90 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 91 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 94 : Found opcode in column 1. (goto)
Warning[205] C:\PROJECTS32\MYTEST.ASM 95 : Found directive in column 1. (end)
Executing: "C:\Program Files\Microchip\MPASM Suite\MPLink.exe" "C:\Projects32\18f1220.lkr" "C:\Projects32\mytest.o" /o"pwmtest.cof" /M"pwmtest.map"
MPLINK 4.06, Linker
Copyright (c) 2006 Microchip Technology Inc.
Error - section '.org_1' can not fit the absolute section. Section '.org_1' start=0x00000008, length=0x00000056
Errors : 1
BUILD FAILED: Thu Dec 07 00:06:35 2006
Can anyone help me in that? Appreciate
PROCESSOR PIC18F1220
RADIX HEX
; Enhancing the CCP/ECCP frequency resolution for lighting applications
;
; This technique allows a very high frequency PWM (100kHz) signal to be generated
; while providing extremely small frequency increments (60Hz)
;
INCLUDE "p18f1220.inc"
;------------------------------------------------
; timing definitions in kH
#define CLOCK .10000 ; Tcy = 40MHz/4 = 10MHz
#define NFREQ .100 ; nominal frequency 100kHz
#define IPERIOD (CLOCK/NFREQ)-1 ; calculating the base period
#define IFRAC .5 ; 4 bit(0-15)augmented resolution
;------------------------------------------------
; RAM allocation
CBLOCK 0
PERIOD ; integer period
FRAC ; fractional period (0-15)
FACC ; fractional accumulator
ENDC
;------------------------------------------------
; port definitions
#define OUT PORTB,0 ; for demonstration only
;------------------------------------------------
ORG 0 ; reset vector
resetv
goto init
;------------------------------------------------
ORG 08 ; high priority interrupt vector
isr
bcf CCP1CON,DC1B1
bcf PIR1,TMR2IF ; clear the interrupt flag
movf FRAC,W
addwf FACC,F ; add the FRAC to the accumulator
movf PERIOD,W ; get the base period value in W
btfss FACC,4 ; if there was a carry in the fractional accumulator
goto setpr2
incf WREG,W ; increase the period by 1
bsf CCP1CON,DC1B1 ; increase duty by 2xTq to keep it 50%
setpr2
movwf PR2 ; update the next period value
; <<< for demonstration only
btfsc FACC,4
bsf OUT ; signal longer period (T1)
btfss FACC,4
bcf OUT ; signal shorter period (T2)
; >>> for demonstration only
bcf FACC,4 ; clear the carry bit
isre
retfie 1 ; return (fast) restoring the shadow registers
; total ISR time = 13 cycles or 13% MCU load @100kHz/40MHz
;------------------------------------------------
setPWM
; save the required PWM period value
movwf PERIOD
; set the initial period register value PR2
movwf PR2
; set the duty cycle to 50%
incf WREG,W ; PERIOD+1 is the actual total cycle count
bcf STATUS,C ; divide by 2
rrcf WREG,F ; shifting right
movwf CCPR1L ; set the duty cycle
return
;------------------------------------------------
init
; init the output port
movlw b'00000000'
movwf TRISB
; disable analog inputs
setf ADCON1
; set CCP module in PWM mode
movlw b'00001100'
movwf CCP1CON
; set the tmr2 to generate the desired frquency and 50% duty
movlw b'00000100' ; prescale 0, postscale 0, tmr2 ON
movwf T2CON
; init the period value
movlw IPERIOD
call setPWM ; set the PWM and duty cycle
; then init the FRACTIONAL divider for the demo
movlw IFRAC
movwf FRAC ; init the fractional period part
; clear the fractional accumulator
clrf FACC ; clear the accumulator
; then init the interrupt on CCP1/TMR2
bcf PIR1,TMR2IF
bsf PIE1,TMR2IE
; init gloabal and peripheral interrupts
bsf INTCON,PEIE
bsf INTCON,GIE
;------------------------------------------------
main
goto main
end
and i got the error:
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Projects32\mytest.o".
Clean: Deleted file "C:\Projects32\mytest.ERR".
Clean: Deleted file "mytest.lst".
Clean: Done.
Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p18F1220 "mytest.asm" /l"mytest.lst" /e"mytest.err" /o"mytest.o"
Warning[205] C:\PROJECTS32\MYTEST.ASM 1 : Found directive in column 1. (PROCESSOR)
Warning[205] C:\PROJECTS32\MYTEST.ASM 2 : Found directive in column 1. (RADIX)
Warning[205] C:\PROJECTS32\MYTEST.ASM 8 : Found directive in column 1. (INCLUDE)
Warning[205] C:\PROJECTS32\MYTEST.ASM 17 : Found directive in column 1. (CBLOCK)
Warning[205] C:\PROJECTS32\MYTEST.ASM 21 : Found directive in column 1. (ENDC)
Warning[205] C:\PROJECTS32\MYTEST.ASM 26 : Found directive in column 1. (ORG)
Warning[203] C:\PROJECTS32\MYTEST.ASM 28 : Found opcode in column 1. (goto)
Warning[205] C:\PROJECTS32\MYTEST.ASM 30 : Found directive in column 1. (ORG)
Warning[203] C:\PROJECTS32\MYTEST.ASM 32 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 33 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 34 : Found opcode in column 1. (movf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 35 : Found opcode in column 1. (addwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 36 : Found opcode in column 1. (movf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 37 : Found opcode in column 1. (btfss)
Warning[203] C:\PROJECTS32\MYTEST.ASM 38 : Found opcode in column 1. (goto)
Warning[203] C:\PROJECTS32\MYTEST.ASM 39 : Found opcode in column 1. (incf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 40 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 42 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 44 : Found opcode in column 1. (btfsc)
Warning[203] C:\PROJECTS32\MYTEST.ASM 45 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 46 : Found opcode in column 1. (btfss)
Warning[203] C:\PROJECTS32\MYTEST.ASM 47 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 49 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 51 : Found opcode in column 1. (retfie)
Warning[203] C:\PROJECTS32\MYTEST.ASM 56 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 58 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 60 : Found opcode in column 1. (incf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 61 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 62 : Found opcode in column 1. (rrcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 63 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 64 : Found opcode in column 1. (return)
Warning[203] C:\PROJECTS32\MYTEST.ASM 68 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 69 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 71 : Found opcode in column 1. (setf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 73 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 74 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 76 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 77 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 79 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 80 : Found opcode in column 1. (call)
Warning[203] C:\PROJECTS32\MYTEST.ASM 82 : Found opcode in column 1. (movlw)
Warning[203] C:\PROJECTS32\MYTEST.ASM 83 : Found opcode in column 1. (movwf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 85 : Found opcode in column 1. (clrf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 87 : Found opcode in column 1. (bcf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 88 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 90 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 91 : Found opcode in column 1. (bsf)
Warning[203] C:\PROJECTS32\MYTEST.ASM 94 : Found opcode in column 1. (goto)
Warning[205] C:\PROJECTS32\MYTEST.ASM 95 : Found directive in column 1. (end)
Executing: "C:\Program Files\Microchip\MPASM Suite\MPLink.exe" "C:\Projects32\18f1220.lkr" "C:\Projects32\mytest.o" /o"pwmtest.cof" /M"pwmtest.map"
MPLINK 4.06, Linker
Copyright (c) 2006 Microchip Technology Inc.
Error - section '.org_1' can not fit the absolute section. Section '.org_1' start=0x00000008, length=0x00000056
Errors : 1
BUILD FAILED: Thu Dec 07 00:06:35 2006
Can anyone help me in that? Appreciate