eventually I found the problem:
in the definition file (P18F4680.pbas) there was an error in declaring CCPR1 (as byte, not as word)
In detail, the ORIGINAL CODE was:
Code: Select all
CCPR1 as byte absolute 0x0FBE volatile register
CCPR1H as byte absolute 0x0FBF volatile register
CCPR1L as byte absolute 0x0FBE volatile register
(...)
ECCP1DEL as byte absolute 0x0FB7 volatile register
ECCPR1 as byte absolute 0x0FBB volatile register
ECCPR1H as byte absolute 0x0FBC volatile register
ECCPR1L as byte absolute 0x0FBB volatile register
Code: Select all
CCPR1 as word absolute 0x0FBE volatile register
CCPR1H as byte absolute 0x0FBF volatile register
CCPR1L as byte absolute 0x0FBE volatile register
(...)
ECCP1DEL as byte absolute 0x0FB7 volatile register
ECCPR1 as word absolute 0x0FBB volatile register
ECCPR1H as byte absolute 0x0FBC volatile register
ECCPR1L as byte absolute 0x0FBB volatile register
Here's the code:
Code: Select all
sub procedure interrupt ' ISR to manage edge detection
If RisingEdge Then
CCP1CON = Capture_FE ' set up to detect next edge
StartEdge = CCPR1
PeriodPWM = CCPR1 - DCEdge + DutyCycle
Else
CCP1CON = Capture_RE ' set up to detect next edge
DCEdge = CCPR1
DutyCycle = CCPR1 - StartEdge
End If
RisingEdge = Not(RisingEdge) ' toggle edge detection flag
PIR1.CCP1IF = 0 ' clear CCP1 interrupt flag
end sub
main:
' inizializzazione generale dello strumento
' init specifico PIC 18F4680
CANCON=%00110000 ' disattivo la periferica CAN
CIOCON.4=0 ' disattivo interrupt su messaggio CAN in ingresso
CANSTAT = 32
CMCON = CMCON OR $07 ' comparatori disattivati
ADCON1 = %00001010 ' analog input su PORTA: DDDAAAAA
PORTB = 0 ' azzero PORTB
TRISB = %00000000 ' inizializzo PORTB: tutto OUTPUT (per GLCD)
'PORTC = 0 ' azzero PORTC
TRISC = %00111001 ' PORTC ha pulsanti su: 0-3-4-5
PORTD = 0 ' azzero PORTD
TRISD = %00000000 ' inizializzo PORTD: tutto OUTPUT (per GLCD)
TRISE = %111 ' inizializzo PORTE: tutto INPUT
' inizializzazione generale DISPLAY GLCD
' * init display for 240 pixel width and 128 pixel height
' * 8 bits character width
' * data bus on PORTD; control bus on PORTB
' * bit 2 is !WR || bit 1 is !RD || bit 0 is !CD || bit 4 is RST
T6963C_Init(240, 128, 8, PORTD, PORTB, 2,1,0,4)
' * enable both graphics and text display at the same time
T6963C_graphics(1)
T6963C_text(1)
' splash screen
T6963C_image(luca_iDEBUG_bmp)
Delay_ms(2000)
' CREAZIONE MENU INIZIALE
menu1:
T6963C_panelFill(0)
T6963C_Write_Text("MENU",10,1,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 1) i-SCOPE ",3,4,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 2) i-PWM ",3,7,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 3) i-SERIAL ",3,10,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 4) i-SERVO ",3,13,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 5) NEXT ---> ",3,15,T6963C_ROM_MODE_XOR)
Delay_ms(200)
seg1:
if PORTE.0=1 then goto iscope end if
if PORTE.1=1 then goto ipwm end if
if PORTE.2=1 then goto iserial end if
if PORTC.0=1 then goto iservo end if
if PORTC.3=1 then goto menu2 end if
Delay_ms(200)
goto seg1
menu2:
T6963C_panelFill(0)
T6963C_Write_Text("MENU",10,1,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 1) i-SERVOLog ",3,4,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 2) i-PWMLog ",3,7,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 3) i-SERIALog ",3,10,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 4) ",3,13,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" 5) <--- PREV ",3,15,T6963C_ROM_MODE_XOR)
Delay_ms(200)
seg2:
if PORTE.0=1 then goto servolog end if
if PORTE.1=1 then goto pwmlog end if
if PORTE.2=1 then goto serialog end if
if PORTC.0=1 then goto menu2 end if
if PORTC.3=1 then goto menu1 end if
Delay_ms(200)
goto seg2
'*******************************************************************************
'************* PWM METER ****************************************************
pwmlog:
' Displays PWM Period/Duty-Period And Frequency/Duty-Percent
'
RisingEdge = false
PeriodPWM = 0
DutyCycle = 0
StartEdge = 0
prevEdge = 0
NextEdge = 0
DCEdge = 0
T3CON = %00000000 ' set TIMER1 for CCP1
T1CON = %00110000 ' Timer1 prescaler = 8 -> 0.8us @ 40MHz
INTCON = 192 ' Global & Peripheral interrupts enabled
CCP1CON = Capture_RE '
LATC.2 = 1 ' Tris RC2 as Input
PIE1.TMR1IE = 0
PIR1.CCP1IF = 0 ' Clear CCP1 Interrupt Flag
PIE1.CCP1IE = 1 ' Enable CCP1 interrupt
T1CON.TMR1ON = 1 ' Start Timer1
T6963C_panelFill(0)
T6963C_Write_Text("LETTORE di segnale PWM",2,1,T6963C_ROM_MODE_XOR)
T6963C_Write_Text("FREQUENZA PWM: ",1,4,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" Hz",25,4,T6963C_ROM_MODE_XOR)
T6963C_Write_Text("DUTY CYCLE PWM: ",1,6,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" %",25,6,T6963C_ROM_MODE_XOR)
T6963C_Write_Text("PERIODO PWM: ",1,9,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" us",25,9,T6963C_ROM_MODE_XOR)
T6963C_Write_Text("PERIODO DUTY CYCLE: ",1,11,T6963C_ROM_MODE_XOR)
T6963C_Write_Text(" us",25,11,T6963C_ROM_MODE_XOR)
While 1=1
' display frequenza PWM in Hz
t0 =10000000 div (periodPWM * 8)
WordToStr(t0, PerStr)
T6963C_Write_Text(PerStr,20,4,T6963C_ROM_MODE_XOR)
' display periodo PWM in us
periodPWM = (periodPWM * 8) div 10
WordToStr(PeriodPWM, PerStr)
T6963C_Write_Text(PerStr,20,9,T6963C_ROM_MODE_XOR)
' display periodo duty cycle in us
DutyCycle = (DutyCycle * 8) div 10
WordToStr(DutyCycle, DCStr)
T6963C_Write_Text(DCStr,20,11,T6963C_ROM_MODE_XOR)
' display duty cycle in %
t0 = DutyCycle * 100 div PeriodPWM
WordToStr(t0, DCStr)
T6963C_Write_Text(DCStr,20,6,T6963C_ROM_MODE_XOR)
Delay_ms(100)
Wend
Luca