Hey Ken, OK, now I understand your project, and the use of the PicKit's!
Well, I was able to correct my servo jitter, an error on my part of course.
Here is some code for a single servo channel pass through, using DT_INTS. Next I will try adding the other CCP pin.
Code:
define OSC 20
DEFINE LOADER_USED 1
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 42 ' 115200 Baud @ 20MHz, 0.94%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
LED0 var portb.0
LED1 var portb.1
LED2 var portb.2
halftime_bit var bit
adcon1=15 ;sets all to digital
TRISA=%00000000 ' Set PORTA
TRISB=%01110000 ' Set PortB switch inputs (not used)
TRISC=%10000100 ' Set PortC.2 to input for ccp1
' set portC.7 to input for serial port
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
include "sub16.inc" ; subtract 16 bit macro
LED1=1 ; Set to Output Low
LED0=0
led2=1
portb.3 = 0
servo_out var portb.3
risetime var word ;used for pulse width measure start of pw
falltime var word ;time at end of pulse width
timer0 var word ;used to load tmr0l and h bytes
falltime_l var falltime.byte0
falltime_h var falltime.byte1
risetime_l var risetime.byte0
risetime_h var risetime.byte1
pause 1000
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
;INT_Handler TMR1_INT, ToggleLED1, ASM, yes
INT_Handler TMR0_INT, _PWMout, ASM, yes
INT_Handler CCP1_INT, PWMeasure, ASM, yes
INT_Handler TMR2_INT, _twentyMs, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T0CON = %00000001
T1CON = %00000001
T2CON = %01011111
CCP1CON = %00000101
;@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts
@ INT_ENABLE TMR0_INT
@ INT_ENABLE CCP1_INT
@ INT_ENABLE TMR2_INT
Main:
NOP
GOTO Main
twentyMs: ;really 10ms, but only acted on half the time
toggle halftime_bit
if halftime_bit = 1 then ;only perform this every other time this is called
timer0 = falltime/4 ;measured pulse length, send to
;hserout [dec timer0,",",dec falltime,10,13]
tmr0h = 255 - timer0.byte1
tmr0l = 255 - timer0.byte0
T0CON.7 = 1 ;start t0
servo_out = 1 ;set servopin high
endif
@ INT_RETURN
PWMout:
T0CON.7 = 0
servo_out = 0 ;at completion of timer set servo pin low
@ NOP
@ INT_RETURN
asm
PWMeasure
BTFSS CCP1CON, CCP1M0 ; Check for falling edge watch
GOTO FALL_EDGE ; Go pick up the falling edge
MOVF CCPR1L,W ; else store leading edge value
MOVWF _risetime_l ; into 16 bit word risetime
MOVF CCPR1H,W
MOVWF _risetime_h
BCF CCP1CON, CCP1M0 ; Now capture the trailing edge
GOTO ISR_2 ; Exit the interrupt service routine
FALL_EDGE:
BSF CCP1CON, CCP1M0 ; Re-set for trailing edge capture
MOVF CCPR1L,W ; Store the captured value into
MOVWF _falltime_l ; falltime_l and ...
MOVF CCPR1H,W
MOVWF _falltime_h ; ... falltime_h
;
; 16 bit subtract
; falltime = falltime - risetime
;
SUB16 _falltime, _risetime
ISR_2
INT_RETURN
endasm
Walter
Bookmarks