GEX thesis source code, full text, references
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
gex-thesis/ch.unit.fcap.tex

173 lines
5.1 KiB

\section{Frequency Capture Unit}
The frequency capture unit implements both the frequency measurement methods explained in section \ref{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 possible averaging. Continuous mode doesn't 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 Cortex-M0, 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 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{u8} polarity (0,1)
\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}