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: m.dileo@sistinf.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