Revision: 1170
Author: jsuijs
Date: Thu Aug 6 09:41:44 2009
Log: delay.jal with better accuracy
http://code.google.com/p/jallib/source/detail?r=1170
Modified:
/trunk/include/jal/delay.jal
=======================================
--- /trunk/include/jal/delay.jal Sat Nov 15 09:24:23 2008
+++ /trunk/include/jal/delay.jal Thu Aug 6 09:41:44 2009
@@ -74,41 +74,58 @@
pragma inline
_usec_delay(9)
end procedure
-
+
+-- calculate instruction execution time in 10ns units
+const instruction_time = 400_000_000 / target_clock
+
-- Delays for n * 10 usec
procedure delay_10us(byte in n) is
- if n==1 then
- _usec_delay(7)
- elsif n==2 then
- _usec_delay(16)
- elsif n==3 then
- _usec_delay(25)
- elsif n==4 then
- _usec_delay(34)
- else
- for n loop
- _usec_delay(8)
- end loop
- end if
- -- to compensate for low values of N
- asm nop
- asm nop
- asm nop
- asm nop
+ if n==0 then
+ return
+ elsif n==1 then
+ const _ten_us_delay1 = 10 - ((17 * instruction_time) / 100)
+ if (_ten_us_delay1 < 10) then
+ _usec_delay(_ten_us_delay1)
+ end if
+ else
+ n = n - 1;
+ const _ten_us_delay2 = 10 - ((24 * instruction_time) / 100)
+ if (_ten_us_delay2 < 10) then
+ _usec_delay(_ten_us_delay2)
+ else
+ _usec_delay(1)
+ end if
+
+ const _ten_us_delay3 = 10 - ((6 * instruction_time) / 100)
+ for n loop
+ if (_ten_us_delay3 < 10) then
+ _usec_delay(_ten_us_delay3)
+ else
+ _usec_delay(1)
+ end if
+ end loop
+ end if
+
end procedure
-- Delays for n * 1 msec
-procedure delay_1ms(byte in n) is
- for n loop
- _usec_delay(995)
- end loop
+procedure delay_1ms(word in n) is
+ const _one_ms_delay = 1000 - ((14 * instruction_time) / 100)
+ for n loop
+ if (_one_ms_delay < 1000) then
+ _usec_delay(_one_ms_delay)
+ else
+ _usec_delay(1)
+ end if
+ end loop
end procedure
-- Delays for n * 100 msec
procedure delay_100ms(word in n) is
- for n loop
- _usec_delay(99995)
- end loop
+ const _100_ms_delay = 100000 - ((14 * instruction_time) / 100)
+ for n loop
+ _usec_delay(_100_ms_delay)
+ end loop
end procedure
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---