Searching \ for '[PIC]: Count processor cycles in simple delay' 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/time.htm?key=delay
Search entire site for: 'Count processor cycles in simple delay'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Count processor cycles in simple delay'
2003\02\03@035503 by Ivan Dachev

flavicon
face
Hello PICLIST,

I found one delay routine in which I think it has errors

the code and explanation is here

http://techref.massmind.org/techref/piclist/weedfreq.htm

I have one question for this part of code from WCT5.ASM:

;
int_del movlw   0x05            ;delay 5.000 ms (4 MHz clock)
       movwf   count1
d1      movlw   0xA5
       movwf   count2
d2      decfsz  count2  ,f
       goto    d2
       decfsz  count1  ,f
       goto    d1
       retlw   0x00

Why in comment it is said that this delay is 5 ms while actually it is
2.5ms ?

I make my one calculation here it is (processor cycles is in '()' ):

int_del movlw   0x05        (1)
       movwf   count1      (1)

       ;494 + 2
d1      movlw   0xA5        (1)
       movwf   count2      (1)

       ;this is for 3 cycles * 0xA5(165) = 495 -1 -this is for last
       ;iteration
d2      decfsz  count2  ,f  (1) (2)
       goto    d2          (2)  |

       ;494 + 2 + 3   = 499
       decfsz  count1  ,f  (1) (2)
       goto    d1          (2)  |

       ;499 * 5 -1 (for last iteration) =
       ;2494 + 2(first two instruction) + 2(return) = 2498
       retlw   0x00        (2)

if we add 2 for call of this delay function the processor cycles are
2500 * 1000uS = 2.500 ms not 5.000 ms !

If I'm wrong please say to me what I do wrong in my calculation.


--
Best regards,
Ivan                          spam_OUTi_dachevTakeThisOuTspamprosyst.bg

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\02\03@041409 by Jinx

face picon face
> Why in comment it is said that this delay is 5 ms while
> actually it is 2.5ms ?

> If I'm wrong please say to me what I do wrong in my calculation.

It is only 2.5ms. Probably the code was originally 5ms and
changed for some reason but the comment was overlooked

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\02\14@053552 by Eric Bohlman

picon face
2/3/03 3:14:28 AM, Jinx <.....joecolquittKILLspamspam@spam@CLEAR.NET.NZ> wrote:

>> Why in comment it is said that this delay is 5 ms while
>> actually it is 2.5ms ?
>
>> If I'm wrong please say to me what I do wrong in my calculation.
>
>It is only 2.5ms. Probably the code was originally 5ms and
>changed for some reason but the comment was overlooked

Unfortunately a very common problem; a good habit to develop is always reading each comment near a
piece of code that you've changed and making sure that it's still correct.

IIRC, Kernighan and Plauger's _The Elements of Programming Style_ showed an example of some Fortran
code that defined a symbolic constant named THREE.  Needless to say, its actual value was 2.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@074113 by Wouter van Ooijen

face picon face
> IIRC, Kernighan and Plauger's _The Elements of Programming
> Style_ showed an example of some Fortran
> code that defined a symbolic constant named THREE.  Needless
> to say, its actual value was 2.

That is for sissies. I recall a story about some system (I think it was
either Fortran or LISP, but it might have been a urban legend) where a
program like this would print 2:

procedure p( x ){
  x = 2
}

p( 9 )
print( 9 )

Now *that* is serious programming :(

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@083422 by Olin Lathrop

face picon face
> Unfortunately a very common problem; a good habit to develop is always
reading each comment near a
> piece of code that you've changed and making sure that it's still
correct.
>
> IIRC, Kernighan and Plauger's _The Elements of Programming Style_ showed
an example of some Fortran
> code that defined a symbolic constant named THREE.  Needless to say, its
actual value was 2.

When I was a freshman in college, I was working on a minicomputer system
that was used by grad students for research.  One of the grad students, a
real smart guy but notorious for kludges, had written a bunch of
independent modules for doing some image processing.  Some time later he
needed a global flag that would modify the operation of several of the
modules.  This was all written in assembler, and he certainly could have
declared a global variable, initialized it in some main module, and used a
bit in it as a flag.  For whatever reason I never did understand, he
decided it was more expedient to change the value of a literal constant,
since they were all system-wide global by definition.  That's bad enough,
but instead of picking an obscure literal value that nothing else was
likely to use, he picked 5.  When 5 = 5 then the flag was initialized.
When 5 was actually zero the flag was set.  Needless to say, this enhanced
his already considerable reputation as a kludger (and I didn't let him
anywhere near my code).


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body

2003\02\14@085747 by michael brown

picon face
Wouter wrote:

> > IIRC, Kernighan and Plauger's _The Elements of Programming
> > Style_ showed an example of some Fortran
> > code that defined a symbolic constant named THREE.  Needless
> > to say, its actual value was 2.
>
> That is for sissies. I recall a story about some system (I think it
was
{Quote hidden}

I used to program in assembly on a mainframe.  The assembler would
automatically build a constants area (called a literal pool) when you
used a string or numeric constant as the operand.  In an attempt to be
efficient the assembler would combine multiple references to the same
constant into just one.  There is an instruction "LDAC" which loads the
accumulator and clears the memory location that is being loaded from.
You should be able to guess at this point what happened when you said
"LDAC   =5".  I hope you weren't planning on loading any more 5's.  ;-)
Of course some people thought it cute to take advantage of this
"feature".  :-((

michael

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

2003\02\19@202137 by William Chops Westfield

face picon face
   That is for sissies. I recall a story about some system (I think it was
   either Fortran or LISP, but it might have been a urban legend) where a
   program like this would print 2:

   procedure p( x ){
      x = 2
   }
   p( 9 )
   print( 9 )

I actually made (or was it "found") a bug like this back when I was a
fortran programmer.  I managed to redefine zero :-(  It was a very
educational experience :-)

BillW

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body

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