Sooo, I think i've gone almost completely crazy trying to figure this out.
I know its asking a lot, but if any one feels they could offer any advice could you please, please have a look at this for me. I've spent so long trying to figure this out and tried everything I can think of but to no avail.
The strange part is, it works perfectly if I use Period of 10000.
Like this,
AND
A test BIT of BIT 2. Shown below.
But as soon as I change the Period to a different value, with a different test BIT, it doesn't work any more.
It reduced the Frequency to something like 12hz. instead of 50hz. Please help if you can. Thanks.
I know its asking a lot, but if any one feels they could offer any advice could you please, please have a look at this for me. I've spent so long trying to figure this out and tried everything I can think of but to no avail.
The strange part is, it works perfectly if I use Period of 10000.
Like this,
Rich (BB code):
MOVLW HIGH D'10000' ; (20000 / (number of channel used 1...8))
MOVWF PeriodH
MOVLW LOW D'10000'
MOVWF PeriodL
A test BIT of BIT 2. Shown below.
Rich (BB code):
BTFSS PortShadow,2 ; IF PAST NUMBER OF REQUIRED SERVOS SKIP NEXT.
But as soon as I change the Period to a different value, with a different test BIT, it doesn't work any more.
It reduced the Frequency to something like 12hz. instead of 50hz. Please help if you can. Thanks.
Rich (BB code):
; PINTERRUPT VECTOR JUMP ADDRESS
; ---------------------------------------------------------------------
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
org H'04' ; INTERRUPT VECTOR JUMP ADDRESS..
movwf W_ISR ; save main program context
swapf STATUS,W ;
movwf S_ISR ; save STATUS reg
clrf STATUS ; force bank 0
movfW FSR ;
movwf F_ISR ; save FSR from MAIN
movfw ISR_FSRsave ; Restore FSR for Interrupt
movwf FSR ;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;*****************************************************************************
;just used to work out if any pins are high or all pins are low.
BTFSC PortFlag,0 ; CHECK IF FLAG (PORTD) BIT IS HIGH ;*
GOTO DriveHigh ; SKIPPED IF PORTD IS ALREADY ZEROS. ;*
;else will SHIFT HIGH BIT.. making curret bit low. ;*
;*****************************************************************************
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;DriveLow
;this section uses servo pulse to work out period, & sets servo high into timer.
;select servo based on indirect addressing.
;also calculate servo low time (period) and store in period register.
movfw INDF ; Servo[x] pulse. low byte, 600..2400
SUBWF PeriodL,F ; CALCULATES LOW BYTE SAVES IN PeriodL
MOVWF CCPR1L ; should put servoLx in timer low
incf FSR,F ;
movfw INDF ; Servo[x] pulse high byte, 600..2400
BTFSS STATUS,C ; Test if Carry occured.
DECF PeriodH,F ; If Carry occured, decrement PeriodH
SUBWF PeriodH,F ; CALCULATES HIGH BYTE SAVES IN PeriodH
MOVWF CCPR1H ; should put servoHx in timer High
;Sets Pin High (Pin is SHIFTED in next part of Subroutine.)
MOVFW PortShadow
MOVWF PORTD
BSF PortFlag,0 ; Set FLAG for test at start.
incf FSR,F ; INCREMENTS FSR ready for next time.
GOTO ISR_EXIT
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
DriveHigh ;drives all pins low and set servo x low time (period)
;this section set Servo into timer.
MOVFW PeriodH ;# ;Period times were calculated
MOVWF CCPR1H ;# ;So now can just store in Timeer Register.
MOVFW PeriodL ;# (20,000 / (between 1&8) - Servo High Time.)
MOVWF CCPR1L ;#
MOVLW b'00000000' ;# PORTD low for Low part of Servo signal.
MOVWF PORTD ;#
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;RESTORE PERIOD TIME
MOVLW HIGH D'5000' ; (20000 / (number of channel used 1...8))
MOVWF PeriodH
MOVLW LOW D'5000'
MOVWF PeriodL
;^^^^^^^^^^^^^^^^^^^^^^^^
;Clears PORTFLAG ready decision next time, and rotates PortShadow PIN.
bcf PortFlag,0 ; so next run selects for Low part of signal
clrc ; clear carry to stop high bit being brough in.
RLF PortShadow,F ; 00000001 <----- rotate bits Port Shadow.
;need to check incase I moved bit into carry.
;TESTS WHAT CHANNEL I AM UP TO. WILL NEED TO TEST CARRY IF I WANT FULL 8 BITS.
BTFSS PortShadow,4 ; IF PAST NUMBER OF REQUIRED SERVOS SKIP NEXT.
GOTO ISR_EXIT ; go to end if ISR.
MOVLW B'00000001' ; If TIME FOR RESET, reset Count and Pin Select.
MOVWF PortShadow ; reset PortShadow to initial position '10000000'
movlw Servo ; add Servo[0] base address
movwf FSR ; setup indirect address
GOTO ISR_EXIT
ISR_EXIT
;^^^^^^^^^^^^^^^^^^^^^^^^^^
BCF PIR1,2 ;BIT 2 IS CCP1F (CCP1 INTERUPT FLAG BIT) CLEAR
;^^^^^^^^^^^^^^^^^^^^^^^^^^^
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
movfw FSR
movwf ISR_FSRsave ; Save FSR from INTERRUPT
movfw F_ISR
movwf FSR ; restore FSR
swapf S_ISR,W
movwf STATUS ; restore STATUS
swapf W_ISR,F ; don't screw up STATUS
swapf W_ISR,W ; restore W-reg
retfie ; return from interrupt
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%