GEX thesis source code, full text, references

ch.unit.fcap.tex 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. \section{Frequency Capture Unit}
  2. The frequency capture unit implements both the frequency measurement methods explained in \cref{sec:theory_fcap}: direct and reciprocal.
  3. The unit has several operational modes: idle, reciprocal continuous, reciprocal burst, direct continuous, direct burst, free counting, and single pulse. Burst mode is an on-demand measurement with optional averaging. Continuous mode does not support averaging, but the latest measurement can be read at any time without a delay.
  4. \subsection{Value Conversion Formulas}
  5. Several of the features implemented in this unit would require floating point arithmetic to provide the measured value in the desired units (Hz, seconds). That is not available in \armcm, only as a software implementation. The calculation is left to the client in order to save Flash space that would be otherwise used by the arithmetic functions. This arrangement also avoids rounding errors and a possible loss of precision.
  6. \subsubsection{Reciprocal (Indirect) Measurement}
  7. Period (in seconds) is computed as:
  8. \begin{equation}
  9. T = \dfrac{\mathrm{period\_sum}}{f_\mathrm{core,MHz} \cdot 10^6 \cdot \mathrm{n\_periods}}
  10. \end{equation}
  11. \noindent
  12. The frequency is obtained by simply inverting it:
  13. \begin{equation}
  14. f=T^{-1}
  15. \end{equation}
  16. The average duty cycle is computed as the ratio of the sum of active-level pulses and the sum of all periods:
  17. \begin{equation}
  18. \mathrm{average\_duty} = \dfrac{\mathrm{ontime\_sum}}{\mathrm{period\_sum}}
  19. \end{equation}
  20. \subsubsection{Direct Measurement}
  21. The frequency can be derived from the pulse count and measurement time using its definition ($t_\mathrm{ms}$ is measurement time in milliseconds):
  22. \begin{equation}
  23. f = \dfrac{1000\cdot\mathrm{count}\cdot\mathrm{prescaller}}
  24. {t_\mathrm{ms}}
  25. \end{equation}
  26. \subsection{Frequency Capture Configuration}
  27. \begin{inicode}
  28. [FCAP:j@10]
  29. # Signal input pin - one of:
  30. # Full support: A0, A5, A15
  31. # Indirect only: A1, B3
  32. pin=A0
  33. # Active level or edge (0-low,falling; 1-high,rising)
  34. active-level=1
  35. # Input filtering (0-15)
  36. input-filter=0
  37. # Pulse counter pre-divider (1,2,4,8)
  38. direct-presc=1
  39. # Pulse counting interval (ms)
  40. direct-time=1000
  41. # Mode on startup: N-none, I-indirect, D-direct, F-free count
  42. initial-mode=N
  43. \end{inicode}
  44. \subsection{Frequency Capture Commands}
  45. Some commands include optional parameter setting. Using 0 in the field keeps the previous value. Those fields are marked with *.
  46. \begin{cmdlist}
  47. 0 & \cname{STOP} Stop all measurements, go idle & \\
  48. 1 & \cname{INDIRECT\_CONT\_START}
  49. Start a repeated reciprocal measurement
  50. & \\
  51. 2 & \cname{INDIRECT\_BUTST\_START}
  52. Start a burst of reciprocal measurements
  53. & \begin{cmdreq}
  54. \cfield{u16} number of periods
  55. \end{cmdreq}
  56. \cjoin
  57. \begin{cmdresp}
  58. \cfield{u16} core speed (MHz)
  59. \cfield{u16} number of periods
  60. \cfield{u64} sum of all periods (ticks)
  61. \cfield{u16} sum of on-times (ticks)
  62. \end{cmdresp} \\
  63. 3 & \cname{DIRECT\_CONT\_START}
  64. Start a repeated direct measurement
  65. & \begin{cmdreq}
  66. \cfield{u16} *measurement time
  67. \cfield{u8} *prescaller (1, 2, 4, 8)
  68. \end{cmdreq} \\
  69. 4 & \cname{DIRECT\_BURST\_START}
  70. Start a single direct measurement. Longer capture time may help increase accuracy for stable signals.
  71. & \begin{cmdreq}
  72. \cfield{u16} *measurement time (ms)
  73. \cfield{u8} *prescaller (1, 2, 4, 8)
  74. \end{cmdreq}
  75. \cjoin
  76. \begin{cmdresp}
  77. \cfield{u8} prescaller
  78. \cfield{u16} measurement time (ms)
  79. \cfield{u32} pulse count
  80. \end{cmdresp} \\
  81. 5 & \cname{FREECOUNT\_START}
  82. Clear and start the pulse counter
  83. & \begin{cmdreq}
  84. \cfield{u8} *prescaller (1, 2, 4, 8)
  85. \end{cmdreq} \\
  86. 6 & \cname{MEASURE\_SINGLE\_PULSE}
  87. Measure a single pulse of the active level. Waits for a rising edge.
  88. & \begin{cmdresp}
  89. \cfield{u16} core speed (MHz)
  90. \cfield{u32} pulse length (ticks)
  91. \end{cmdresp} \\
  92. 7 & \cname{FREECOUNT\_CLEAR}
  93. Read and clear the pulse counter.
  94. & \begin{cmdresp}
  95. \cfield{u32} previous counter value
  96. \end{cmdresp} \\
  97. 10 & \cname{INDIRECT\_CONT\_READ}
  98. Read the latest value from the continuous reciprocal measurement, if running.
  99. & \begin{cmdresp}
  100. \cfield{u16} core speed (MHz)
  101. \cfield{u32} period length (ticks)
  102. \cfield{u32} on-time (ticks)
  103. \end{cmdresp} \\
  104. 11 & \cname{DIRECT\_CONT\_READ}
  105. Read the latest value from the continuous direct measurement, if running.
  106. & \begin{cmdresp}
  107. \cfield{u8} prescaller
  108. \cfield{u16} measurement time (ms)
  109. \cfield{u32} pulse count
  110. \end{cmdresp} \\
  111. 12 & \cname{FREECOUNT\_READ}
  112. Read the pulse counter value
  113. & \begin{cmdresp}
  114. \cfield{u32} pulse count
  115. \end{cmdresp} \\
  116. 20 & \cname{SET\_POLARITY}
  117. Set pulse polarity (active level)
  118. & \begin{cmdresp}
  119. \cfield{bool} polarity
  120. \end{cmdresp} \\
  121. 21 & \cname{SET\_PRESCALLER}
  122. Set prescaller for the direct mode
  123. & \begin{cmdresp}
  124. \cfield{u8} prescaller (1, 2, 4, 8)
  125. \end{cmdresp} \\
  126. 22 & \cname{SET\_INPUT\_FILTER}
  127. Set input filtering (a hardware feature designed to ignore glitches)
  128. & \begin{cmdresp}
  129. \cfield{u8} filtering factor (0--15, 0=off)
  130. \end{cmdresp} \\
  131. 23 & \cname{SET\_DIR\_MSEC}
  132. Set direct measurement time
  133. & \begin{cmdresp}
  134. \cfield{u16} measurement time (ms)
  135. \end{cmdresp} \\
  136. 30 & \cname{RESTORE\_DEFAULTS}
  137. Restore all run-time adjustable parameters to their configured default values
  138. & \\
  139. \end{cmdlist}