Question 1: The calculated values range from 471 to 553. I plan to subtract 384 from each value to give 87 to 169. I chose 384 (256 +128) on a wild guess -- largest number less than 471 with only two 1's -- that it might speed the calculation. Would it be faster to subtract a one-byte number, say 235, twice?
DelayCy macro delay ; 12..327690 cycle range
movlw high((delay-12)/5)+1
movwf delayhi
movlw low((delay-12)/5)+1
movwf delaylo
call uDelay-((delay-12)%5)
endm
Note: These operators cannot be used with program variables. They are for use with directives only.
movlw low(table-471) ;
addwf resultlo,F ;
movlw high(table-471) ;
skpnc ;
addlw 1 ;
addwf resulthi,W ;
movwf PCLATH ;
movf resultlo,W ;
addwf PCL,F ;
;
;
I started this thread unaware that the arithmetic operators for the assembler could not be used with program instructions (See posts#8, 9 ) and have subsequently spent several hours reading about pre-processor routines (Olin Lathrop's PIC Development Tools looks interesting). I came back to Cleveland early just so I could play with them. One approach I might try with them is to get the concatenation done using shifts instead of rotates. Your suggestion for the look-up table is appreciated and will also be tried....simply add 'result' (471..553) to table address minus 471. You'd save one arithmetic operation by letting the assembler pre-processor do some of the work for you.
TableHigh
dt high(.7),high(.54),high(.97),high(.139),high(.177)
dt high(.12),high(.53),high(.92),high(.128),high(.162)
dt high(.16),high(.53),high(.87),high(.119),high(.149)
dt high(.21),high(.53),high(.83),high(.111),high(.136)
dt high(.26),high(.53),high(.79),high(.103),high(.125)
dt high(.30),high(.54),high(.76),high(.97),high(.115)
dt high(.35),high(.55),high(.74),high(.91),high(.106)
dt high(.39),high(.56),high(.72),high(.86),high(.98)
dt high(.44),high(.57),high(.70),high(.81),high(.92)
TableLow
dt low(.7),low(.54),low(.97),low(.139),low(.177)
dt low(.12),low(.53),low(.92),low(.128),low(.162)
dt low(.16),low(.53),low(.87),low(.119),low(.149)
dt low(.21),low(.53),low(.83),low(.111),low(.136)
dt low(.26),low(.53),low(.79),low(.103),low(.125)
dt low(.30),low(.54),low(.76),low(.97),low(.115)
dt low(.35),low(.55),low(.74),low(.91),low(.106)
dt low(.39),low(.56),low(.72),low(.86),low(.98)
dt low(.44),low(.57),low(.70),low(.81),low(.92)
;count_reg is now 0 - 0xff representing tan(angle) in the range 0 - 45 deg
;there is a lookup table for the values, 0x00, 0x40, 0x80, 0xC0 and 0x100
;the value looked up is 4 times the tan in degrees
;the values either side of the current tan are looked up
;the last 6 bits are multiplied by the difference in the lookup table
;we want the atan of the number /256
clrf count1
bcf status, carry
rlcf count_reg, f
rlcf count1, f
rlcf count_reg, f ;collect the top 2 bits and
rlcf count1, f ;multiply what is left by 4, because it will later be divided by 4
incf count1, f
rcall arc_tan_table ;Get a2=atan( (x>>6) + 1)
movwf count2 ;Store temporarily in count2
decf count1, f ;Get the saved index
rcall arc_tan_table ;Get a1=atan( (x>>6) )
subwf count2, w ;W=a2-a1, This is always positive.
subwf count2, f ;a1 = a1 - (a1-W) = W ;now count2 is the lower value and w is the difference
mulwf count_reg ;the difference is multiplied,
movf prodh, w ;take the high byte because we want the atan of input/256
addwf count2, w
mullw d'64'
movff prodh, count_reg ;divide by 4 so angle is now in count_reg
;This is the end of the code. The lookup table follows.
arc_tan_table
movlw high(atan_start)
movwf pclath
rlncf count1, w
addlw low (atan_start)
btfsc status, carry
incf pclath, f
movwf pcl
atan_start
retlw d'3'
retlw d'59'
retlw d'110'
retlw d'150' ;these are 4 times the arctan of the numbers
retlw d'182'
atan_end
Catenate ;Catenate quotient <12,5>
movlw b'00011111' ;mask off upper 3 bits of quotient high byte
andwf divid1,f
clrc
rlf divid1,f
rlf divid1,f
rlf divid1,f
movlw b'11100000' ;mask off lower 5 bits of quotient low byte
andwf divid0,f
swapf divid0,f ;exchange high and low nibbles
clrc
rrf divid0,f
movf divid1,w
addwf divid0,f ;combine high and low bytes into divid0
btfss divid0,7 ;check if divid0 is >d.127
goto Bin2BCD ;No, call Table for positive tilts
bsf status,1 ;Yes, set carry bit as flag
bcf divid0,7 ;subtract 128 because comf is limited to 0<=f<=127
comf divid0,f ;1's complement to "fold" table, only Z is affected by comf
bcf divid0,7
goto Bin2BCD ;call Table for tilt
1) Is there another processor you would recommend?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?