GEX thesis source code, full text, references

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180  \section{Frequency Capture Unit} The frequency capture unit implements both the frequency measurement methods explained in \cref{sec:theory_fcap}: direct and reciprocal. 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. \subsection{Value Conversion Formulas} 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. \subsubsection{Reciprocal (Indirect) Measurement} Period (in seconds) is computed as: T = \dfrac{\mathrm{period\_sum}}{f_\mathrm{core,MHz} \cdot 10^6 \cdot \mathrm{n\_periods}} \noindent The frequency is obtained by simply inverting it: f=T^{-1} The average duty cycle is computed as the ratio of the sum of active-level pulses and the sum of all periods: \mathrm{average\_duty} = \dfrac{\mathrm{ontime\_sum}}{\mathrm{period\_sum}} \subsubsection{Direct Measurement} The frequency can be derived from the pulse count and measurement time using its definition ($t_\mathrm{ms}$ is measurement time in milliseconds): f = \dfrac{1000\cdot\mathrm{count}\cdot\mathrm{prescaller}} {t_\mathrm{ms}} \subsection{Frequency Capture Configuration} \begin{inicode} [FCAP:j@10] # Signal input pin - one of: # Full support: A0, A5, A15 # Indirect only: A1, B3 pin=A0 # Active level or edge (0-low,falling; 1-high,rising) active-level=1 # Input filtering (0-15) input-filter=0 # Pulse counter pre-divider (1,2,4,8) direct-presc=1 # Pulse counting interval (ms) direct-time=1000 # Mode on startup: N-none, I-indirect, D-direct, F-free count initial-mode=N \end{inicode} \subsection{Frequency Capture Commands} Some commands include optional parameter setting. Using 0 in the field keeps the previous value. Those fields are marked with *. \begin{cmdlist} 0 & \cname{STOP} Stop all measurements, go idle & \\ 1 & \cname{INDIRECT\_CONT\_START} Start a repeated reciprocal measurement & \\ 2 & \cname{INDIRECT\_BUTST\_START} Start a burst of reciprocal measurements & \begin{cmdreq} \cfield{u16} number of periods \end{cmdreq} \cjoin \begin{cmdresp} \cfield{u16} core speed (MHz) \cfield{u16} number of periods \cfield{u64} sum of all periods (ticks) \cfield{u16} sum of on-times (ticks) \end{cmdresp} \\ 3 & \cname{DIRECT\_CONT\_START} Start a repeated direct measurement & \begin{cmdreq} \cfield{u16} *measurement time \cfield{u8} *prescaller (1, 2, 4, 8) \end{cmdreq} \\ 4 & \cname{DIRECT\_BURST\_START} Start a single direct measurement. Longer capture time may help increase accuracy for stable signals. & \begin{cmdreq} \cfield{u16} *measurement time (ms) \cfield{u8} *prescaller (1, 2, 4, 8) \end{cmdreq} \cjoin \begin{cmdresp} \cfield{u8} prescaller \cfield{u16} measurement time (ms) \cfield{u32} pulse count \end{cmdresp} \\ 5 & \cname{FREECOUNT\_START} Clear and start the pulse counter & \begin{cmdreq} \cfield{u8} *prescaller (1, 2, 4, 8) \end{cmdreq} \\ 6 & \cname{MEASURE\_SINGLE\_PULSE} Measure a single pulse of the active level. Waits for a rising edge. & \begin{cmdresp} \cfield{u16} core speed (MHz) \cfield{u32} pulse length (ticks) \end{cmdresp} \\ 7 & \cname{FREECOUNT\_CLEAR} Read and clear the pulse counter. & \begin{cmdresp} \cfield{u32} previous counter value \end{cmdresp} \\ 10 & \cname{INDIRECT\_CONT\_READ} Read the latest value from the continuous reciprocal measurement, if running. & \begin{cmdresp} \cfield{u16} core speed (MHz) \cfield{u32} period length (ticks) \cfield{u32} on-time (ticks) \end{cmdresp} \\ 11 & \cname{DIRECT\_CONT\_READ} Read the latest value from the continuous direct measurement, if running. & \begin{cmdresp} \cfield{u8} prescaller \cfield{u16} measurement time (ms) \cfield{u32} pulse count \end{cmdresp} \\ 12 & \cname{FREECOUNT\_READ} Read the pulse counter value & \begin{cmdresp} \cfield{u32} pulse count \end{cmdresp} \\ 20 & \cname{SET\_POLARITY} Set pulse polarity (active level) & \begin{cmdresp} \cfield{bool} polarity \end{cmdresp} \\ 21 & \cname{SET\_PRESCALLER} Set prescaller for the direct mode & \begin{cmdresp} \cfield{u8} prescaller (1, 2, 4, 8) \end{cmdresp} \\ 22 & \cname{SET\_INPUT\_FILTER} Set input filtering (a hardware feature designed to ignore glitches) & \begin{cmdresp} \cfield{u8} filtering factor (0--15, 0=off) \end{cmdresp} \\ 23 & \cname{SET\_DIR\_MSEC} Set direct measurement time & \begin{cmdresp} \cfield{u16} measurement time (ms) \end{cmdresp} \\ 30 & \cname{RESTORE\_DEFAULTS} Restore all run-time adjustable parameters to their configured default values & \\ \end{cmdlist}