.def VectL = r09 ; Vector lenght low .def VectM = r10 ; Vector lenght mid .def VectH = r11 ; Vector lenght high .def ADC3L = r12 ; ADC low Byte oldest value .def ADC3H = r13 ; ADC high Byte oldest value .def ADC2L = r14 ; ADC low Byte last value .def ADC2H = r15 ; ADC high Byte last value .def ADC1L = r16 ; ADC low Byte most recent value .def ADC1H = r17 ; ADC high Byte most recent value .def TempL = r23 ; general temporary register (low) .def TempM = r24 ; general temporary register (mid) .def TempH = r25 ; general temporary register (high) ;************************************************************************* ;* ... computes vector lenght from last two measurements. ;* Squareroot of (X^2 + Y^2) is approximated by : ;* (larger one of X,Y) + 106/256 * (smaller one of X,Y) ;* 106/256 is an approximation of Sqrt(2)-1 = 0.4142 ;* so the circle is approximated by its inscribed eight corner area ;************************************************************************* cp ADC3H,ADC2H ; (1) find larger value brlo Lo3 ; (1+1) brne Hi3 ; (1+1) if equal cp ADC3L,ADC2L ; (1) compare low bytes brlo Lo3 ; (1+1) Hi3: set ; (1) T-flag=H -> ADC3 >= ADC2 mov TempM,ADC2H ; (1) mov TempL,ADC2L ; (1) rjmp By106 ; (2) Lo3: clt ; (1) T-flag=L -> ADC3 < ADC2 mov TempM,ADC3H ; (1) mov TempL,ADC3L ; (1) By106: clr TempH ; (1) multiply smaller value by 106 lsl TempL ; (1) 106 = 2+8+32+64 rol TempM ; (1) = "*2" mov VectL,TempL ; (1) mov VectM,TempM ; (1) add to vector clr VectH ; (1) lsl TempL ; (1) rol TempM ; (1) lsl TempL ; (1) rol TempM ; (1) = "*8" add VectL,TempL ; (1) adc VectM,TempM ; (1) add to vector lsl TempL ; (1) rol TempM ; (1) lsl TempL ; (1) rol TempM ; (1) = "*32", high byte = 0 add VectL,TempL ; (1) adc VectM,TempM ; (1) add to vector lsl TempL ; (1) rol TempM ; (1) = "*64" rol TempH ; (1) now we need a 3rd byte add VectL,TempL ; (1) adc VectM,TempM ; (1) add to vector adc VectH,TempH ; (1) brts x ; (1+1) add VectM,ADC2L ; (1) adc VectH,ADC2H ; (1) rjmp y ; (2) x: add VectM,ADC3L ; (1) adc VectH,ADC3H ; (1) nop ; (1) y: mov ADC3L,ADC2L ; (1) mov ADC3H,ADC2H ; (1)