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 (…")
 
(some translation)
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
* 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
 +
 
 +
== 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
  
 
== Durchschnittsbildung ==
 
== Durchschnittsbildung ==

Revision as of 22:15, 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
  • 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

Durchschnittsbildung

  • Durch Interrupt-Verzögerungen etc. kann es zu Fehlmessungen kommen
  • Bei höheren Frequenzen sinkt die maximal mögliche Auflösung
  • Um das zu kompensieren wird immer der Durchschnitt von n Messungen verwendet, n ist im Konfigurationsmenü einstellbar
  • Zusätzlich wird immer der höchste und der niedrigste Wert einer dieser Durchschnittsreihen verworfen (es werden n+2 Samples genommen)

ECMD-Befehle

Hinweis: Channel ist momentan immer 0
Kommando Funktion
fc freq Channel Gibt die Frequenz in Hz zurück (Achtung: 32 Bit).
fc ticks Channel Gibt die Frequenz in CPU Ticks zurück (Achtung: 32 Bit).
fc duty Channel Gibt den Duty Cycle als 8 Bit Wert zurück (0-255 dezimal).
fc %duty Channel Gibt den Duty Cycle in Prozent zurück.