I've fixed an error in the code.
read comment.
When at least 2 channels have the same value there will
be no problems. Because the sorting cycle just changes the
array when numbers are in wrong place:
example: 1000 1000 1300 1400
current test number:1000
if current number > next number then swap
but 1000 is not > than 1000
so it will not change.
when all ch have the same value:
1000 1000 1000 1000
the B array values will be: [0,1,2,3]
------------------
'startup
counter var BYTE
Temp var byte
A var WORD[4]
B var byte[4]
trisa=0
trisb=0
for counter=0 to 3 'DONT delete!!!!
b[counter]=counter 'its for fill B[] on start up
next counter
'end of startup
a[0]=1000 'CH0 RB0 'assign any value between ~1000-2000uS->~1-2mS
a[1]=1430 'CH1 RB1 'in 1uS resolution!
a[2]=1321 'CH2 RB2
a[3]=1000 'CH3 RB3
'sorting routine (from Melanie)
'B[0] smallest, B[3] biggest
counter=0
SortLoop: 'dont delete this label,its for looping
If a[b[counter]] > a[b[counter+1]] then
Temp=b[counter]
b[counter]=b[counter+1]
b[counter+1]=Temp
If counter>0 then counter=counter-2
endif
counter=counter+1
If counter<3 then goto SortLoop
'end sorting of B index array
'this was 500-725 uS from start,depend a little on
'how much sorting (swapping) was needed
'next routine will be as long as the biggest ch value
'max 2mS + some uS
'Sendout:
high portb.0 'CH0
high portb.1 'CH1
high portb.2 'CH2
high portb.3 'CH3
pauseus a[b[0]] 'for the lowest ch, not for fix ch!
Portb.0(B[0])=0 'dont change!
'the above 2 lines cant be inserted into the For cycle,
'because it will couse for ever loops some times.
'the reason is counter-1 @counter=0, some times will not be 0 (maybe 255).
for counter=1 to 3 'for more channel replace 3
pauseus a[b[counter]]-a[b[counter-1]]
'calc delta times
Portb.0(B[counter])=0
'LOW portb# given back from B
next counter
'you need to redesign this send out routine
'when you reach the max portb port number (1-7)
'simply copy another FOR cycle
'for Porta like: For counter 1 to 7
end
---------------
Bookmarks