Searching \ for ' Delay loops' 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/timers.htm?key=delay
Search entire site for: 'Delay loops'.

No exact or substring matches. trying for part
PICList Thread
'long delay loops'
1998\06\08@062043 by Gavin Jackson

flavicon
face
Hi there

I was playing around with some long delays and
decided to get a formula for working out some of
the delays, instead of just trying random values
to get the desired delay.
The following code contains three loops with
different values. The code is called with the
value for DEL1 in w. This code includes the
call and return clock cycles in the formula.
Note that when F8 (step through) is used the
stopwatch shows an extra clock cycle, that
should not be there. If you step through the
delay you get the correct number of steps.

e.g..           SOME INSTRUCTION
               MOVLW   ??H <- use your DEL1 value
               CALL            DELAY1
               NEXT INSTRUCTION AFTER DELAY

DELAY1  MOVWF   DEL1
LOOP1           MOVLW   ??H <- use your DEL2 value
               MOVWF   DEL2
LOOP2           MOVLW   ??H <- use your DEL3 value
               MOVWF   DEL3
               DECFSZ  DEL3,F
               GOTO    $-1
               DECFSZ  DEL2,F
               GOTO            LOOP2
               DECFSZ  DEL1,F
               GOTO            LOOP1
               RETURN

The delay in clock cycles is:
4*(1 + DEL1 + DEL1*DEL2) + 3*DEL1*DEL2*DEL3

Regards

Gavin
--------------------------
spam_OUTvulcanTakeThisOuTspamihug.co.nz
www.geocities.com/TheTropics/Cabana/2625
--------------------------


'MPLAB help - stimulation with delay loops'
2000\01\24@213140 by Charles L. Stackhouse
flavicon
face
When running MPLAB stimulator in single step fashion to try to debug an LCD
control program, I ran into some 10msec delay loops - OUCH!  What takes a
short time when the PIC is running, takes many hundreds of mouse clicks or
more to step through the program.
Even the "Animate" mode was taking way too long to get through these delay
loops.

What is the easiest way to deal with this? I haven't figured out  how to use
breakpoints yet but would a breakpoint at the end of the delay loop stop the
program here so I can resume the single step stimulation? I don't want to
comment out the delay loops as I am not sure the program will run properly
then.

Thanks.

Charlie WA2IPZ
Burley, Idaho

2000\01\24@213805 by Erik Reikes

flavicon
face
At 07:21 PM 1/24/00 -0700, you wrote:
>When running MPLAB stimulator in single step fashion to try to debug an LCD
>control program, I ran into some 10msec delay loops - OUCH!  What takes a
>short time when the PIC is running, takes many hundreds of mouse clicks or
>more to step through the program.
>Even the "Animate" mode was taking way too long to get through these delay
>loops.
>
>What is the easiest way to deal with this? I haven't figured out  how to use
>breakpoints yet but would a breakpoint at the end of the delay loop stop the
>program here so I can resume the single step stimulation? I don't want to
>comment out the delay loops as I am not sure the program will run properly
>then.
>

Set breakpoints by right clicking and setting the breakpoint.  The line of
code will turn red indicating a break there.

It will still take a while to go through but will be much faster than
clicking with the mouse.



>Thanks.
>
>Charlie WA2IPZ
>Burley, Idaho

Erik Reikes
Software Engineer
Xsilogy, Inc.

.....ereikesKILLspamspam@spam@xsilogy.com
ph : (858) 535-5113
fax : (858) 535-5163
cell : (858) 663-1206

2000\01\24@222636 by Charles Linquist

picon face
I just comment out (or jump around) the delay loop during
the simulation phase.




----- Original Message -----
From: "Charles L. Stackhouse" <cstackspamKILLspamSAFELINK.NET>
To: <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU>
Sent: Monday, January 24, 2000 6:21 PM
Subject: MPLAB help - stimulation with delay loops


> When running MPLAB stimulator in single step fashion to try to debug an
LCD
> control program, I ran into some 10msec delay loops - OUCH!  What takes a
> short time when the PIC is running, takes many hundreds of mouse clicks or
> more to step through the program.
> Even the "Animate" mode was taking way too long to get through these delay
> loops.
>
> What is the easiest way to deal with this? I haven't figured out  how to
use
> breakpoints yet but would a breakpoint at the end of the delay loop stop
the
> program here so I can resume the single step stimulation? I don't want to
> comment out the delay loops as I am not sure the program will run properly
> then.
>
> Thanks.
>
> Charlie WA2IPZ
> Burley, Idaho

2000\01\24@225353 by Dennis Gearon

flavicon
face
OR.............manually change the values that determine how long the loop is
taking, in the memory of the simulator to speed things up.



Erik Reikes wrote:

{Quote hidden}

--
-----------------------------------------------------------------
Time Spent With Your Dog(Kid) is Time Well Spent
-----------------------------------------------------------------
   Sincerely, Dennis Gearon

2000\01\25@122206 by Edson Brusque

face
flavicon
face
> OR.............manually change the values that determine how long the loop
is
> taking, in the memory of the simulator to speed things up.

   OR.... (:^) put the loop values on a EQU in the start of the program.
Change it to a low value when simulating, return it to the correct high
value when burning.

   As I'm using CCS, I change the line "#USE DELAY(clock=20000000)" to
"#USE DELAY(clock=1000)" when simulating/debugging.

   Bes regards,

   Brusque
+----------------------+
|    Edson  Brusque    |
|   Tech Development   |
| http://www.citronics.com.br |
+----------------------+

2000\01\25@122620 by Harold M Hallikainen

picon face
       If the delay loop is a separate subroutine, you can use F8 to run the
subroutine at full speed, then stop when it returns.

Harold

On Mon, 24 Jan 2000 19:26:14 -0800 Charles Linquist
<clinquistspamspam_OUTMINDSPRING.COM> writes:
> I just comment out (or jump around) the delay loop during
> the simulation phase.
>
>
>

FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com

________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk!  For your FREE software, visit:
dl.http://www.juno.com/get/tagj.

2000\01\25@142824 by Anthony Ryan

picon face
I had exactly the same problem with a LCD routine too.

If your delay is a subroutine, add a label such as "DELAY_TRAP" on (or just
before) your RETURN instruction.

Then from the BREAK SETTINGS menu option, select DELAY_TRAP (from the pull
down label list) as your break point. The break point will then have a tick
next to it if it is enabled.

Whenever you reach the delay loop during single step, just press F9 to run
through the delay.

Regards

Tony

2000\01\25@173101 by Larry G. Nelson Sr.

flavicon
face
Is it something you can use step over on? Otherwise you can comment out the
delay or modify the program counter to jump past the loop. You can also
modify the counter register to shorten the loop while stepping thru.


At 07:21 PM 1/24/00 -0700, you wrote:
{Quote hidden}

Larry G. Nelson Sr.
@spam@L.NelsonKILLspamspamieee.org
http://www.ultranet.com/~nr


'[PICLIST] Delay loops that don't need any RAM'
2001\10\28@204818 by Dwayne Reid
flavicon
face
Good day to all.

I'm adding some major new functions to some code written by a colleague and
started getting short on RAM.  Rather than re-target to a different
processor, I started looking through his code to see where I could free up RAM.

One area that kind of jumped out at me was his delay routines.  His
routines used the standard 'decfz  somereg,F' technique.  I could free up a
couple of bytes of RAM if I re-wrote his routines to just use W.  Thats
real easy on the 14 bit core parts: 'addlw -1' works just fine.  But this
was on the 12 bit core chips.

I remembered that John Payson came up with a neat 2's complement technique
for complementing the value contained in W and works on all PIC cores:

; complement W
    addwf       FSR,W       ;can be any register that does not change
between these
    subwf       FSR,W       ;  two instructions
;done!

A 2's complement is simply the 1's complement of a number plus 1.  If I
took the 1's complement a number, then took the 2's complement of that same
number, I'd wind up with the original number plus 1.  In other words: a way
to increment W without needing any RAM.

It works!

The version I came up with looks like this:

Delay500
    movlw       -(.500/6)     ;desired delay / loop delay

Delay500Loop
    xorlw       0xFF            ;1's complement W
    addwf       FSR,W           ;2's complement W
    subwf       FSR,W
    skpz                        ;W wrap to 0?
      goto      Delay500Loop    ;loop is 6 instructions


dwayne


Dwayne Reid   <KILLspamdwaynerKILLspamspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 17 years of Engineering Innovation (1984 - 2001)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\10\28@205849 by Tony Nixon

flavicon
picon face
Dwayne Reid wrote:

> The version I came up with looks like this:
>
> Delay500
>      movlw       -(.500/6)     ;desired delay / loop delay
>
> Delay500Loop
>      xorlw       0xFF            ;1's complement W
>      addwf       FSR,W           ;2's complement W
>      subwf       FSR,W
>      skpz                        ;W wrap to 0?
>        goto      Delay500Loop    ;loop is 6 instructions
>
> dwayne


Why not just use the FSR register?

Delay   movlw ???
       movwf FSR
DelayL  decfsz FSR
       goto DelayL

Or any other 'hardly' used register like EEDATA or ADRESL etc.

--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
spamBeGonesalesspamBeGonespambubblesoftonline.com

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-requestEraseMEspamspam_OUTmitvma.mit.edu


2001\10\29@205238 by Dwayne Reid

flavicon
face
At 12:58 PM 10/29/01 +1100, Tony Nixon wrote:
{Quote hidden}

In my case, FSR contains active data (its pointing to the data being dealt
with) and I can't trash it.  Note that the routine only *reads* FSR, it
does not modify it in any way.


>Or any other 'hardly' used register like EEDATA or ADRESL etc.

12 bit core: EEDATA and ADRESL don't exist.

Good suggestions, though, and I have done exactly that in previous projects
(FSR, ADRES).

The neat thing about the routine I posted is that it is usable on all PIC
cores.

dwayne



Dwayne Reid   <RemoveMEdwaynerspamTakeThisOuTplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 17 years of Engineering Innovation (1984 - 2001)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\29@205252 by Dwayne Reid

flavicon
face
resent with the 'PIC' topic tag

Good day to all.

I'm adding some major new functions to some code written by a colleague and
started getting short on RAM.  Rather than re-target to a different
processor, I started looking through his code to see where I could free up RAM.

One area that kind of jumped out at me was his delay routines.  His
routines used the standard 'decfz  somereg,F' technique.  I could free up a
couple of bytes of RAM if I re-wrote his routines to just use W.  Thats
real easy on the 14 bit core parts: 'addlw -1' works just fine.  But this
was on the 12 bit core chips.

I remembered that John Payson came up with a neat 2's complement technique
for complementing the value contained in W and works on all PIC cores:

; complement W
    addwf       FSR,W       ;can be any register that does not change
between these
    subwf       FSR,W       ;  two instructions
;done!

A 2's complement is simply the 1's complement of a number plus 1.  If I
took the 1's complement a number, then took the 2's complement of that same
number, I'd wind up with the original number plus 1.  In other words: a way
to increment W without needing any RAM.

It works!

The version I came up with looks like this:

Delay500
    movlw       -(.500/6)     ;desired delay / loop delay

Delay500Loop
    xorlw       0xFF            ;1's complement W
    addwf       FSR,W           ;2's complement W
    subwf       FSR,W
    skpz                        ;W wrap to 0?
      goto      Delay500Loop    ;loop is 6 instructions


dwayne


Dwayne Reid   <dwaynerEraseMEspam.....planet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 17 years of Engineering Innovation (1984 - 2001)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\10\31@125645 by Dwayne Reid

flavicon
face
Good day again!

I got intrigued with this business of incrementing W on a 12 bit core PIC
and tried something a little different.  Again: this technique should work
on all PIC parts for those who are writing code that is intended to be
portable or re-usable.

The first routine I posted seems to work just fine:

Delay500
    movlw       -(.500/6)     ;desired delay / loop delay

Delay500Loop
    xorlw       0xFF            ;1's complement W
    addwf       FSR,W           ;2's complement W
    subwf       FSR,W
    skpz                        ;W wrap to 0?
      goto      Delay500Loop    ;loop is 6 instructions

But I got thinking about the possibility of using a pair of 2's complement
instructions in succession.  An easy way to complement W is to do a 'subwf
SOMEREG,W' where that register contains 0.  But if I do it twice, it
doesn't matter what the register contains because the 2nd subtraction
cancels the effect of the first.

Of course, this is now a 2 instruction 2 cycle NOP!  W ends up with same
value it started out with at the end of the 2nd subwf.  But what if the
register I was subtracting from increased by 1 between the
instructions?  Might that fix the problem?

So far, the answer seems to be YES!  As you might guess, the register I
want to use as the target for the 'subwf' instructions is PCL.  So now my
little delay loop looks like:

Delay500
    movlw       -(.500/5)     ;desired delay / loop delay

Delay500Loop                    ;loop is 5 cycles
    subwf       PCL,W           ;these 2 instr increment W by 1
    subwf       PCL,W
    skpz                        ;W wrap to 0?
      goto      Delay500Loop    ;

This little loop should be completely position independent and PCLATH does
not matter since PCL is not actually being changed.  And, again, even
though it is written for the 12 bit core devices, it should work on all PIC
families.

Thought?  Comments?

dwayne


Dwayne Reid   <EraseMEdwaynerspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 17 years of Engineering Innovation (1984 - 2001)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

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


2001\10\31@125654 by Drew Vassallo

picon face
>Delay500
>     movlw       -(.500/6)     ;desired delay / loop delay
>
>Delay500Loop
>     xorlw       0xFF            ;1's complement W
>     addwf       FSR,W           ;2's complement W
>     subwf       FSR,W
>     skpz                        ;W wrap to 0?
>       goto      Delay500Loop    ;loop is 6 instructions

I've seen this before somewhere, but it's still neat.  But, since nearly all
of my projects (and I'm sure others, too) use "temp" registers for
calculations, counters, etc., I would be surprised if one file couldn't be
freed for use with a standard delay loop.  Plus, you could reduce the
program memory by over 1/2.

Also, note that the routine above is limited to 256 times through the loop.
The more delay you need, the more program memory is required due to NOPs.

--Andrew

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

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


2001\10\31@165941 by Ian Chapman

flavicon
picon face
Dwayne Reid <RemoveMEdwaynerEraseMEspamEraseMEPLANET.EON.NET> wrote:
>    subwf       PCL,W           ;these 2 instr increment W by 1
>    subwf       PCL,W

Impressive!  This certainly wins my vote for the most imaginative use of
the PCL register.  Or are there other candidates?  ;-)
--
Ian Chapman
Chapmip Technology, UK

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



'[PIC]: Delay loops that don't need any RAM'
2001\11\01@094209 by o-8859-1?Q?K=FCbek_Tony?=
flavicon
face
Hi,

Dwayne Reid wrote:
<snip>
{Quote hidden}

Neat ! however..

a bit concerned over 8 bit pcl rollover ( i.e. from 0xFF -> 0x00 )
lets try with the following:
Let's try with 1 loop delay and let PCL have the value 0xFF at the
first subwf.

W = 1 -> a 5 cycle delay ( excluding and returns or calls )

Delay500Loop_1                  ; W = 1
    subwf       PCL,W          ; PCL = 0xFF ( 255 ) -> F-W = 254
    subwf       PCL,W            ; PCL = 0x00 -> F-W = 254 !!! gotcha...
    skpz                       ;
     goto      Delay500Loop    ; loop forever....

But apart from that elegant solution,
hope I'm correct been a while without pic's :)

/Tony







Tony Kübek, Flintab AB            
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²
"No! Try not. Do, or do not. There is no try.", Yoda
E-mail: RemoveMEtony.kubekspam_OUTspamKILLspamflintab.com
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

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


2001\11\01@101538 by Scott Dattalo

face
flavicon
face
On Thu, 1 Nov 2001, K|bek Tony wrote:

> Neat ! however..
>
> a bit concerned over 8 bit pcl rollover ( i.e. from 0xFF -> 0x00 )
> lets try with the following:
> Let's try with 1 loop delay and let PCL have the value 0xFF at the
> first subwf.
>
> W = 1 -> a 5 cycle delay ( excluding and returns or calls )
>
> Delay500Loop_1                  ; W = 1
>      subwf       PCL,W          ; PCL = 0xFF ( 255 ) -> F-W = 254
>      subwf       PCL,W            ; PCL = 0x00 -> F-W = 254 !!! gotcha...
>      skpz                       ;
>       goto      Delay500Loop    ; loop forever....

Tony,

It's actually 0 - 254 which yields 2. Roll over is no problem.

Dwayne has stumbled on a truly devious piece of code that couldn't have
been posted on a better day of the year!

Scott

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


2001\11\01@153644 by Dwayne Reid

flavicon
face
At 03:18 PM 11/1/01 +0100, Kübek Tony wrote:

>Neat ! however..
>
>a bit concerned over 8 bit pcl rollover ( i.e. from 0xFF -> 0x00 )
>lets try with the following:
>Let's try with 1 loop delay and let PCL have the value 0xFF at the
>first subwf.
>
>W = 1 -> a 5 cycle delay ( excluding and returns or calls )
>
>Delay500Loop_1                  ; W = 1
>      subwf       PCL,W          ; PCL = 0xFF ( 255 ) -> F-W = 254
>      subwf       PCL,W            ; PCL = 0x00 -> F-W = 254 !!! gotcha...
>      skpz                       ;
>       goto      Delay500Loop    ; loop forever....

Nope - no gotcha!  W is an 8 bit register.  I simulated with boundary conditions as you describe and there was no problem whatsoever.

It *does* work!  (MPLAB 5.40, tried with both 12c508 & 16f84).

dwayne



Dwayne Reid   <RemoveMEdwaynerKILLspamspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 17 years of Engineering Innovation (1984 - 2001)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

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


2001\11\01@180716 by Olin Lathrop

face picon face
>>
Neat ! however..

a bit concerned over 8 bit pcl rollover ( i.e. from 0xFF -> 0x00 )
<<

It will still work since the high bits can't feed back into the low bits,
and the low bits are still correct.

>>
Delay500Loop_1                  ; W = 1
    subwf       PCL,W          ; PCL = 0xFF ( 255 ) -> F-W = 254
    subwf       PCL,W            ; PCL = 0x00 -> F-W = 254 !!! gotcha...
<<

No gotcha.  0 - 254 = 2, just like it would with any other starting value of
PCL.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, spamBeGoneolinSTOPspamspamEraseMEembedinc.com, http://www.embedinc.com

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


2001\11\02@045655 by o-8859-1?Q?K=FCbek_Tony?=

flavicon
face
Hi,

Scott, Olin and Dwayne kindly corrected my blunder :)
as I said to long without pic's.

Isn't the first time that subwf have bitten me backwards.

Excellent.

/Tony


Tony Kübek, Flintab AB            
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²
"No! Try not. Do, or do not. There is no try.", Yoda
E-mail: EraseMEtony.kubekspamEraseMEflintab.com
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-request@spam@spamspam_OUTmitvma.mit.edu


2001\11\02@102642 by Lawrence Lile

flavicon
face
I simulated this yesterday, pumping a number of values into PCL and w just
to see if I could trick it into failing.  If you enter with 0 in w, the loop
executes 256 times.  That makes sense if you think about it, but I think it
is dangerous. Perhaps a robust algorithm would test for zero and kick out
before entering the delay loop.

Now how could somebody convince a C compiler to use this algorithm for
RAM-free software delays? It seems to me that passing an argument in C would
most likely eat up precious RAM, even if the algorithm itself was dropped
into assembler, no?

--Lawrence

{Original Message removed}

2001\11\02@124324 by Scott Dattalo

face
flavicon
face
On Fri, 2 Nov 2001, Lawrence Lile wrote:

> Now how could somebody convince a C compiler to use this algorithm for
> RAM-free software delays? It seems to me that passing an argument in C would
> most likely eat up precious RAM, even if the algorithm itself was dropped
> into assembler, no?

It may just depend on whether or not you have the source to the
C-compiler. :)

Scott

PS. SDCC is moving along more quickly than I expected. A beta may be ready
January instead of March.

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamKILLspammitvma.mit.edu


2001\11\02@161818 by Lawrence Lile

flavicon
face
I've been working on a two-byte version of the RAMless delay loop, which
uses FSR to store the high byte.  In assembler I can get it to work fine.
In CCS C, there seems to be a problem in simulation under MPLAB, because a
skpz instruction clearly always skips, regardless of the state of the
status,Z bit on the adjacent watch window+ACE-  (aargh) Simulation works OK in
Hitech C under MPLAB.    SO far, both versions have a fixed delay (which is
what I happen to need for a project I am working on today+ACE-)

//     ASSEMBLER VERSION
+ADsAOw- loop 10,000 cycles +AD0- 10,000 / 5.0351 +AD0- 1986  loops
+ADsAOw- +AD0- 0x7C2  loops  FSR needs to be 0x07+-1for it to work right
MAINLOOP
movlw -(0x07+-1)
movwf FSR
movlw -(0xC2+-1)

Delay500Loop
subwf       PCL,W
subwf       PCL,W
skpz
goto      Delay500Loop
movf FSR,w
subwf       PCL,W
subwf       PCL,W
movwf FSR
skpnz
goto endofloop
clrw
goto Delay500Loop
endofloop:
   nop


//   C VERSION:
void delay1()+AHs-
// 10000 machine cycles
//
//  10000 / 5.03125 machine cycles per loop
// +AD0- 1986D +AD0- 07C2

+ACM-asm
movlw -(0x07+-1)    // gotta add 1 to get this to work right
movwf fsr
movlw -(0xC2+-1)    //   ditto

loop:
subwf pcl,w
subwf pcl,w
btfss status, zbit
goto loop
movf fsr,w
subwf pcl,w
subwf pcl,w
movwf fsr
btfsc status, zbit
goto endloop
clrw
goto loop

endloop:

+ACM-endasm

+AH0-

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestspam_OUTspammitvma.mit.edu


2001\11\02@171532 by Scott Dattalo

face
flavicon
face
On Fri, 2 Nov 2001, Lawrence Lile wrote:

{Quote hidden}

Why not just use

  decf  fsr,f  ;
  skpnz
   goto   endofloop


>  clrw
>  goto Delay500Loop
> endofloop:
>     nop


Also, is this for a 12bit core or 14bit core? If you're using the 14-bit
core then a simpler "addlw -1" would suffice.

Scott

PS. Nikolai tells me he has some nifty variations on Dwayne's trick.
Unfortunately the list server doesn't like him right now...

--
http://www.piclist.com hint: To leave the PICList
TakeThisOuTpiclist-unsubscribe-request.....spamTakeThisOuTmitvma.mit.edu


2001\11\03@062727 by Gerhard Fiedler

flavicon
face
At 09:25 11/02/2001 -0600, Lawrence Lile wrote:
>Now how could somebody convince a C compiler to use this algorithm for
>RAM-free software delays? It seems to me that passing an argument in C would
>most likely eat up precious RAM, even if the algorithm itself was dropped
>into assembler, no?

As someone already mentioned, most programs will have some kind of scratch
RAM that they can use for such purposes. This is especially true for C
compilers. There are a number of different kinds of "scratch RAM" that are
available for this, and the probablility that such code will not increase
the overall amount of RAM used even if it uses 1 or 2 byte file storage is
pretty high.

Besides, it may be possible write a macro that does this loop. The use of
the W register may create a problem, though.

ge

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\11\03@170650 by Olin Lathrop

face picon face
>Now how could somebody convince a C compiler to use this algorithm for
>RAM-free software delays? It seems to me that passing an argument in C
would
>most likely eat up precious RAM, even if the algorithm itself was dropped
>into assembler, no?

If your system is so small and you're so close to the edge that you can't
afford one more RAM location, you have no business writing in C.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, TakeThisOuTolinKILLspamspamspamembedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\11\03@183759 by Andrew E. Kalman

flavicon
face
Re:

>Now how could somebody convince a C compiler to use this algorithm for
>RAM-free software delays? It seems to me that passing an argument in C would
>most likely eat up precious RAM, even if the algorithm itself was dropped
into assembler, no?

Practically speaking, passing a single 8-bit-sized parameter to a
HI-TECH PICC function will have no effect on your overall RAM usage.
That's because 8-bit params are passed in W. You can then code the
guts of the function either in C or in-line assembly. For larger
parameters (e.g. ints), they're passed in the btemp registers, IIRC.

The overall RAM usage is a little complicated to predict, because the
compiler is smart about overlaying RAM. Function call graph depth and
max(sizeof(parameters of your functions)) will dictate how much RAM
you need.

Since HI-TECH places all parameters in RAM bank 0 exclusively, it's
unlikely that passing a single 8-bit parameter will have any affect
on your application's RAM requirements, assuming your application is
reasonably complex (i.e. functions with parameters call functions
with parameters, etc.).

Be sure to enable the generation of listing files when you build your
project(s), and use maximum optimization (level 9). You can play
around with different schemes to see which ones result in the
smallest RAM and/or ROM size.

--

 ______________________________________
  Andrew E. Kalman, Ph.D.   .....aekspamRemoveMEpumpkininc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\11\05@110107 by Lawrence Lile

flavicon
face
Scott Dattallo wrote:

>
> Why not just use
>
>    decf  fsr,f  ;
>    skpnz
>     goto   endofloop
>

Makes sense.  Tighter loop.


>
> Also, is this for a 12bit core or 14bit core? If you're using the 14-bit
> core then a simpler "addlw -1" would suffice.
>

I'm writing for the 12 bit core right now.  I guess the 12 bit instruction
would be general, the 14bit instruction would be a tighter loop.

Tighter timing loop is good sometimes, sometimes not depending on whether
you want to waste a lot of time.  The app I'm working on right now has lots
and lots of time to wait around (it's just a timer) so a few extra
statements just stretch the amount of time that two bytes can reach.

It would be fun to come up with a compiler hack what would:
A. Decide on 12 bit or 14 bit core
B. Do the math to figure out what bits to stuff at the beginning of the loop
C. use no unneccesary RAM
D. Compute all this stuff at compile time


--Lawrence





{Quote hidden}

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


2001\11\05@111506 by Andrew E. Kalman

flavicon
face
Re:

>It would be fun to come up with a compiler hack what would:
>A. Decide on 12 bit or 14 bit core


#ifdef _PIC12
....
#elif _PIC14
...
#endif

(this for HI-TECH PICC)
--

 ______________________________________
  Andrew E. Kalman, Ph.D.   spamBeGoneaek@spam@spamspam_OUTpumpkininc.com

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


2001\11\05@114017 by Gerhard Fiedler

flavicon
face
At 09:58 11/05/2001 -0600, Lawrence Lile wrote:
>B. Do the math to figure out what bits to stuff at the beginning of the loop
>D. Compute all this stuff at compile time

This could be done by preprocessor calculations, using #define etc. Once
you have the clock speed defined, you can calculate the counter values.

>C. use no unneccesary RAM

Using inline assembly?

ge

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


2001\11\05@132637 by Lawrence Lile

flavicon
face
Yeah, that's what I mean.

THe hard part would be a little math to decide what values to stuff into w
before starting the loop.

Even harder would be to allow the processor to pass a variable into the
function.

--Lawrence

{Quote hidden}

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



'[PIC] : Delay loops'
2002\08\05@180149 by Jinx
face picon face
>  bsf PORTB, 4
>  bsf PORTB, 1  ;---------------------
>  ; delay for at least 2ms
>  movlw 0x95
>  movwf Dlay
>  movlw 0x02
>  movwf Dlay + 1

>  decfsz Dlay
>   goto $ - 1

>  decfsz Dlay + 1
>   goto $ - 3

Hi Mike, the problem is that the inner loop (decfsz Dlay, goto $-1) is
being executed only twice. So your total delay is $195, not $295, or
770us short. Make it MOVLW 0x03, MOVWF Dlay+1 and you'll be
in business

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


'[PIC]: Re: Delay loops'
2002\08\12@051322 by sbryden

flavicon
face
As promised, the link I was referring to in previous posts regarding PIC delay
loop calculation. It is part of Sean Hugh Breheny's page which has other
useful PIC info.

http://www.people.cornell.edu/pages/shb7/lop.html

Regards,
Simon.
---

At 05:19 PM 8/5/02 -0400, Michael A. Powers wrote:

{Quote hidden}

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



'[SX] Delay Loops'
2005\10\07@132229 by kingnebn/a
flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, kingneb wrote:

I am running an SX28 or SX18 with the 4mhz internal oscilator.  How do you figure out the delay values for an X amount of seconds or microseconds?  Could u post a code sample and formula.  I am not running SX/B, one of the most innefficient compilers i've seen, assembler rules!    

thanks,
kingneb
---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=90754
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)

2005\10\07@144228 by g_daubachn/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, g_daubach wrote:

Hi,
please have a look at http://www.sxlist.com/techref/piclist/codegen/delay.htm for a delay code generator.

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=90754#m90767
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)

2005\10\09@132305 by Kennethn/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Kenneth wrote:

You can find the "delay value" m in this loop:

mov m,#?

delay decsz m ; m + 1
jmp delay ; 3*(m - 1)
by the formula:

x = (1/fclk)*(4m - 2) <==> m = (x*fclk + 2) / 4 .

If you keep fclk in MHz you will have x in usec. Keep in mind that m >= 1.

cheers,
Kenneth
---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=90754#m90910
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)

2005\10\09@191621 by beann/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, bean wrote:

I don't agree that SX/B is an "innefficient" compiler...
Not everyone is the master assembly language programmer, that you are. BTW did you figure out how to make a delay yet ?
In SX/B I write "PAUSE x" where is x is the milliseconds to pause, or "PAUSEUS y" where y is the microseconds to pause.
Bean.

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=90754#m90936
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)

2005\10\11@081754 by johncouturen/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, johncouture wrote:

I was wondering when one of the SX/B programmers was going to pipe up.  Assembler may rule but SX/B yields a finished program in a reasonable amount of time.  When was the last time you got an assembly program to work in one day (grin)?  The SX/B compiler is actually pretty efficient and for routines that put too much code in, you can insert assembler directly after reading how the compiler does it.  How kool is that!

As to WHAT rules, you might want to heed the advice of someone that has a FINISHED product (grin) like Bean above.  He has a product that has actually made it to market and presumably sells pretty well!  Pretty impressive in my book!

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=90754#m91191
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)

2005\10\11@104034 by Jon Williamsn/a

flavicon
face
In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Jon Williams wrote:

FWIW, I posted my Serial Inkjet Code as a demonstration of what SX/B is capable of doing when handled with a bit of skill -- skills that all of us hold, no matter what language we use.  I've become a very big fan of SX/B because it lets me get my work done quickly (all of the "smart" products we've created in the Parallax EFX group are programmed in SX/B) and I can learn assembly by looking at the output.  In fact, during the testing phase I would often make adjustments to the SRC file and feed that information back to our compiler engineer for inclusion into the compiler.  The nature of SX/B allows us to improve it quickly, hence the regular updates since its release (and yes, more are coming).

I think it's fair to conclude that inefficiency is under the direct control of the programmer -- no matter what programming tool in his/her hands.

---------- End of Message ----------

You can view the post on-line at:
http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=90754#m91217
Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com
The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2005 (http://www.dotNetBB.com)

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