thanks for the replies and code richard 
After i saw your first reply, i messed around a little and came up with this
Code:
DEFINE OSC 4
OSCCON = %01101010 ' Oscillator internal 4 mhz PLL disabled
CM1CON0.7 = 0 ' Comparator 1 off
CM2CON0.7 = 0 ' Comparator 2 off
CPSCON0.7 = 0 ' Capsense module off
MDCON = %00000000 ' Disable the Modulator
ANSELB = %00000000 ' Select no analog
TRISA=%00000000 ' Port A all output
TRISB=%00001001 ' Port B all output except 3 ,1
PulseArray var byte[80] ' 88 bytes 640 bits total
ArrayTail var word
GetThisPulse var word
Difference var word
Offset var word
Arraytail=0
GetThisPulse=0
Offset = 250 '(250)
' ---------- COLD START
' set all unused pins low
Low PortA.0
Low PortA.1
Low PortA.2
Low PortA.3
Low PortA.4
'Low PortB.0
Low PortB.1
Low PortB.2
Low PortB.4
Low PortB.5
Low PortB.6
Low PortB.7
Pause 25
clear
Arraytail=0
RunController:
PulseArray.0[Arraytail] = PortB.0 'set the last bit in the array as per b.0
if arraytail >= 639 then arraytail = 0 ' circle
Arraytail= Arraytail+1
latb.4 = !latb.4 ' use p4 to check loop time on scope
if offset > arraytail then
difference = offset-arraytail
GetThisPulse = 639 - difference
else
GetThisPulse = ArrayTail - offset
endif
latb.5 = PulseArray.0[GetThisPulse] ' output this bit
pauseus 300 ; adj to suit
goto RunController
it has compiled ok etc but I havent had time to scope it, but i think your second reply is a much cleaner and more practical solution
Bookmarks