;test_ifposequaltrg has to be called before ;to make it sure, that curpos, and targepos is not ;equal ( done by STEP_WORK ) ;this should never be called, if positions are equal ;for this init_scanoffset should be runned after ;config1, to have a valid offsetbyte,offsetbit ;we use only the highest 4bits (16 segments)of a value, to ;decide which direction we will use ;offsetbyte contains nr of byte containing the highest bit of maxval ;offsetbit contains nr to rol ;spec_flags.OFFSET_ROLLEFT is set, or not to show direction to rol scan_direction BCF work_flags,RUN_LEFTDOWN,AC scandiroftb0 MOVLW 0x00 CPFSEQ offsetbyte,AC BRA scandiroftb1 MOVFF curpos0,rega0 MOVFF target0,regb0 CLRF rega1 ;byte 0 have no following byte CLRF regb1 ;so we use dummys BRA scandirbstart scandiroftb1 MOVLW 0x01 CPFSEQ offsetbyte,AC BRA scandiroftb2 MOVFF curpos1,rega0 MOVFF target1,regb0 MOVFF curpos0,rega1 MOVFF target0,regb1 BRA scandirbstart scandiroftb2 MOVLW 0x02 CPFSEQ offsetbyte,AC BRA scandiroftb3 MOVFF curpos2,rega0 MOVFF target2,regb0 MOVFF curpos1,rega1 MOVFF target1,regb1 BRA scandirbstart scandiroftb3 MOVFF curpos3,rega0 MOVFF target3,regb0 MOVFF curpos2,rega1 MOVFF target2,regb1 ;20 till here with call ;now, rega0,rega1 contains a 16bit value of currentpos ; regb0,regb1 of targetpos scandirbstart MOVF offsetbit,W,AC BZ scandirsetit ;for case last byte low-nibble, or not necessary MOVWF regc0,AC ;regc0 contains offsetbit BTFSC spec_flags,OFFSET_ROLLEFT,AC BRA scandirrleft scandirrright ;rol right RRNCF rega0,1,AC RRNCF regb0,1,AC ;thats all, the lower byte is for hell DECFSZ regc0,1,AC BRA scandirrright BRA scandirsetit scandirrleft ;rol left ;thats a bit more difficult, showing the overflow from lower byte RLCF rega0,1,AC RLCF rega1,1,AC BTFSC STATUS,C,AC BSF rega0,0x00,AC ;the same for target RLCF regb0,1,AC RLCF regb1,1,AC BTFSC STATUS,C,AC BSF regb0,0x00,AC DECFSZ regc0,1,AC BRA scandirrleft scandirsetit MOVLW 0x0f ANDWF rega0,1,AC ;rega0 contains section for current ANDWF regb0,1,AC ;regb0 contains section for target ;------------------------------------------------------------------- ;abs max. possible cycles used till here is 64 ( with 4 x rol left ) ;hmm looks good ;------------------------------------------------------------------- ;So, now we have valid sections, and have to compare it MOVF rega0,W,AC CPFSEQ regb0,AC ;compare sections together BRA scandirsection ;not equal, so we have scan sections. ;here both sections are equal, so we have a minimal differenc ;between current, and target, and both are not differed ;through under/overflow 0/360 degrees. ;we using a call to test_pos ;wich compares fro smaller,equal,greater, and ;sets flags: run_flags.RUN_LEFTDOWN, ;and work_flags POS_SMALLER,POS_GREATER,POS_EQUAL ;POS_EQUAL should normally never happens here, ;because the test for this is called previous ;by STEP_WORK, to decide is this work here ;necessary :-) CALL test_pos BTFSC work_flags,POS_GREATER,AC BSF work_flags,RUN_LEFTDOWN,AC ;if current pos greater, then target ;we have to go to left ;Now, we have the "shortest way" as possible. RETURN ;SO, here the max. possible value of cycles is ;71, + the call of test_pos (36 ) = 107 ( thats the worst case ) ;( better as the previous version of more then 800 :-) ;--------------------------------------------- scandirsection ;67 max poss. cycles till here with call ;the using of sections is useful, if target, on the ;other side of current. So we don't know if one of ;them affected to the under/overflow of 0/360 degrees ;So, we have split both circles to 16 sections, ;and defined in wich section every position is currently. ;If current section is diagonal to target section, ;we have not the "shortest" possible way in every case, ;but its as nearest to them as possible. To make ;it more sensible, by using more sections ( 32, or 64 ) ;is to hard for this poor processor-environment, and not necessary, ;because if we spare 22,5 degrees in the way, seems to be ;only for interrest when using very large circles. ;Such large instruments, can also pay a more sensible ;steering hard,- software :-) cur0_f BTFSC rega0,0x03,AC BRA cur8_f cur0_7 BTFSC rega0,0x02,AC BRA cur4_7 cur0_3 BTFSC rega0,0x01,AC BRA cur2_3 cur0_1 BTFSC rega0,0x00,AC BRA cur__1 cur__0 ;sector current 0 CALL cursecmatrix0 BRA scandirsecend cur__1 ;sector current 1 CALL cursecmatrix1 BRA scandirsecend cur2_3 BTFSC rega0,0x00,AC BRA cur__3 cur__2 ;sector current 2 CALL cursecmatrix2 BRA scandirsecend cur__3 ;sector current 3 CALL cursecmatrix3 BRA scandirsecend cur4_7 BTFSC rega0,0x01,AC BRA cur6_7 cur4_5 BTFSC rega0,0x00,AC BRA cur__5 cur__4 ;sector current 4 CALL cursecmatrix4 BRA scandirsecend cur__5 ;sector current 5 CALL cursecmatrix5 BRA scandirsecend cur6_7 BTFSC rega0,0x00,AC BRA cur__7 cur__6 ;sector current 6 CALL cursecmatrix6 BRA scandirsecend cur__7 ;sector current 7 CALL cursecmatrix7 BRA scandirsecend cur8_f BTFSC rega0,0x02,AC BRA curc_f cur8_b BTFSC rega0,0x01,AC BRA cura_b cur8_9 BTFSC rega0,0x00,AC BRA cur__9 cur__8 ;sector current 8 CALL cursecmatrix8 BRA scandirsecend cur__9 ;sector current 9 CALL cursecmatrix9 BRA scandirsecend cura_b BTFSC rega0,0x00,AC BRA cur__b cur__a ;sector current 10 CALL cursecmatrixa BRA scandirsecend cur__b ;sector current 11 CALL cursecmatrixb BRA scandirsecend curc_f BTFSC rega0,0x01,AC BRA cure_f curc_d BTFSC rega0,0x00,AC BRA cur__d cur__c ;sector current 12 CALL cursecmatrixc BRA scandirsecend cur__d ;sector current 13 CALL cursecmatrixd BRA scandirsecend cure_f BTFSC rega0,0x00,AC BRA cur__f cur__e ;sector current 14 CALL cursecmatrixe BRA scandirsecend cur__f ;sector current 15 CALL cursecmatrixf BRA scandirsecend ;to found the section for current ;all under 10 cycles max ;also for the target ;so we have 67 + 14 + 14 = 95 as worst case for sectionwork scandirsecend ;--------------------------------------------- RETURN ;the absolutely worst case for this is 107 cycles