Difference between revisions of "Frequency Counter"

From Ethersex_Wiki
Jump to: navigation, search
(some translation)
(more translation)
 
Line 18: Line 18:
 
   pin(FREQCOUNT_PIN, PB0, INPUT)
 
   pin(FREQCOUNT_PIN, PB0, INPUT)
  
* if you want to measure the frequency of multiple signals, you can multiplex them with one or two 74HC251
+
* 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:
 
* define the pinning for the control lines you need like this:
 
   pin(FREQCOUNT_CHANNEL_MULTIPLEX_BIT1, PB1, OUTPUT)
 
   pin(FREQCOUNT_CHANNEL_MULTIPLEX_BIT1, PB1, OUTPUT)
Line 41: Line 41:
 
* duty cycle is stored as 8 bit value
 
* duty cycle is stored as 8 bit value
  
== Durchschnittsbildung ==
+
== Basic Averaging ==
* Durch Interrupt-Verzögerungen etc. kann es zu Fehlmessungen kommen
+
* you will sometimes get a wrong result due to interrupt latencies etc.
* Bei höheren Frequenzen sinkt die maximal mögliche Auflösung
+
* the module always averages the result of ''n'' measurements. You can define ''n'' in the menuconfig.
* Um das zu kompensieren wird immer der Durchschnitt von n Messungen verwendet, n ist im Konfigurationsmenü einstellbar
+
* additionally the highest and lowest value of a averaging-block will be cut off, so ''n''+2 samples are taken
* Zusätzlich wird immer der höchste und der niedrigste Wert einer dieser Durchschnittsreihen verworfen (es werden n+2 Samples genommen)
+
* use a power of 2 for ''n'' to reduce code size and improve execution speed
  
== ECMD-Befehle ==
+
== 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 22: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.