Hi,
I do this sort of thing alot in MPASM, however, I think you miss understand about the float.
MPASM only uses integer type values of 24, 16, or 8 bits that I'm aware of. You have to be careful, because it will truncate.
instructionPeriod equ 4/8
is the same as
instructionPeriod equ 0
This is a better way of doing things. Say you want to delay by 100 uS and the XTAL was 8 MHz. The number of instruction cycles you would delay is:
100*8/4 = 200
instead do it this way
Code:
XTAL equ 8
variable delay, delayCycle
delay = 100
delayCycle = (delay * XTAL) / 4
But say you wanted a delay of something messy like 5.5us.
Then you need to think about possibly defining in ns or 100ns blocks.
I would do
Code:
XTAL equ 8
variable delay, delayCycle
delay = 55 ; 5.5uS
delayCycle = (delay*XTAL) / 40 ;11 cycles
Then you have to think about rounding. Suppose you wanted a delay of 5.6 us. The closest you could get is to delay 5.5us or delay 6us. Obviously 5.5 us is closer. If you want to round then I suggest using
Code:
XTAL equ 8
variable delay, delayCycle
delay = 56
delayCycle = (((delay + 1) * XTAL) / 20 + 1) / 2
This is 57*8 = 456. 456/20 = 22.8 => 22. 22+1 = 23. 23/2 = 11.5 => 11 (delay of 5.5 uS).
-jonathan