Difference between revisions of "Frequency Counter"

From Ethersex_Wiki
Jump to: navigation, search
(Created page with "{{i18n|Frequency Counter}} {{Module |NAME=Frequency Counter |MENUCONFIG={{Applications}}->Frequency Counter |STATUS={{stable}} |PINNING=yes |ECMD={{has_ecmd}} |DEPENDS=ECMD (…")
 
(more translation)
 
(One intermediate revision by the same user not shown)
Line 13: Line 13:
 
Measures the frequency and duty cycle of a signal
 
Measures the frequency and duty cycle of a signal
  
== Anschluss ==
+
== Pinning ==
* muss immer an das ICP1-Pin angeschlossen werden
+
* the signal must always be fed to the ICP1-pin. Look up in the datasheet which physical pin this is on the used controller.
* im Pinning muss der Pin zusätzlich noch definiert werden:
+
* you need to define the pinning in ''pinning/hardware/<your board>.m4'':
<code>pin(FREQCOUNT_PIN, PB0, INPUT)</code>
+
  pin(FREQCOUNT_PIN, PB0, INPUT)
* es ist geplant noch ein Multiplexing mit einem zusätzlichen 74HC251 oder dem Ananlog-Multiplexer (unter Verlust des ADCs) einzubauen
 
  
== Frequenz ==
+
* if you want to measure the frequency of multiple signals, you can multiplex them with one or two 74HC251, up to 16 channels are supported
* CPU-Ticks von Rising-Edge zu Rising-Edge werden gemessen
+
* define the pinning for the control lines you need like this:
* Minimal das kleinere von 1 Hz und CPU-Frequenz / 16777216, in der Praxis 2 Hz
+
  pin(FREQCOUNT_CHANNEL_MULTIPLEX_BIT1, PB1, OUTPUT)
* Maximal ca. 50 CPU-Takte, also ca. 400KHz bei 20 MHz
+
  pin(FREQCOUNT_CHANNEL_MULTIPLEX_BIT2, PB2, OUTPUT)
* Ist die Frequenz höher, wird dies nicht sicher erkannt, es werden einfach falsche Werte gemessen
+
  pin(FREQCOUNT_CHANNEL_MULTIPLEX_BIT2, PB3, OUTPUT)
* Steigt die Interrupt-Last der CPU (z.B. durch Netzwerkverkverkehr oder UART), sinkt die maximal sicher messbare Frequenz
+
  pin(FREQCOUNT_CHANNEL_MULTIPLEX_CS_A, PB4, OUTPUT)
* Die Frequenz wird intern als Anzahl der Ticks (32 Bit unsigned int) gespeichert
+
  pin(FREQCOUNT_CHANNEL_MULTIPLEX_CS_B, PB5, OUTPUT)
  
== Duty-Cycle ==
+
== Frequency ==
* Kann auch den Duty-Cycle eines PWM-Signals messen
+
* CPU ticks from rising edge to rising edge are measured
* Duty-Cycle ist (Zeit von Rising Edge zu Falling Edge) / Gesamtdauer des letzten Zyklus von Rising zu Rising
+
* minimum frequency is the smaller value of 1 Hz and CPU frequency divided by 16777216, in practice 2 Hz
* Frequenz und Duty-Cycle werden nacheinander gemessen
+
* if the frequency is below the minimum, the output is 0
* Sollte sich die Frequenz signifikant ändern, ist die Duty-Cycle Messung falsch
+
* maximum frequency is about 50 cpu ticks, about 400 KHz at 20 MHz CPU
* Der Duty Cycle wird intern als 8 Bit Wert gespeichert
+
* if the frequency is above the maximum you get bogus results
 +
* when the irq load of the cpu increases (e.g. by network traffic or UART), the maximum frequency decreases
  
== Durchschnittsbildung ==
+
== Duty Cycle ==
* Durch Interrupt-Verzögerungen etc. kann es zu Fehlmessungen kommen
+
* you can also measure the duty cycle of a PWM signal
* Bei höheren Frequenzen sinkt die maximal mögliche Auflösung
+
* duty cycle is (time from rising edge to falling edge) / time of whole cycle from rising to rising
* Um das zu kompensieren wird immer der Durchschnitt von n Messungen verwendet, n ist im Konfigurationsmenü einstellbar
+
* frequency and duty cycle are measured one after another
* Zusätzlich wird immer der höchste und der niedrigste Wert einer dieser Durchschnittsreihen verworfen (es werden n+2 Samples genommen)
+
* when the frequency changes significantly the measured duty cycle will be wrong
 +
* duty cycle is stored as 8 bit value
  
== ECMD-Befehle ==
+
== Basic Averaging ==
 +
* you will sometimes get a wrong result due to interrupt latencies etc.
 +
* the module always averages the result of ''n'' measurements. You can define ''n'' in the menuconfig.
 +
* additionally the highest and lowest value of a averaging-block will be cut off, so ''n''+2 samples are taken
 +
* use a power of 2 for ''n'' to reduce code size and improve execution speed
 +
 
 +
== Moving Average ==
 +
* additionally to the basic averaging you can enable the moving average
 +
* the moving average uses the output from basic averaging as input
 +
* you can define the number of samples in the menuconfig
 +
* use a power of 2 for the number of samples to reduce code size and improve execution speed
 +
 
 +
== ECMD Commands ==
 
{| border=1 cellspacing=0 padding=4 class=wikitable
 
{| border=1 cellspacing=0 padding=4 class=wikitable
  ! width="25%" | Kommando
+
  ! width="25%" | Command
  ! Funktion
+
  ! Function
 +
|-
 +
|fc freq ''Channel''|| Returns the frequency in Hz (Attention: 32 Bit).
 +
|-
 +
|-
 +
|fc ticks ''Channel''|| Returns the frequency in CPU ticks (Attention: 32 Bit).
 +
|-
 
|-  
 
|-  
|fc freq ''Channel''|| Gibt die Frequenz in Hz zurück (Achtung: 32 Bit).
+
|fc duty ''Channel''|| Returns the duty cycle (0-255 decimal).
 
|-  
 
|-  
 
|-  
 
|-  
|fc ticks ''Channel''|| Gibt die Frequenz in CPU Ticks zurück (Achtung: 32 Bit).
+
|fc %duty ''Channel''|| Returns the duty cycle in percent.
 
|-  
 
|-  
 
|-  
 
|-  
|fc duty ''Channel''|| Gibt den Duty Cycle als 8 Bit Wert zurück (0-255 dezimal).
+
|fc on ''Channel''|| Switches on frequency counting on the given channel.
 
|-  
 
|-  
 
|-  
 
|-  
|fc %duty ''Channel''|| Gibt den Duty Cycle in Prozent zurück.
+
|fc off ''Channel''|| Switches off frequency counting on the given channel.
 
|-  
 
|-  
 
|-  
 
|-  
Hinweis: Channel ist momentan immer 0
+
''Channel'' is the number of the multiplexing channel (0-15), 0 if you do not use channel multiplexing.

Latest revision as of 21:36, 6 November 2011

Frequency Counter
Status
Stable
menuconfig Applications->Frequency Counter
Pinning yes
Ecmd yes
Depends on ECMD (optional)
Requires -
Code https://github.com/ethersex/ethersex/tree/master/services/freqcount

Measures the frequency and duty cycle of a signal

Pinning

  • the signal must always be fed to the ICP1-pin. Look up in the datasheet which physical pin this is on the used controller.
  • you need to define the pinning in pinning/hardware/<your board>.m4:
 pin(FREQCOUNT_PIN, PB0, INPUT)
  • if you want to measure the frequency of multiple signals, you can multiplex them with one or two 74HC251, up to 16 channels are supported
  • define the pinning for the control lines you need like this:
 pin(FREQCOUNT_CHANNEL_MULTIPLEX_BIT1, PB1, OUTPUT)
 pin(FREQCOUNT_CHANNEL_MULTIPLEX_BIT2, PB2, OUTPUT)
 pin(FREQCOUNT_CHANNEL_MULTIPLEX_BIT2, PB3, OUTPUT)
 pin(FREQCOUNT_CHANNEL_MULTIPLEX_CS_A, PB4, OUTPUT)
 pin(FREQCOUNT_CHANNEL_MULTIPLEX_CS_B, PB5, OUTPUT)

Frequency

  • CPU ticks from rising edge to rising edge are measured
  • minimum frequency is the smaller value of 1 Hz and CPU frequency divided by 16777216, in practice 2 Hz
  • if the frequency is below the minimum, the output is 0
  • maximum frequency is about 50 cpu ticks, about 400 KHz at 20 MHz CPU
  • if the frequency is above the maximum you get bogus results
  • when the irq load of the cpu increases (e.g. by network traffic or UART), the maximum frequency decreases

Duty Cycle

  • you can also measure the duty cycle of a PWM signal
  • duty cycle is (time from rising edge to falling edge) / time of whole cycle from rising to rising
  • frequency and duty cycle are measured one after another
  • when the frequency changes significantly the measured duty cycle will be wrong
  • duty cycle is stored as 8 bit value

Basic Averaging

  • you will sometimes get a wrong result due to interrupt latencies etc.
  • the module always averages the result of n measurements. You can define n in the menuconfig.
  • additionally the highest and lowest value of a averaging-block will be cut off, so n+2 samples are taken
  • use a power of 2 for n to reduce code size and improve execution speed

Moving Average

  • additionally to the basic averaging you can enable the moving average
  • the moving average uses the output from basic averaging as input
  • you can define the number of samples in the menuconfig
  • use a power of 2 for the number of samples to reduce code size and improve execution speed

ECMD Commands

Channel is the number of the multiplexing channel (0-15), 0 if you do not use channel multiplexing.
Command Function
fc freq Channel Returns the frequency in Hz (Attention: 32 Bit).
fc ticks Channel Returns the frequency in CPU ticks (Attention: 32 Bit).
fc duty Channel Returns the duty cycle (0-255 decimal).
fc %duty Channel Returns the duty cycle in percent.
fc on Channel Switches on frequency counting on the given channel.
fc off Channel Switches off frequency counting on the given channel.