Searching \ for '[PIC]: tiny challenge ;)' 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/microchip/devices.htm?key=pic
Search entire site for: 'tiny challenge ;)'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: tiny challenge ;)'
2000\08\10@173344 by Tim Hamel

picon face
Yes, I got lost too. Please explain...


Tim H.

In a message dated 8/10/00 2:30:27 PM Pacific Daylight Time, spam_OUTjimTakeThisOuTspamJPES.COM
writes:

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]: PIC only [EE]: engineering [OT]: off topic [AD]: advertisements

2000\08\10@202453 by Bob Ammerman

picon face
How about this:

  00ab00cd
+00100010
---------------
 0aAb0cCd
&01010101
----------------
 0a0b0c0d
+01010101
----------------
aAbBcCdD


so, in code:

   ADDLW    B'00100010'
   ANDLW    B'01010101'
   ADDLW    B'01010101'

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)


{Original Message removed}

2000\08\11@081835 by Dmitry Kiryashov

flavicon
face
Hi Bob and Scott and other guys. ;)

> > How about this:
> > so, in code:
> >
> >     ADDLW    B'00100010'
> >     ANDLW    B'01010101'
> >     ADDLW    B'01010101'
>
> Excellent! Now I know I've been doing too much C/C++

Perfect! ;)

I got the same in two variations for pure W usage (without
additional temp cell) and another one with temp cell usage.

2nd variation is:

       addlw   0x66    ;00ab00cd -> aAAbcCCd
       andlw   0xDD    ;-> aA0bcC0d
       addlw   0x11    ;-> aAbBcCdD

And with temp cell:

       movwf   temp    ;00ab00cd
       iorlw   0x55    ;01a101c1
       addwf   temp,W  ;aAbBcCdD

Last one is useful for storing original W for futher usage.

And now the story about what practical usage it covers.

I've been asked to design some trick to reduce code execution time
for rise and fall edge events on some port pins.   For instance we
have two samples, previous byte x0 and current byte x1. Each holds
inside value like aAbBcCdD. As a result of playing with vetical
math I realized that:

a) (x0^x1)&x1 = X0&x1 , which is "1" in case of rise event only
b) (X0^X1)&X1 = x0&X1 , which is "1" in case of fall event only

where X0=!x0, Y0=!y0

Example:

;...                            ;W holds 00ab00cd
       movwf   temp            ;save it for
       iorlw   0x55            ;future usage
       addwf   temp,W          ;get aAbBcCdD

       xorwf   prev,W          ;put x1 byte to prev
       xorwf   prev,F          ;get x0^x1 byte into W
       andwf   prev,W          ;get edges a) and b)
       iorwf   edges,F         ;detected edges
;...

We will get "rises detected" flags in 7.5.3.1. (case a) and
"falls detected" flags in 6.4.2.0 (case b)

For instance edge can have a place somewhere within 10 samples
period, so instead of reading and analizing it each time you
can just accumulate it 10 times in edges cell and then analize
it only ones. (don't forget to reset edges flags after that ;)
Some clock saving anyway ;)

Probably someone can see another useful features of applying
aAbBcCdD view of 4 bits variable.

WBR Dmitry.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2000\08\11@084607 by Olin Lathrop

flavicon
face
> For instance edge can have a place somewhere within 10 samples
> period, so instead of reading and analizing it each time you
> can just accumulate it 10 times in edges cell and then analize
> it only ones. (don't forget to reset edges flags after that ;)
> Some clock saving anyway ;)

I didn't completely follow your explanation of what you were trying to do,
but the general theme seems to be looking for rising and falling edges on
input ports.

XORing the new value with the previous value yields a mask for all the
changed bits.  ANDing the result of that with the old value yields 1s for
all the falling edges, and ANDing with the new value yields 1s for all the
rising edges.  These falling and rising edge masks can be accumulated by
ORing them with previous versions if that's what you want to do.

This seems a lot simpler than your aAbB... scheme, but I may be missing what
your objective is.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, .....olinKILLspamspam@spam@cognivis.com, http://www.cognivis.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2000\08\11@103836 by Don Hyde

flavicon
face
Although it seems no longer relevant, since Bob Ammerman found a way to do
it with one less instruction (25% better!), I am reposting it since it seems
to have received one of the notorious, obnoxious colonic responses.

{Original Message removed}

2000\08\11@125349 by Dmitry Kiryashov

flavicon
face
Hi Olin.

> > For instance edge can have a place somewhere within 10 samples
> > period, so instead of reading and analizing it each time you
> > can just accumulate it 10 times in edges cell and then analize
> > it only ones. (don't forget to reset edges flags after that ;)
> > Some clock saving anyway ;)
>
> I didn't completely follow your explanation of what you were trying to do,
> but the general theme seems to be looking for rising and falling edges on
> input ports.

Ok. Brief explanation. You are to run 10 tasks "simultaneously". 4 of
them are
counting pulses (or reading some buses if you would like to ;) while 6
others
are some timing, converting information, sending and receiving RS232
stuff.
Each slice of code has some execution time t1,t2,t3,... You can run
everything
in straight way in one loop when one follows by another but you will got
total
loop execution time exactly equal to t1+t2+t3+...+t9+t10 which is
enormously huge ;)
Forgot to mention that those pulses of course are longer than 10
sampling periods.

But you can reduce it significantly if will run each task separately in
different
time slots. Timer constantly generates required slots. Two different
types of
processes: constant rate happened and floating. Sampling ports and doing
RS232
for instance are constant rate processes. Those should be sampled by
every pass
but finding edges can be scheduled for later. To reduce total time you
also need
to do finding edges in parallel for all 4 port pins. So you are just
collecting
information for analyzing it in later time. Total execution time in this
case of
every loop is no more than tC+tMAX where tC is time for driving/reading
constant
rate part of all process and tMAX is maximal execution time of longest
process.
Average execution time is reduced anyway. So applying this trick with
accumulating
first and executing later you can either do it faster or move this part
of code
into timer driven interrupt and forget about it (it becomes to be
transparent and
you don't care about low level programming anymore just playing with
flags, buffers
and semaphores on "high" level of art ;))

> XORing the new value with the previous value yields a mask for all the
> changed bits.  ANDing the result of that with the old value yields 1s for
> all the falling edges, and ANDing with the new value yields 1s for all the
> rising edges.  These falling and rising edge masks can be accumulated by
> ORing them with previous versions if that's what you want to do.

Anding that mask with inverted current bit also produces falling flag.
It's very easy to check. So you need to store only one variable (last
one)
and being exchanging it with a new one will have flags the same time.

> This seems a lot simpler than your aAbB... scheme, but I may be missing what
> your objective is.
Correct. I'm using the technique you are talking about together with
aAbB..

WBR Dmitry.

PS. Just check it now. a is previous and b is current.

(a^b)&b = A&b -> rising flag
(A^B)&B = a&B -> falling flag

                       ;W holds current
       xorwf   prev,W  ;update prev
       xorwf   prev,F  ;with new value
       andwf   prev,W  ;get flags

Got two kind of flags the same time ;)

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

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