Searching \ for 'calculation in MPASM' 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/language/index.htm?key=asm
Search entire site for: 'calculation in MPASM'.

Truncated match.
PICList Thread
'calculation in MPASM'
1998\05\26@100855 by Mark Jurras

picon face
I need to calculate a constant at compile time to set a delay. I have
an equate:

NumAve  equ     0x40            ;Average 64 Readings

that I set for the number of A/D readings I want to average. I want to
average that number over one cycle of the AC power or 1/60 seconds. I
want to call a Macro (You know it well Andy!) with the amount of the
delay between A/D readings. The equation for the delay is:

1000000/60/NumAve-80


1000000 is me instruction rate
60 is the power line freq.
NumAve (see above)
80 is my A/D overhead

I want to invoke Andrew Warren's WAIT macro with
the result. Any hints how to setup the expression??

Thank you,

- -Mark



_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

1998\05\26@123811 by Marco DI LEO

flavicon
face
Mark Jurras wrote:
>
> I need to calculate a constant at compile time to set a delay. I have
> an equate:
>
> NumAve  equ     0x40            ;Average 64 Readings
>
> that I set for the number of A/D readings I want to average. I want to
> average that number over one cycle of the AC power or 1/60 seconds. I
> want to call a Macro (You know it well Andy!) with the amount of the
> delay between A/D readings. The equation for the delay is:
>
> 1000000/60/NumAve-80

Simply use the following:

       WAIT    ((1000000/60)/NumAve)-80

Actually you shouldn't need the parenthesis but I prefer to specify the
strict operation precedence. All calculation in MPASM are carried out on
32 bit _integer_ values so you can compute the desired value.

Please note that your expression gives a result of 0xb4 (180 decimal) so
you are almost near the capacity of a byte. Should you, in a latter
time, decide to reduce the number of readings to, say, 32, the
expression gives 0x1b8 (440 decimal) thus exceeding the byte size (the
same applies if you change the osc frequency). I don't know if the macro
you are planning to use takes a 16 or 8 bit value but in the latter case
you have to handle the overflow.

You can try something like this:

NumAve    equ     0x40            ;Average 64 Readings
CyclePS   equ     D'1000000'      ;Cycles per second
LineFreq  equ     D'60'           ;AC power frequency
ADtime    equ     D'80'           ;A/D overhead

ToWait    equ     ((CyclePS/LineFreq)/NumAve)-ADtime

         if      ToWait > 0xff   ;Change 0xff to the routine limit
         error   "Can't wait so long..."
         endif
...
...
...
         WAIT    ToWait

This way if your delay exceeds the limit of the macro (remember to
change the value in the 'if' line) you get an error so you can fix the
problem.

Using a routine that needs the delay value in separate bytes (LSB to
MSB) you can call it as in:

         movlw   low ToWait
         movwf   DelayLO              ;Low byte of delay
         movlw   high ToWait
         movwf   DelayHI              ;High part of delay
         call    Delay

or for 32 bit values (veeery long delay):

         movlw   ToWait & 0x000000ff
         movwf   DelayLO              ;Low byte
         movlw   (ToWait & 0x0000ff00) >> 8
         movwf   DelayML              ;Middle-low byte
         movlw   (ToWait & 0x00ff0000) >> 16
         movwf   DelayMH              ;Middle-high byte
         movlw   (ToWait & 0xff000000) >> 24
         movwf   DelayHI              ;High byte
         call    LongDelay

Ciao
 Marco

----
Marco DI LEO                  email: spam_OUTm.dileoTakeThisOuTspamsistinf.it
Sistemi Informativi S.p.A.    tel:   +39 6 50292 300
V. Elio Vittorini, 129        fax:   +39 6 5015991
I-00144 Roma                  web:   http://members.tripod.com/~mdileo/
Italy

1998\05\26@150524 by Andrew Warren

face
flavicon
face
Mark Jurras <.....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU> wrote:

> I need to calculate a constant at compile time to set a delay. I
> have an equate:
>
> NumAve  equ     0x40            ;Average 64 Readings
> ....
> The equation for the delay is:
>
> 1000000/60/NumAve-80
> ....
> I want to invoke Andrew Warren's WAIT macro with the result. Any
> hints how to setup the expression??

Mark:

   WAIT (1000000/(60*NUMAVE)) - 80

-Andy

=== Andrew Warren - fastfwdspamKILLspamix.netcom.com
=== Fast Forward Engineering - Vista, California
=== http://www.geocities.com/SiliconValley/2499 (personal)
=== http://www.netcom.com/~fastfwd (business)

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