Wandering tachometer, a digression

A project log for Ventbot: warm side cool, cool side warm

A speculative DIY register booster project to even out the temps around my home.

WJCarpenterWJCarpenter 09/11/2022 at 21:320 Comments

[Edit, 2 October 2022: OK, forget all that. I set everything up on my breadboard a second time, and everything came out nice, well-behaved square waves. I'm not sure what I did wrong the first time, but I suspect that I didn't correctly set up the pull-up resistor on the fan tach output, even though that was my intention. Since the fans all seem to tolerate the EPS32's 3.3v PWM signal and since the tachometer output is now nicely cycling between ground and 3.3v, I can probably get away with directly connecting things instead of using a signal switching transistor.]

On the way to measuring the loudness of fans running at various speeds, I also wired up the tachometer output to an ESP32 pin to monitor the speed. The somewhat ancient Intel spec for PWM fans (I haven't yet found a newer one) requires a linear relationship between the PWM duty cycle and the fan RPMs, at least for the mainstream part of the graph. The spec generally asks things to meet a +/-10% tolerance. I wanted to see if that actually held true for the PWM fans I have on hand.

The tachometer output from the fan is the 3rd wire on the connector, for both 3-wire (non-PWM) and 4-wire (PWM) fans. It's called "sense" in some diagrams and documentation. The idea is that the controller can get feedback about the effects of the inputs it sends to the fan (whether PWM duty cycle or varying supply voltage) and can dial in some particular RPM target, or at least display the fan speed for humans to geek out on. The spec calls for 2 pulses per revolution, typically implemented via Hall effect sensors. The pulse count divided in half and then multiplied by 60 will give RPMs. (Puzzler for wiseguys: see if you can solve that with just a single multiplication.)

Like many explorers before me, I found the pulse count measurements to be surprisingly unstable. As I changed the PWM duty cycle in increments of 10%, I could hear the fans running faster. But it took a couple of minutes for the pulse counts to settle down, and they never really became completely stable. There was generally a correlation between the PWM duty cycle and the RPMs, but it was only roughly linear. Most perplexing of all, when I got up to the 80-100% duty cycle area, the pulse counts sometimes decreased pretty dramatically.

At first, I blamed the fan manufacturer, but I observed this on five different fans from three manufacturers. What the heck could be going on? The mystery was at least partially resolved when I used a scope to observe the tachometer output. I was slightly surprised by one thing and greatly surprised by another.

The scope trace of the tachometer above was taken at a PWM duty cycle of 40%. (Sorry for the lousy photo. My scope is not configured to let me take a real screenshot.)

The slight surprise was that the pulse outputs were not the nice, tidy square wave I was assuming. Instead, they had non-trivial ramps for the tops and bottoms of the waveform, gravitating toward the midpoint. The waves themselves are roughly 50% up and 50% down. There are some return-to-midpoint mini-pulses within each real pulse.

Hypothesis: The ESP32 might be counting unreliably due to the ramps on the top of the waveform.

The big surprise was in the voltage range of the tachometer pulses. To be honest, I didn't even give this any thought when I wired things up. On the scope, I could see that the pulse waveform was centered around 0 with the waveform going between roughly +/-2.5v. Just through dumb luck, the pulses at +2.5v were visible to the ESP32 3.3v input pins. The ESP32 spec guarantees detecting a HIGH on an input at 0.75*Vdd or higher, or 2.475v. That was pretty lucky, except for one thing. I noticed that as the PWM duty cycle went up, the waveform shifted down. I assume that's somehow related to the power draw for driving the fan. In some observations, I saw it go as low as about 1.8v at higher RPMs. (I'm a software guy, so how a +12v power input can trick a fan into producing output pulses that dip to -2.5v is puzzling to me right now.)

This is more than a hypothesis: When the PWM duty cycle gets high enough, the waveform drops low enough that the ESP32 does not see as many HIGH pulses, so the pulse count actually drops. This is not the fault of the ESP32, of course.

Surprisingly, the Intel spec cited above does not actually say what the voltage range of the tachometer should be, though it does say the signal should be pulled up to the 12v supply. I have already been using the ESP32 internal pull-up to 3.3v. The pullup makes some kind of difference, but I don't yet grok what it does. Various "someone on the Internet" postings make conflicting claims. Some say the waveform varies from 0v-12v, some 0v-5v, and almost all give the useless disclaimer to check the datasheet for the fan in question because it varies by manufacturer. The disclaimer is useless because you are unlikely to find a datasheet with that info for any US$10 case fan. (If you do, let me know. I'd like to read it.)

I'm still pondering how to resolve these two things. Luckily, observing the tachometer output is more of a curiosity of mine  than a functional necessity for this project. I have plenty of time to figure it out. I know from real, physical experiments that all 3 brands of fans that I have on hand put out a pulse waveform that is generally in the area of +/-2.5v, and I know that logic inputs on the ESP32 are expecting 0v-3.3v, more or less. Sooner or later, I'll settle on a reliable way of doing that level shifting. My intuition is that some "too cheap to meter" transistors will do the job.