Frequency Counter
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 0Kommando | 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. |