I tried to use Melanie's great piece of code (Thanks !) for sorting the values I read with 12F675 ...
But the results are ...strange ; the schematic wont work as I wish.
It's something wrong in my code ? Thanks in advance !
Code:
CounterA var BYTE ' Just a BYTE Temporary working variable
DataW var WORD ' Just a WORD Temporary working variable
RawData var WORD [10] ' Array holding ADC Result
............
Main:
For CounterA=0 to 9
ADCON0 = %10001001
Pauseus 50 ' Wait for channel to setup
ADCON0.1 = 1 ' Start conversion
While ADCON0.1=1:Wend ' Wait for conversion
DataW.HighByte=ADRESH ' Read variable from ADC and save
DataW.LowByte=ADRESL
RawData(CounterA)=DataW
Next CounterA
gosub getsort
CounterA=0
if (ADvalue < 650) then
IF (ADvalue > 450) AND (ADvalue < 640) THEN gosub do_1
IF (ADvalue > 320) AND (ADvalue < 440) THEN gosub do_2
IF (ADvalue > 180) AND (ADvalue < 310) THEN gosub do_3
IF (ADvalue > 90) AND (ADvalue < 170) THEN gosub do_4
IF (ADvalue < 80) THEN gosub do_5
endif
Goto Main
;=========================
; here are the commands
GetSort:
If RawData(CounterA+1) < RawData(CounterA) then
DataW=RawData(CounterA)
RawData(CounterA)=RawData(CounterA+1)
RawData(CounterA+1)=DataW
If CounterA>0 then CounterA=CounterA-2
endif
CounterA=CounterA+1
If CounterA<9 then goto GetSort
DataW=0
For CounterA=2 to 9
DataW=DataW+RawData(CounterA)
Next CounterA
Advalue=DataW>>3
return
Bookmarks