Searching \ for 'comparison routine' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=comparison+routine
Search entire site for: 'comparison routine'.

Truncated match.
PICList Thread
'comparison routine'
2000\03\22@214908 by Reginald Neale

flavicon
face
<x-flowed>Esteemed PIC Gurus:

Does anyone have a favorite way to do a window comparison on an A/D
result? Seems to me there was one here a week ago, but it has eluded
me.

What I want to do is to insert code in an existing loop that will set
an alarm output pin if the A/D result falls outside the window; set
another pin high if it is below the hard-coded lower limit, set a
different pin if it is above the upper limit, and continue on without
setting any of the three if the result is within the window.

TIA,
Reg Neale

</x-flowed>

2000\03\22@220311 by Tony Nixon

flavicon
picon face
Reginald Neale wrote:
>
> Esteemed PIC Gurus:
>
> Does anyone have a favorite way to do a window comparison on an A/D
> result? Seems to me there was one here a week ago, but it has eluded
> me.
>
> What I want to do is to insert code in an existing loop that will set
> an alarm output pin if the A/D result falls outside the window; set
> another pin high if it is below the hard-coded lower limit, set a
> different pin if it is above the upper limit, and continue on without
> setting any of the three if the result is within the window.
>
> TIA,
> Reg Neale

movf ADres,w
sublw UpLimit
btfss status,c
goto TooHigh

movlw LoLimit
subwf ADres,w
btfss status,c
goto TooLow


--
Best regards

Tony

http://www.picnpoke.com
spam_OUTsalesTakeThisOuTspampicnpoke.com

2000\03\23@070112 by Scott Dattalo

face
flavicon
face
On Thu, 23 Mar 2000, Tony Nixon wrote:

{Quote hidden}

If you're comparing against constants, why not do this:

 movf   ADres,w
 sublw  UpLimit            ;W = UpLimit - ADres
 skpc
  goto  TooHigh
 sublw  UpLimit-LoLimit    ;W = ADres - LoLimit
 skpc
  goto  TooLow

(You save a whole instruction!)


Example:

 ADres     LoLimit  UpLimit  (Up-AD)     (AD-Lo)
------------------------------------------------------
   9         4       10    10-9=>1,C=1     6-1=>5,C=1
   11        4       10    10-11=>ff,C=0    ----
   2         4       10    10-2=>8,C=1     6-8=>fe,C=0

C-Code:

GoldiLocks(unsigned char ADres)
{
  if(ADres>HiLimit)
    TooHigh();
  else if(ADres < LoLimit)
    TooLow();
  else
    JustRight();
}


Scott

2000\03\23@173029 by Andrew Warren

face
flavicon
face
Reginald Neale <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU> wrote:

> Does anyone have a favorite way to do a window comparison on an
> A/D result? .... What I want to do is to insert code in an existing
> loop that will set an alarm output pin if the A/D result falls
> outside the window; set another pin high if it is below the
> hard-coded lower limit, set a different pin if it is above the
> upper limit, and continue on without setting any of the three if
> the result is within the window.

Reg:

Try this; I haven't even assembled it, let alone tested it, but it
SHOULD work...

   MOVF    ADRES,W

   ADDLW   256-UPPER       ;These 4 lines were written by
   ADDLW   (UPPER-LOWER)+1 ;a smart guy named Eric Smith.
   SKPNC                   ;
   GOTO    DONE            ;

   ;Our A/D result was outside the [LOWER-UPPER] window.

   BSF     ALARMPIN        ;Set the ALARM pin.

   ADDLW   LOWER-1         ;Was ADRES too low?
   SKPC                    ;If so, skip ahead.
   BSF     HIGHPIN         ;Otherwise, set the HIGHPIN pin.
   SKPNC                   ;If ADRES was too high, skip ahead.
   BSF     LOWPIN          ;Otherwise, set the LOWPIN pin.

 DONE:

-Andy


=== Andrew Warren - fastfwdspamKILLspamix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499

2000\03\23@181124 by John Orhan
flavicon
face
Hi Andrew,
Could I ask what the intruction 'SKPNC' does? Is it skip if not carry?
Forgive my ignorance but I have not seen it before.


Regards John

               {Original Message removed}

2000\03\23@185153 by Tony Nixon

flavicon
picon face
Andrew Warren wrote:
>     MOVF    ADRES,W
>
>     ADDLW   256-UPPER       ;These 4 lines were written by
>     ADDLW   (UPPER-LOWER)+1 ;a smart guy named Eric Smith.
>     SKPNC                   ;
>     GOTO    DONE            ;

I got that technique out of the last Microchip seminar I went to :-)

--
Best regards

Tony

http://www.picnpoke.com
.....salesKILLspamspam.....picnpoke.com

2000\03\23@190021 by Andrew Warren

face
flavicon
face
John Orhan <EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU> wrote:

> Could I ask what the intruction 'SKPNC' does? Is it skip if not
> carry? Forgive my ignorance but I have not seen it before.

John:

Yeah, it means "skip if the carry flag is clear"; it's equivalent to

   BTFSC   STATUS,C

and it's always been supported by MPASM, although it hasn't always
been documented.  The latest MPASM/MPLAB User's Guides contain a
table showing this and all other pseudo-ops understood by MPASM;
here's the list:

          PIC16CXX SPECIAL INSTRUCTION MNEMONICS

    Name                Mnemonic       Equivalent       Status
                                      Operation(s)
Clear Carry                CLRC        BCF      3,0        -
Clear Digit Carry          CLRDC       BCF      3,1        -
Set Digit Carry            SETDC       BSF      3,1        -
Clear Zero                 CLRZ        BCF      3,2        -
Set Zero                   SETZ        BSF      3,2        -
Skip on Carry              SKPC        BTFSS    3,0        -
Skip on No Carry           SKPNC       BTFSC    3,0        -
Skip on Digit Carry        SKPDC       BTFSS    3,1        -
Skip on No Digit Carry     SKPNDC      BTFSC    3,1        -
Skip on Zero               SKPZ        BTFSS    3,2        -
Skip on Non Zero           SKPNZ       BTFSC    3,2        -
Test File                  TSTF f      MOVF     f,1        Z
Move File to W             MOVFW f     MOVF     f,0        Z
Negate File                NEGF f,d    COMF     f,1
                                      INCF     f,d        Z
Add Carry to File          ADDCF f,d   BTFSC    3,0
                                      INCF     f,d        Z
Subtract Carry from File   SUBCF f,d   BTFSC    3,0
                                      DECF     f,d        Z
Add Digit Carry to File    ADDDCF f,d  BTFSC    3,1
                                      INCF     f,d        Z
Subtract Digit             SUBDCF f,d  BTFSC    3,1
Carry from File                        DECF     f,d        Z
Branch                     B k         GOTO     k          -
Branch on Carry            BC k        BTFSC    3,0
                                      GOTO     k          -
Branch on No Carry         BNC k       BTFSS    3,0
                                      GOTO     k          -
Branch on Digit Carry      BDC k       BTFSC    3,1
                                      GOTO     k          -
Branch on No Digit Carry   BNDC k      BTFSS    3,1
                                      GOTO     k          -
Branch on Zero             BZ k        BTFSC    3,2
                                      GOTO     k          -
Branch on Non Zero         BNZ k       BTFSS    3,2
                                      GOTO     k          -
Call across page boundary  LCALL k     BCF 3,5 or BSF 3,5
                                      BCF 3,6 or BSF 3,6
                                      CALL     k

By the way, don't bother using the "LCALL" pseudo-op... Since it
doesn't restore the code-page bits after the CALL, it's sorta
useless.  Also, be careful with the pseudo-ops that assemble to two
instructions; constructs like the following, for instance, will cause
you great pain and suffering:

   ; DON'T DO THIS!

   BTFSS   FLAGS,SWITCH    ;If the switch is pressed, skip ahead.
   NEGF    REG             ;Otherwise, negate the REG register.

-Andy


=== Andrew Warren - fastfwdspamspam_OUTix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499

2000\03\23@191718 by John Orhan

flavicon
face
Hi Andrew,
Many thanks for your data on the extra instructions. Very interesting.


                               Regards John

               {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...