Searching \ for '[PIC] Design Challenge: Find center of three value' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/devices.htm?key=pic
Search entire site for: 'Design Challenge: Find center of three value'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Design Challenge: Find center of three value'
2005\07\15@132612 by Mark Rages

face picon face
Here's a design challenge for you guys:

I have values in three file registers:  fileA, fileB, fileC.

I want to choose the value that's in the middle (numerically) and put it into W.

The brute-force way to do this would be to copy the list, sort the
copy in place, and choose the middle value.

I'm sure there's a more direct way.  Any ideas?

(Application:  This a simple nonlinear filter to remove occasional
outliers in a sampled data stream.)

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\07\15@132921 by Mark Rages

face picon face
On 7/15/05, Mark Rages <spam_OUTmarkragesTakeThisOuTspamgmail.com> wrote:
> Here's a design challenge for you guys:

I should add, I'm using the 14-bit 16F688.

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\07\15@133310 by Mark Rages

face picon face
Here's a design challenge for you guys:

I have values in three file registers:  fileA, fileB, fileC.

I want to choose the value that's in the middle (numerically) and put it into W.

The brute-force way to do this would be to copy the list, sort the
copy in place, and choose the middle value.

I'm sure there's a more direct way.  Any ideas?

(Application:  This a simple nonlinear filter to remove occasional
outliers in a sampled data stream.)

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\07\15@144433 by James Newtons Massmind

face picon face
Find the min, find the max, use the remaining value.

---
James.



{Quote hidden}

> -

2005\07\15@145723 by Dave W Turner

picon face
Well, no code atm., but:

Sort through list, on first item, put the item id in a temp register.
Next item, subtract from temp, if carry, it was bigger, so put the
item id in the same temp register.  Same for last item.  The temp
register now contains highest.  Do the same for all three, but with a
different temp register, and this time replace register is NOT
carried.  This will find the smallest.  Check both the first and
second register - the item id not in either is the middle.  This could
be done by making the temp registers the memory address of the item.
After you have found the highest and lowest items, use the indirect
register to clear them.  Then check which item, out of the 3 is not 0
(clear).

There is probably a better/quicker/simpler way, but that's how I'd do it.

On 7/15/05, Mark Rages <EraseMEmarkragesspam_OUTspamTakeThisOuTgmail.com> wrote:
{Quote hidden}

> -

2005\07\15@150308 by Dave W Turner

picon face
I got there first, AND posted an actual way of finding highest and lowest  ;-)

On 7/15/05, James Newtons Massmind <@spam@jamesnewtonKILLspamspammassmind.org> wrote:
> Find the min, find the max, use the remaining value.
>
> ---
> James.
>
>
>
> > {Original Message removed}

2005\07\15@161658 by Tom Smith

flavicon
face
You *could* set upper and lower limits and discard incoming values that fall
outside these limits. OTOH, any selection among A, B, C will involve three
comparisons; if you swap-if-greater following each comparison the process is
equivalent to a bubble sort anyway.

-----Original Message-----
From: KILLspampiclist-bouncesKILLspamspammit.edu [RemoveMEpiclist-bouncesTakeThisOuTspammit.edu]On Behalf Of
Mark Rages
Sent: Friday, July 15, 2005 1:26 PM
To: spamBeGonepiclistspamBeGonespammit.edu
Subject: [PIC] Design Challenge: Find center of three values

Here's a design challenge for you guys:

I have values in three file registers:  fileA, fileB, fileC.

I want to choose the value that's in the middle (numerically) and put it
into W.

<snip>


2005\07\15@162958 by Peter Onion

flavicon
face
On Fri, 2005-07-15 at 12:26 -0500, Mark Rages wrote:


> (Application:  This a simple nonlinear filter to remove occasional
> outliers in a sampled data stream.)

What is the probablility of two (or more) consecutive samples being
"outliers" because your method will let one through if that ever
happens ?

Peter

2005\07\15@165629 by Bob Blick

face picon face
How's this? I had to use a temp register though:

movf   file1,w
subwf  file2,w
btfsc  STATUS, C
goto   $ + 2
movf   file1,w
goto   $ + 1
movf   file2,w
movwf  temp
subwf  file3,w
btfsc  STATUS, C
goto   $ + 2
movf   file3,w
movwf  temp
movf   temp,w

Cheerful regards,
Bob Blick


{Quote hidden}

2005\07\15@165949 by Scott Dattalo

face
flavicon
face
Mark Rages wrote:
> Here's a design challenge for you guys:
>
> I have values in three file registers:  fileA, fileB, fileC.
>
> I want to choose the value that's in the middle (numerically) and put it into W.


  movf  fileB,W
  subwf fileA,W  ; W=A-B
  movf  fileB,W  ; assume B is larger
  skpnc          ; if Carry is clear then B is larger
   movf fileA,W  ; carry is set, so A is larger (or equal)

  movwf temp     ;temp = max(A,B)

  subwf fileC,W  ; compare C, W = C-max(A,B)
  movf  temp,W   ; assume max(A,B) > C
  skpnc          ;
   movf fileC,W  ; C is larger than the max(A,B)

  ; W = max(A,B,C)

If you don't want to use a temp then:

  movf  fileB,W
  subwf fileA,W  ; W=B-A
  movf  fileB,W  ; assume B is larger
  skpnc          ; if Carry is clear then B is larger
   movf fileA,W  ; carry is set, so A is larger

  subwf fileC,W  ; compare C
  skpnc          ;
   movf fileC,W  ; C is larger than the max(A,B)
  skpc
   subwf fileC,W ; W = C - (C-max(A,B)) = max(A,B)

  ; W = max(A,B,C)



If you can trash the registers, you can write:

  movf  fileB,W
  subwf fileA,F
  skpnc
   movf fileA,W

  subwf fileC,F
  skpnc
   movf fileC,W

This is of course untested and probably has bugs... but I believe the
approach works okay.

Scott

2005\07\15@185405 by Mark Rages

face picon face
On 7/15/05, Peter Onion <TakeThisOuTPeter.OnionEraseMEspamspam_OUTbtinternet.com> wrote:
> On Fri, 2005-07-15 at 12:26 -0500, Mark Rages wrote:
>
>
> > (Application:  This a simple nonlinear filter to remove occasional
> > outliers in a sampled data stream.)
>
> What is the probablility of two (or more) consecutive samples being
> "outliers" because your method will let one through if that ever
> happens ?
>
> Peter

The outliers are isolated, uncorrelated events: getting two in a row
would be very unlikely.

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\07\15@185525 by Mark Rages

face picon face
On 7/15/05, Scott Dattalo <RemoveMEscottspamTakeThisOuTdattalo.com> wrote:
> This is of course untested and probably has bugs... but I believe the
> approach works okay.
>
> Scott

These are approaches to obtaininx the maximum of three registers,
right?  My challenge is to find the median.

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\07\15@193719 by Bob Blick

face picon face
Actually when I rethink this, I was wrong. It picks file3 if file1 is the
middle value. Sorry.

-Bob

{Quote hidden}

> -

2005\07\15@195718 by Mark Rages

face picon face
On 7/15/05, Bob Blick <bblickEraseMEspam.....sonic.net> wrote:
> Actually when I rethink this, I was wrong. It picks file3 if file1 is the
> middle value. Sorry.
>
> -Bob
>

It's harder than it sounds.

I'll post my solution in a minute, once I'm satisfied it works.

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\07\15@202410 by Mark Rages

face picon face
On 7/15/05, Mark Rages <EraseMEmarkragesspamgmail.com> wrote:
> I'll post my solution in a minute, once I'm satisfied it works.

Well, I think it's working and it's quitting time, so here goes:

I started by listing all the possibilities:

A > B > C choose B
A > C > B choose C
B > A > C choose A
B > C > A choose C
C > A > B choose A
C > B > A choose B

I notice that there are really only three comparisons, if we ingnore
equality.  (After all, if A=B, it doesn't matter which I choose.)

So I made a mapping from the comparison result to the choice:

A>B | B>C | C>A | Choose
----+-----+-----+--------
1  |  1  |  0  | B
1  |  0  |  0  | C
0  |  1  |  0  | A
0  |  1  |  1  | C
1  |  0  |  1  | A
0  |  0  |  1  | B

Or, in decimal and numerical order:
comparison  | choose
------------+--------
  0        | X
  1        | B
  2        | A
  3        | C
  4        | C
  5        | A
  6        | B
  7        | X

But there's an interesting symmetry here: 3..0 is the same as 4..7.  This will
simplify my selection code.

Here's my code.  I used one temp register for the comparison result.

gteq macro fileA,fileB
       movfw fileB                ; w=B
       subwf fileA,w                ; w=A-B
       ;; if B>A we borrowed, so _borrow=0
       ;;  ... _borrow=1 means A>B or A==B

       ;; Tack the result on the right of the comparison register.
       rlf iris_adc_temp,f        ; '1'-> A>=B
       endm

abc_median macro A,B,C
       local done
       
       clrf comparison_temp

       ; do comparisons
       gteq A,B
       gteq B,C
       gteq C,A
       
       ;; fold around 4
       movfw comparison_temp
       btfsc comparison_temp,2        ; is >=4?
       sublw 0x07                ; yes. 4->3,5->2,6->1,7->0

       skpnz                   ; handle special case A=B=C
       movlw 0x01                ; in that case just choose any!

       movwf comparison_temp        
       
       ; Now select from A,B,C like this:
       ;; 1 -> B
       ;; 2 -> A
       ;; 3 -> C

       movfw A
       btfss comparison_temp,0        ; this bit clear: comparison_temp=2
       goto done

       movfw B
       btfss comparison_temp,1        ; this bit clear: comparison_temp=1
       goto done

       movfw C
done
       endm
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2005\07\15@215025 by Tom Smith

flavicon
face
cmp(A,B)
swapif(A>B)
cmp(B,C)
swapif(B>C)
cmp(A,B)
swapif(A>B)

B is middle value

-----Original Message-----
From: RemoveMEpiclist-bouncesEraseMEspamEraseMEmit.edu [RemoveMEpiclist-bouncesspam_OUTspamKILLspammit.edu]On Behalf Of
Mark Rages
Sent: Friday, July 15, 2005 8:24 PM
To: Microcontroller discussion list - Public.
Subject: Re: [PIC] Design Challenge: Find center of three values

On 7/15/05, Mark Rages <RemoveMEmarkragesTakeThisOuTspamspamgmail.com> wrote:
> I'll post my solution in a minute, once I'm satisfied it works.

Well, I think it's working and it's quitting time, so here goes:

I started by listing all the possibilities:

A > B > C choose B
A > C > B choose C
B > A > C choose A
B > C > A choose C
C > A > B choose A
C > B > A choose B

I notice that there are really only three comparisons, if we ingnore
equality.  (After all, if A=B, it doesn't matter which I choose.)

<snip>


2005\07\15@232804 by Andrew Warren

face
flavicon
face
Scott Dattalo <EraseMEpiclistspamspamspamBeGonemit.edu> wrote:

>    movf  fileB,W
>    subwf fileA,W  ; W=A-B
>    movf  fileB,W  ; assume B is larger
>    skpnc          ; if Carry is clear then B is larger
>     movf fileA,W  ; carry is set, so A is larger (or equal)
>
>    movwf temp     ;temp = max(A,B)
>
>    subwf fileC,W  ; compare C, W = C-max(A,B)
>    movf  temp,W   ; assume max(A,B) > C
>    skpnc          ;
>     movf fileC,W  ; C is larger than the max(A,B)
>
>    ; W = max(A,B,C)

Scott:

You can do it quicker... Here's the "min" code from my web page; it's
easily modified to compute max:

       MOVF    NUM1,W  ;Set the Carry flag if NUM1 is
       SUBWF   NUM2,W  ;less than NUM2.

       MOVF    NUM1,W  ;Assume that NUM1 was less than
                       ;NUM2.  This instruction does
                       ;NOT affect the Carry flag.

       SKPC            ;If NUM1 really was less than
                       ;NUM2, skip ahead with W = NUM1.

       MOVF    NUM2,W  ;Otherwise, W = NUM2.

   ;At this point, W contains min(NUM1,NUM2).

       MOVWF   RESULT  ;Store it in RESULT.

   ;At this point, both W and RESULT contain min(NUM1,NUM2).

       SUBWF   NUM3,W  ;Set the Carry flag if W [which
                       ;still contains min(NUM1,NUM2)]
                       ;is less then NUM3.

   ;At this point, RESULT still holds min(NUM1,NUM2),
   ;but W now contains NUM3 - min(NUM1,NUM2).

       SKPC            ;If W really was less than NUM3,
                       ;skip ahead.

       ADDWF   RESULT  ;Otherwise,
                       ;RESULT=RESULT + W
                       ;      =min(N1,N2) + W
                       ;      =min(N1,N2) + [N3-min(N1,N2)]
                       ;      =N3.
                       ;

   ;At this point, RESULT holds min(NUM3,min(NUM1,NUM2)),
   ;which is of course equivalent to min(NUM1,NUM2,NUM3).

Of course, we're supposed to find the median rather than min or max,
so how about this?

   MOVF    REGA,W    ;Copy from REGA-REGC to
   MOVWF   TEMP1     ;TEMP1, TEMP2, and MEDIAN.
   MOVF    REGB,W    ;
   MOVWF   TEMP2     ;
   MOVF    REGC,W    ;
   MOVWF   MEDIAN    ;

   SUBWF   TEMP2,W   ;TEMP2 >= MEDIAN?
   BC      $+3       ;If so, skip ahead.
   ADDWF   MEDIAN    ;Otherwise, swap MEDIAN and
   SUBWF   TEMP2     ;TEMP2.

   MOVF    TEMP1,W   ;MEDIAN >= TEMP1?
   SUBWF   MEDIAN,W  ;
   SKPC              ;If so, skip ahead.
   SUBWF   MEDIAN    ;Otherwise, MEDIAN = TEMP1.

   MOVF    MEDIAN,W  ;TEMP2 >= MEDIAN?
   SUBWF   TEMP2,W   ;
   SKPC              ;If so, skip ahead.
   ADDWF   MEDIAN    ;Otherwise, MEDIAN = TEMP2.

19 words, 18 or 19 cycles.

-Andy

=== Andrew Warren - RemoveMEfastfwdKILLspamspamix.netcom.com

2005\07\15@233515 by Andrew Warren

face
flavicon
face
Oops, we don't need to copy REGA, so it can be done even faster:

   ; Find median of REGA, REGB, REGC.

   MOVF    REGB,W    ;TEMP2 = REGB.
   MOVWF   TEMP2     ;
   MOVF    REGC,W    ;MEDIAN = REGC.
   MOVWF   MEDIAN    ;

   SUBWF   TEMP2,W   ;TEMP2 >= MEDIAN?
   BC      $+3       ;If so, skip ahead.
   ADDWF   MEDIAN    ;Otherwise, swap MEDIAN and
   SUBWF   TEMP2     ;TEMP2.

   MOVF    REGA,W   ;MEDIAN >= REGA?
   SUBWF   MEDIAN,W  ;
   SKPC              ;If so, skip ahead.
   SUBWF   MEDIAN    ;Otherwise, MEDIAN = TEMP1.

   MOVF    MEDIAN,W  ;TEMP2 >= MEDIAN?
   SUBWF   TEMP2,W   ;
   SKPC              ;If so, skip ahead.
   ADDWF   MEDIAN    ;Otherwise, MEDIAN = TEMP2.

17 words, 16 or 17 cycles.

-Andy

=== Andrew Warren - fastfwdSTOPspamspamspam_OUTix.netcom.com

------- End of forwarded message -------
=== Andrew Warren - spamBeGonefastfwdSTOPspamspamEraseMEix.netcom.com

2005\07\16@005050 by Scott Dattalo

face
flavicon
face

On Fri, 2005-07-15 at 20:37 -0700, Andrew Warren wrote:

{Quote hidden}

Looks good to me. There's away to make it 17-instructions and 17-cycles,
but it's not too interesting. I don't know what I was thinking earlier - I
guess I've been smoking too many virtual functions here lately!

Scott

2005\07\16@012355 by Andrew Warren

face
flavicon
face
Scott Dattalo <KILLspampiclistspamBeGonespammit.edu> wrote:

> I don't know what I was thinking earlier - I guess I've been
> smoking too many virtual functions here lately!

Dude:

Assembly = the win.  C++ = the suck.

-Andy

P.S. Here's some better commenting (and more-descriptive register
naming):

   ; Find median of REGA, REGB, REGC.
   ; 17 words, 17 or 18 cycles.
   ;
   ; Throughout these comments, I'll be using A, B, and C as
   ; shorthand for REGA, REGB, and REGC.  Also, the "greater
   ; than" signs in the comments really represent "greater-
   ; than-or-equal"... But that doesn't matter for our
   ; purposes, since the median is B whether the inequality
   ; is A<B<C or A<=B<=C.

   ; Start by assuming that A < B < C, so max(B,C) is assumed
   ; to be C and median is assumed to be B.

       MOVF    REGC,W    ;MAXBC = REGC.
       MOVWF   MAXBC     ;
       MOVF    REGB,W    ;MEDIAN = REGB.
       MOVWF   MEDIAN    ;

       SUBWF   MAXBC,W   ;MAXBC >= MEDIAN?
                         ;[i.e., C > B]?

       BC      MAXBC_OK  ;If so, our assumption about
                         ;MAXBC was correct, so jump ahead.

       ADDWF   MEDIAN    ;Otherwise, swap MEDIAN and
       SUBWF   MAXBC     ;MAXBC.

   ; At this point, MAXBC = max(B,C) and MEDIAN = min(B,C).

   MAXBC_OK:

       MOVF    REGA,W    ;MEDIAN >= REGA?
       SUBWF   MEDIAN,W  ;[i.e., A = min(A,B,C)]?

       SKPC              ;If so, A can't be the median,
                         ;so skip ahead.

       SUBWF   MEDIAN    ;Otherwise, MEDIAN = REGA.

   ; At this point, MEDIAN holds max(A,min(B,C)) and MAXBC
   ; still holds max(B,C)].
   ;
   ; It's fortunate that we have those values stored,
   ; because...
   ;
   ; If A<B<C:  MEDIAN = B, MAXBC = C, median = B = MEDIAN
   ; If A<C<B:  MEDIAN = C, MAXBC = B, median = C = MEDIAN
   ; If B<A<C:  MEDIAN = A, MAXBC = C, median = A = MEDIAN
   ; If B<C<A:  MEDIAN = A, MAXBC = C, median = C = MAXBC
   ; If C<A<B:  MEDIAN = A, MAXBC = B, median = A = MEDIAN
   ; If C<B<A:  MEDIAN = A, MAXBC = B, median = B = MAXBC
   ;
   ; In other words... If A is the largest of the three
   ; numbers, the median is MAXBC [max(B,C)], otherwise the
   ; median is MEDIAN [max(A,min(B,C))].

       MOVF    MEDIAN,W  ;MAXBC >= MEDIAN? [i.e.,
       SUBWF   MAXBC,W   ;max(A,B,C)) != A?]

       SKPC              ;If so, median = max(A,min(B,C)),
                         ;which is already stored in MEDIAN,
                         ;so skip ahead.

       ADDWF   MEDIAN    ;Otherwise, median = max(B,C),
                         ;which is stored in MAXBC, so
                         ;MEDIAN = MAXBC.

   ; At this point, MEDIAN holds median(A,B,C).

It's funny... With those comments, the code doesn't look at all like
what it really is, which is just a three-element bubble-sort with all
the unnecessary register-swapping removed.

=== Andrew Warren - EraseMEfastfwdspamEraseMEix.netcom.com

2005\07\16@165648 by Scott Dattalo

face
flavicon
face
On Fri, 2005-07-15 at 22:26 -0700, Andrew Warren wrote:
Scott Dattalo <@spam@piclist@spam@spamspam_OUTmit.edu> wrote:
>
> > I don't know what I was thinking earlier - I guess I've been
> > smoking too many virtual functions here lately!
>
> Dude:
>
> Assembly = the win.  C++ = the suck.
>

:)

> P.S. Here's some better commenting (and more-descriptive register
> naming):

<snip>

And here's a brute-force version that is a little faster, but takes more
instructions:

23 instructions,   10-15 Cycles - average 13 (which is one cycle too many
- there must be a way to get this to 12 cycles!)

  movf  REGA,W
  subwf REGB,W   ; W=B-A
  skpc
   goto L_A_GT_B

  ; B>=A

  movf  REGA,W
  subwf REGC,W   ; W=C-A
  skpc
   goto L_AisMedian ; B>=A>=C

  ; B>=A, C>A

  movf  REGB,W
  subwf REGC,W   ; W=C-B
  movf  REGC,W   ; Assume C is the median
  skpnc
L_BisMedian:
   movf REGB,W   ;
  goto  done

L_A_GT_B:
  ; A>B

  movf  REGB,W
  subwf REGC,W   ; W=C-B
  skpc
   goto L_BisMedian ; A>B>C

  ; A>B, C>=B

  movf  REGA,W
  subwf REGC,W   ; W=C-A
  movf  REGC,W
  skpnc
L_AisMedian:
   movf REGA,W   ; C>A>B

done:


Scott

2005\07\16@170148 by Peter

picon face

On Fri, 15 Jul 2005, Scott Dattalo wrote:

> If you can trash the registers, you can write:
>
>  movf  fileB,W
>  subwf fileA,F
>  skpnc
>   movf fileA,W
>
>  subwf fileC,F
>  skpnc
>   movf fileC,W

       movf        fileB,w ; w=b
       subwf        fileA,f ; a=a-b : a>=b : C=0, want b
       skpnc
         movf fileA,w   ; w=a-b ?!

       subwf fileC,f        ; c=c-a+b ?!
       skpnc
        movf fileC,w        ; w=c-a+b ?!
       ; w=b or w=a-b or w=c-a+b

Maybe I made a mistake but I think that there is an error. Without
thrashing one could use a proper goto and one more test case. It looks
like 12 instructions with that ? ;-)

Peter

2005\07\17@121244 by Dmitriy Kiryashov

picon face
Hi Mark.

You got the same idea as I got when looked at your first post
ten minutes ago :) Shift all carries into temp first.
Ok, here is straightforward coding.

       movfw        fileC                ;1
       subwf        fileB,w                ;2
       rlf        temp,F                ;3

       movfw        fileA                ;4
       subwf        fileC,w                ;5
       rlf        temp,F                ;6

       movfw        fileB                ;7
       subwf        fileA,w                ;8

Indeed table is simmetrical, so we can reduce it by half


 Cy  temp.1 temp.0
> A>B | B>C | C>A | Choose
> ----+-----+-----+--------
>  1  |  1  |  0  | B
>  1  |  0  |  0  | C
>  0  |  1  |  0  | A
>  0  |  1  |  1  | C
>  1  |  0  |  1  | A
>  0  |  0  |  1  | B

       skpnc                        ;9
       comf        temp,F                ;10

> A>B | B>C | C>A | Choose
> ----+-----+-----+--------
>  0  |  1  |  0  | A
>  0  |  1  |  1  | C
>  0  |  0  |  1  | B

Now let's decrement it by one

       decf        temp,F                ;11

> A>B | B>C | C>A | Choose
> ----+-----+-----+--------
>  0  |  0  |  1  | A
>  0  |  1  |  0  | C
>  0  |  0  |  0  | B


Here comes the result

       movfw        fileB                ;12
       btfsc        temp.0                ;13
       movfw        fileA                ;14
       btfsc        temp.0                ;15
       movfw        fileC                ;16


Code hasn't been tested thought and looks like there should be way
to squeeze it 4 instructions less :) Guess I'm getting old and lazy :)


WBR Dmitry.


PS.  Scott you always were good at finding bugs :)





Mark Rages wrote:
{Quote hidden}

> -

2005\07\17@153728 by Dmitriy Kiryashov

picon face
Misprints and corrections.


Dmitriy Kiryashov wrote:
{Quote hidden}

    1  |  1  |  1  | any
    0  |  0  |  0  | any

{Quote hidden}

    0  |  0  |  0  | any

{Quote hidden}

    1  |  1  |  1  | any

>
> Here comes the result
>
>         movfw   fileB           ;12
>         btfsc   temp,0          ;13
>         movfw   fileA           ;14

         btfsc   temp,1          ;15

{Quote hidden}


'[PIC] Design Challenge: Find center of three value'
2006\01\19@053905 by Jan-Erik Soderholm
face picon face
I think there was a thread 6-10 months ago on this subject.
Check the piclist archives...

Jan-Erik.



2006\01\19@101113 by Bob Axtell

face picon face
Mark Rages wrote:

>Here's a design challenge for you guys:
>
>I have values in three file registers:  fileA, fileB, fileC.
>
>I want to choose the value that's in the middle (numerically) and put it into W.
>
>The brute-force way to do this would be to copy the list, sort the
>copy in place, and choose the middle value.
>
>I'm sure there's a more direct way.  Any ideas?
>
>(Application:  This a simple nonlinear filter to remove occasional
>outliers in a sampled data stream.)
>
>Regards,
>Mark
>markrages@gmail
>  
>
Your clock is set to July 2005, Mark.

--
Note: To protect our network,
attachments must be sent to
TakeThisOuTattach.....spamTakeThisOuTengineer.cotse.net .
1-520-850-1673 USA/Canada
http://beam.to/azengineer

2006\01\19@102657 by Mark Rages

face picon face
On 1/19/06, Bob Axtell <TakeThisOuTengineerKILLspamspamspamcotse.net> wrote:
{Quote hidden}

It's an old thread.  The application I referred to is in full
production right now.

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2006\01\19@103444 by Jan-Erik Soderholm

face picon face
Mark Rages wrote :

> It's an old thread.  The application I referred to is in full
> production right now.

You mean you didn't send this now ?
That might explain why I thought I'd seen
it before... :-)

Jan-Erik.



2006\01\19@113853 by Howard Winter

face
flavicon
picon face
Jan-Erik,

On Thu, 19 Jan 2006 16:34:39 +0100 (MET), Jan-Erik
Soderholm wrote:

> Mark Rages wrote :
>
> > It's an old thread.  The application I referred to
is in full
> > production right now.
>
> You mean you didn't send this now ?
> That might explain why I thought I'd seen
> it before... :-)

You aren't the only one - it arrived here a day or two
ago, dated July.  Either Mark's system re-sent it for
some reason, or it's been hanging around on some
street-corner of the Internet with its gang for the past
6 months...

Cheers,


Howard Winter
St.Albans, England


2006\01\19@115727 by John Nall

picon face
Howard Winter wrote:
> You aren't the only one - it arrived here a day or two ago, dated
> July. Either Mark's system re-sent it for some reason, or it's been
> hanging around on some street-corner of the Internet with its gang for
> the past 6 months..

It arrived here only this morning (but dated July).  I always keep my
inbox on Thunderbird cleared after I have read the messages, either by
deleting the ones that have been read, or by moving them to another
folder.  So it definitely popped into the inbox just this morning.  
Wonder where that puppy has been hanging out???  :-)

2006\01\19@121822 by Alan B. Pearce

face picon face
>So it definitely popped into the inbox just this morning.
>Wonder where that puppy has been hanging out???  :-)

In a sandbox somewhere?

Sorry couldn't resist after the recent discussion on CVS in its various
forms ...

2006\01\19@121835 by Bob Axtell

face picon face
John Nall wrote:

>Howard Winter wrote:
>  
>
>>You aren't the only one - it arrived here a day or two ago, dated
>>July. Either Mark's system re-sent it for some reason, or it's been
>>hanging around on some street-corner of the Internet with its gang for
>>the past 6 months..
>>    
>>
>
>It arrived here only this morning (but dated July).  I always keep my
>inbox on Thunderbird cleared after I have read the messages, either by
>deleting the ones that have been read, or by moving them to another
>folder.  So it definitely popped into the inbox just this morning.  
>Wonder where that puppy has been hanging out???  :-)
>
>  
>
Yes, it JUST arrived.

Homeland security up to their old tricks again, I guess. They delayed
some encrypted
firmware code for 6 weeks once.

--Bob

--
Note: To protect our network,
attachments must be sent to
.....attachspamRemoveMEengineer.cotse.net .
1-520-850-1673 USA/Canada
http://beam.to/azengineer

2006\01\19@124511 by James Humes

picon face
I read about Richard Feynman and his girlfriend, during his time at Los
Alamos, going out of their way to come up with more and more complicated
cyphers for their personal letters to give the security guys a hard time.
Sounded fun.  I wonder what kind of heat you'd draw by sending a lot of
encrypted emails to the Middle East.

James


On 1/19/06, Bob Axtell <RemoveMEengineerspamspamBeGonecotse.net> wrote:
{Quote hidden}

> -

2006\01\19@131902 by James Newton, Host

face picon face
Please keep the topic to PICs when the topic tag is [PIC] or change the
topic to [OT] if the discussion wanders off to other things.

---
James Newton: PICList webmaster/Admin
TakeThisOuTjamesnewtonspamspampiclist.com  1-619-652-0593 phone
http://www.piclist.com/member/JMN-EFP-786
PIC/PICList FAQ: http://www.piclist.com




> I read about Richard Feynman and his girlfriend, during his

> > >>You aren't the only one - it arrived here a day or two ago, dated

> > >It arrived here only this morning (but dated July).  I

> > Yes, it JUST arrived.

> > Homeland security up to their old tricks again, I guess.

2006\01\19@201744 by Dan Wonacott

flavicon
face
I don't think there's a cunning way to do it.  It demands a minimum of 2
comparisons, max 3. Sorting 4 or more you'd want to use a function call or
you'd have a lot of messy and confusing code (this is confusing enough).
Best pseudo code I can do:

                 IF B >= A GOTO BA
                 IF C >= A GOTO A                ; A > B if C >= A then C
>= A > B
                 IF C >= B GOTO C                ; A > B and A > C if C >=
B  then A > C >= B
                                                                 ; A > B, A
> C and B > C therefore A > B > C
B               ANSWER B
                 GOTO END
BA             IF C >= A GOTO BACA        ; B >= A
                                                                 ; B >= A >
C
A               ANSWER A
                 GOTO END
BACA       IF C >= B GOTO B                 ; B > A, C > A if C >= B then C
>= B > A
                                                                 ; B > A, C
> A and B > C therefore B > C > A
C               ANSWER C
END

Regards,

Dan


{Original Message removed}

2006\01\19@203323 by Mark Rages

face picon face
On 1/19/06, Dan Wonacott <danEraseMEspamwonacott.com> wrote:
{Quote hidden}

Yeah, that's pretty much the answer I came up with last time.
(Somehow this thread from July 2005 just got reposted. I have no idea
how...)  If you found this to be an interesting problem, look back at
the piclist archives around July 15, 2005. There were some good
responses.

Regards,
Mark
markrages@gmail
--
You think that it is a secret, but it never has been one.
 - fortune cookie

2006\01\20@052329 by Dmitriy Kiryashov

picon face
Hi Mark.

I've kind of got "deja vu" feeling seeing that post from you again :)


WBR Dmitry.

PS. PICLIST archieve should have all that thread with solutions.


Mark Rages wrote:
{Quote hidden}

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