clockmem.awl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. FUNCTION "TIMEDIFF" : TIME
  2. TITLE = Compute TIME0 minus TIME1
  3. VAR_INPUT
  4. TIME0 : TIME;
  5. TIME1 : TIME;
  6. END_VAR
  7. BEGIN
  8. L #TIME0
  9. L #TIME1
  10. -D
  11. UD DW#16#7FFFFFFF
  12. T #RET_VAL
  13. END_FUNCTION
  14. FUNCTION "UPDATE_TIME" : VOID
  15. BEGIN
  16. CALL "TIME_TCK" (
  17. RET_VAL := "TIME",
  18. )
  19. END_FUNCTION
  20. ORGANIZATION_BLOCK OB 1
  21. BEGIN
  22. M001: CALL "UPDATE_TIME"
  23. // Warmup time (pypy needs this)
  24. CALL "TIMEDIFF" (
  25. TIME0 := "TIME",
  26. TIME1 := "BOOT_TIME",
  27. RET_VAL := "DIFF",
  28. )
  29. L "DIFF"
  30. L T#2s
  31. >=D
  32. S "RUNNING"
  33. U "RUNNING"
  34. FP "RUNNING_EDGE"
  35. SPBN M005
  36. CALL "__CLKRST"
  37. CALL "UPDATE_TIME"
  38. L "TIME"
  39. T "START_TIME"
  40. T "STAMP_0.1s"
  41. T "STAMP_0.2s"
  42. T "STAMP_0.4s"
  43. T "STAMP_0.5s"
  44. T "STAMP_0.8s"
  45. T "STAMP_1.0s"
  46. T "STAMP_1.6s"
  47. T "STAMP_2.0s"
  48. L 0
  49. T "COUNT_0.1s"
  50. T "COUNT_0.2s"
  51. T "COUNT_0.4s"
  52. T "COUNT_0.5s"
  53. T "COUNT_0.8s"
  54. T "COUNT_1.0s"
  55. T "COUNT_1.6s"
  56. T "COUNT_2.0s"
  57. CLR
  58. = "CLOCK_0.1s_EDGE"
  59. = "CLOCK_0.2s_EDGE"
  60. = "CLOCK_0.4s_EDGE"
  61. = "CLOCK_0.5s_EDGE"
  62. = "CLOCK_0.8s_EDGE"
  63. = "CLOCK_1.0s_EDGE"
  64. = "CLOCK_1.6s_EDGE"
  65. = "CLOCK_2.0s_EDGE"
  66. // Check 0.1s trigger time
  67. M005: U "CLOCK_0.1s"
  68. FN "CLOCK_0.1s_EDGE"
  69. SPBN M010
  70. CALL "TIMEDIFF" (
  71. TIME0 := "TIME",
  72. TIME1 := "STAMP_0.1s",
  73. RET_VAL := "DIFF",
  74. )
  75. L "DIFF"
  76. UN "RUNNING"
  77. SPB M006
  78. __ASSERT>= __ACCU 1, T#10ms
  79. __ASSERT<= __ACCU 1, T#250ms
  80. M006: L "TIME"
  81. T "STAMP_0.1s"
  82. L "COUNT_0.1s"
  83. + 1
  84. T "COUNT_0.1s"
  85. // Check 0.2s trigger time
  86. M010: U "CLOCK_0.2s"
  87. FN "CLOCK_0.2s_EDGE"
  88. SPBN M020
  89. CALL "TIMEDIFF" (
  90. TIME0 := "TIME",
  91. TIME1 := "STAMP_0.2s",
  92. RET_VAL := "DIFF",
  93. )
  94. L "DIFF"
  95. UN "RUNNING"
  96. SPB M011
  97. __ASSERT>= __ACCU 1, T#100ms
  98. __ASSERT<= __ACCU 1, T#350ms
  99. M011: L "TIME"
  100. T "STAMP_0.2s"
  101. L "COUNT_0.2s"
  102. + 1
  103. T "COUNT_0.2s"
  104. // Check 0.4s trigger time
  105. M020: U "CLOCK_0.4s"
  106. FN "CLOCK_0.4s_EDGE"
  107. SPBN M030
  108. CALL "TIMEDIFF" (
  109. TIME0 := "TIME",
  110. TIME1 := "STAMP_0.4s",
  111. RET_VAL := "DIFF",
  112. )
  113. L "DIFF"
  114. UN "RUNNING"
  115. SPB M021
  116. __ASSERT>= __ACCU 1, T#300ms
  117. __ASSERT<= __ACCU 1, T#550ms
  118. M021: L "TIME"
  119. T "STAMP_0.4s"
  120. L "COUNT_0.4s"
  121. + 1
  122. T "COUNT_0.4s"
  123. // Check 0.5s trigger time
  124. M030: U "CLOCK_0.5s"
  125. FN "CLOCK_0.5s_EDGE"
  126. SPBN M040
  127. CALL "TIMEDIFF" (
  128. TIME0 := "TIME",
  129. TIME1 := "STAMP_0.5s",
  130. RET_VAL := "DIFF",
  131. )
  132. L "DIFF"
  133. UN "RUNNING"
  134. SPB M031
  135. __ASSERT>= __ACCU 1, T#400ms
  136. __ASSERT<= __ACCU 1, T#650ms
  137. M031: L "TIME"
  138. T "STAMP_0.5s"
  139. L "COUNT_0.5s"
  140. + 1
  141. T "COUNT_0.5s"
  142. // Check 0.8s trigger time
  143. M040: U "CLOCK_0.8s"
  144. FN "CLOCK_0.8s_EDGE"
  145. SPBN M050
  146. CALL "TIMEDIFF" (
  147. TIME0 := "TIME",
  148. TIME1 := "STAMP_0.8s",
  149. RET_VAL := "DIFF",
  150. )
  151. L "DIFF"
  152. UN "RUNNING"
  153. SPB M041
  154. __ASSERT>= __ACCU 1, T#700ms
  155. __ASSERT<= __ACCU 1, T#950ms
  156. M041: L "TIME"
  157. T "STAMP_0.8s"
  158. L "COUNT_0.8s"
  159. + 1
  160. T "COUNT_0.8s"
  161. // Check 1.0s trigger time
  162. M050: U "CLOCK_1.0s"
  163. FN "CLOCK_1.0s_EDGE"
  164. SPBN M060
  165. CALL "TIMEDIFF" (
  166. TIME0 := "TIME",
  167. TIME1 := "STAMP_1.0s",
  168. RET_VAL := "DIFF",
  169. )
  170. L "DIFF"
  171. UN "RUNNING"
  172. SPB M051
  173. __ASSERT>= __ACCU 1, T#900ms
  174. __ASSERT<= __ACCU 1, T#1s150ms
  175. M051: L "TIME"
  176. T "STAMP_1.0s"
  177. L "COUNT_1.0s"
  178. + 1
  179. T "COUNT_1.0s"
  180. // Check 1.6s trigger time
  181. M060: U "CLOCK_1.6s"
  182. FN "CLOCK_1.6s_EDGE"
  183. SPBN M070
  184. CALL "TIMEDIFF" (
  185. TIME0 := "TIME",
  186. TIME1 := "STAMP_1.6s",
  187. RET_VAL := "DIFF",
  188. )
  189. L "DIFF"
  190. UN "RUNNING"
  191. SPB M061
  192. __ASSERT>= __ACCU 1, T#1s500ms
  193. __ASSERT<= __ACCU 1, T#1s750ms
  194. M061: L "TIME"
  195. T "STAMP_1.6s"
  196. L "COUNT_1.6s"
  197. + 1
  198. T "COUNT_1.6s"
  199. // Check 2.0s trigger time
  200. M070: U "CLOCK_2.0s"
  201. FN "CLOCK_2.0s_EDGE"
  202. SPBN M080
  203. CALL "TIMEDIFF" (
  204. TIME0 := "TIME",
  205. TIME1 := "STAMP_2.0s",
  206. RET_VAL := "DIFF",
  207. )
  208. L "DIFF"
  209. UN "RUNNING"
  210. SPB M071
  211. __ASSERT>= __ACCU 1, T#1s900ms
  212. __ASSERT<= __ACCU 1, T#2s150ms
  213. M071: L "TIME"
  214. T "STAMP_2.0s"
  215. L "COUNT_2.0s"
  216. + 1
  217. T "COUNT_2.0s"
  218. // Stop test, if test time complete
  219. M080: CALL "TIMEDIFF" (
  220. TIME0 := "TIME",
  221. TIME1 := "START_TIME",
  222. RET_VAL := "DIFF",
  223. )
  224. UN "RUNNING"
  225. BEB
  226. L "DIFF"
  227. L T#4s50ms
  228. <D
  229. BEB // Not completed, yet
  230. // Completed. Check trigger counts.
  231. L "COUNT_0.1s"
  232. __ASSERT>= __ACCU 1, 39
  233. __ASSERT<= __ACCU 1, 41
  234. L "COUNT_0.2s"
  235. __ASSERT== __ACCU 1, 20
  236. L "COUNT_0.4s"
  237. __ASSERT== __ACCU 1, 10
  238. L "COUNT_0.5s"
  239. __ASSERT== __ACCU 1, 8
  240. L "COUNT_0.8s"
  241. __ASSERT== __ACCU 1, 5
  242. L "COUNT_1.0s"
  243. __ASSERT== __ACCU 1, 4
  244. L "COUNT_1.6s"
  245. __ASSERT== __ACCU 1, 2
  246. L "COUNT_2.0s"
  247. __ASSERT== __ACCU 1, 2
  248. // Everything is ok. Abort the test.
  249. CALL "STP" // Stop CPU
  250. END_ORGANIZATION_BLOCK
  251. ORGANIZATION_BLOCK OB 100
  252. BEGIN
  253. CALL "UPDATE_TIME"
  254. L "TIME"
  255. T "BOOT_TIME"
  256. CLR
  257. = "RUNNING"
  258. = "RUNNING_EDGE"
  259. END_ORGANIZATION_BLOCK