you are right, the code segment where the input pulses are received is coded in assembly :
[code];[Pulsein7] Read in all 7 servo values in one pass.
Pulsein7:
; Make sure all 7 IOs are set to input.
PMR5 = 0 ; all IO lines are general IO
PCR5 = 0 ; All are input (may want to leave bit 7 alone…
; Ok now lets transisiton to assembly language.
;
; bMask = 0x7f ; set a mask of which bits we are needing…
; ; Mask could be 0xFE for pins 1-7, need to make array 8 not 7
mov.b #0x7f, r1l ; Ok R1l will be our mask for outstanding IO port bytes.
; wait until none of the IO lines are high...
; while PDR5 & bMask
; ;
; wend
mov.l #250000,er2 ;(4) - setup timeout counter
_PI7_WAIT_FOR_ALL_LOW:
mov.b @PDR5:8, r0l
and.b r1l, r0l ; see if any of the IO bits is still on…
beq _PI7_WAIT_FOR_NEXT_IO_TO_GO_HIGH:8 ; all zero go to wait for one to go high…
dec.l #1,er2 ;(2)
bne _PI7_WAIT_FOR_ALL_LOW:8 ; an IO pin is high and we have not timed out, keep looping until none are high
; We timed out waiting for all inputs to be low, so error out…
bra _P17_RETURN_STATUS:16 ; will return status that all timed out…
; while bMask
_PI7_WAIT_FOR_NEXT_IO_TO_GO_HIGH:
mov.l #250000,er2 ;(4) - setup timeout counter
_PI7_WAIT_FOR_NEXT_IO_TO_GO_HIGH2:
; we still need some 1 or more of the pulses…
; while (PDR5 & bMask) = 0 ; waiting for a pulse to go high.
mov.b @PDR5:8, r0l ;(4)
and.b r1l, r0l ;(*2) see if any of the IO bits is still on…
bne _P17_IO_WENT_HIGH:8 ;(*4) One went high so go process
dec.l #1,er2 ;(2)
bne _PI7_WAIT_FOR_NEXT_IO_TO_GO_HIGH2:8 ; (4) Not a timeout go try again.
; we timed out…
bra _P17_RETURN_STATUS:16 ; will return status of what timed out…
; wend
; iPin = ???; TBD: convert which bit is high to IO line number 0-6
; see which bit is on in the mask
ASM {
_P17_IO_WENT_HIGH:
xor.w r2,r2 ;(*2)
xor.b r0h, r0h ;(*2)
mov.l #AWPULSESIN,er3 ;(*6)
_P17_WHICH_BIT_LOOP:
shlr.b r0l ;(@2)
bcs _P17_WHICH_BIT_LOOP_DONE:8 ;(@4)
inc.b r0h ;(@2)
inc.l #2, er3 ;(@2) - point to the next place in the array.
add.w #18,r2 ;(@4) - we do 18 clocks for each pass through this loop
bra _P17_WHICH_BIT_LOOP:8 ;(@4)
_P17_WHICH_BIT_LOOP_DONE:
; bMaskBit = 1 << iPin ; get the mask for which pin…
xor.b r1h,r1h ;(*2)
bset.b r0h,r1h ;(*2) ok we have the mask
bclr.b r0h,r1l ;(*2) and clear it from our global mask of ones we are waiting for
}
; = (22) - count so far of clocks after went high
; iPinLoopCnt = 0 ; This may be replaced with time calculations…
; while (PDR5 & bMaskBit)
; iPinLoopCnt = iPinLoopCnt + 1 ; how long until it goes low again
; wend
_P17_WAIT_FOR_IO_GO_BACK_LOW:
mov.b @PDR5:8, r0l ;(#4)
and.b r1h, r0l ;(#2)
beq _P17_IO_WENT_BACK_LOW:8 ;(#4)
add.w #18,r2 ;(#4) - number of cyles per loop
bcc _P17_WAIT_FOR_IO_GO_BACK_LOW:8 ;(#4)
; we had a timeout return the status.
bset.b r0h, r1l ; turn back on the bit we were waiting for…
bra _P17_RETURN_STATUS:8 ;
_P17_IO_WENT_BACK_LOW:
; need to calculate the pulse width in ms… need to divide calculated clocks by 16
add.w #22,r2 ; (4) ; need to add the rest of the overhead(*-1 loop above) in…
shlr.w r2 ; (2)
shlr.w r2 ; (2)
shlr.w r2 ; (2)
shlr.w r2 ; (2) / 16 (for clock speed)
; aPulses(iPin) = iPinLoopCnt ; convert loop count to pulse width…
mov.w r2,@er3 ; Save away the value
; bMask = bMask & ~bMaskBit ; turn off waiting for this one…
or r1l,r1l ; (2) see if we are done or not
; wend
bne _PI7_WAIT_FOR_NEXT_IO_TO_GO_HIGH:16 ;(6)our mask has not gone to zero so wait for the next one.
_P17_RETURN_STATUS:
mov.b r1l,@BPULSETIMEOUT
; finally transisition back to basic and return.
return
;--------------------------------------------------------------------[/code]
I couldn’t understand one bit of that code, i only know c and basic x). I’ll see if i can get my hands on a ps2 version of the code, thanks for your input . stay tuned for more updates 