基于LM2917N与ESP32的金属车轮RPM测量技术求助
1. Calculating LM2917N Parameters (C1, C2, R1)
The LM2917N converts input frequency to a proportional voltage using this core formula:Vout = (Vcc * R1 * C2 * F) / 2
Where:
Vcc: 12V (system supply)F: Input pulse frequency (Hz)Vout: Output voltage from LM2917N
Step 1: Define Target Output
Choose whether to scale the LM2917N output directly to 0-3.3V or use a voltage divider later. For direct scaling (no extra components):
- Max
F= 17.67Hz → TargetVout= 3.3V
Rearrange the formula to solve for theR1*C2product:R1*C2 = (2 * Vout_max) / (Vcc * F_max)
Plugging in values:R1*C2 = (2 * 3.3) / (12 * 17.67) ≈ 0.0311s (31.1ms)
Step 2: Pick Standard Components
Select off-the-shelf values that meet the R1*C2 requirement:
- Example 1:
C2 = 10µF→R1 = 3.1kΩ(closest standard to 3110Ω) - Example 2:
C2 = 22µF→R1 = 1.4kΩ(closest standard to 1414Ω)
Step 3: Input Filter Capacitor (C1)
Use C1 = 0.1µF to filter noise from the NPN sensor output. If you see erratic readings, increase to 1µF.
2. Adjusting Output Voltage to ESP32's 0-3.3V Range
Two practical options:
Option A: Direct Scaling
Use the R1/C2 values calculated above to set LM2917N's max output to 3.3V. This is simple but leaves no headroom for unexpected frequency spikes.
Option B: Voltage Divider
For more headroom (e.g., set LM2917N's max output to 6.6V), add a 1:1 voltage divider:
- Connect
R_top = 10kΩbetween LM2917N pin3 (output) and ESP32 ADC pin - Connect
R_bottom = 10kΩbetween ESP32 ADC pin and ground
AdjustR1/C2to target 6.6V at max frequency:R1*C2 = (2 * 6.6) / (12 *17.67) ≈0.0622s (62.2ms)
Example:C2=22µF→R1=2.8kΩ(closest standard to 2827Ω)
3. Mapping ADC Voltage to RPM
The system is linear, so mapping is straightforward:
Step 1: Frequency to RPM Conversion
Each revolution produces 2 pulses, so:RPM = (F * 60) / 2 = 30 * F
Where F is pulses per second.
Step 2: Simplified Linear Mapping
Since max RPM (530) corresponds to 3.3V on ESP32, use direct proportion:RPM = (530 / 3.3) * V_ESP ≈ 160.6 * V_ESP
For ESP32's 12-bit ADC (0-4095 raw value), convert to voltage first:V_ESP = (raw_adc_value * 3.3) / 4095
Combine into one formula for raw ADC to RPM:RPM ≈ 0.128 * raw_adc_value
Example Checks
- Raw ADC = 4095 → RPM ≈ 524 (close to 530, accounting for component tolerances)
- Raw ADC = 769 → RPM ≈98.4 (matches 100 RPM target within tolerance)
Additional Practical Notes
- NPN Sensor Interface: Connect sensor output to LM2917N pin1, sensor ground to system ground, sensor Vcc to 12V. The sensor's 12V high/0V low outputs are compatible with LM2917N's input.
- Tolerances: Use 1% tolerance resistors/capacitors for better accuracy.
- Calibration: After assembly, test with a known RPM to tweak the mapping formula if needed.
内容的提问来源于stack exchange,提问作者lucian_v

