Home     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
 Home     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

Author Topic: PWM 3-Wires Fan Controller with RPM feedback (Pulse Stretching Method)  (Read 20483 times)

0 Members and 1 Guest are viewing this topic.


  • Guest
Thank you for the work you put into this website.
Tho I am not active in posting, I have spent a lot of hours reading.

I am very interested in this fan controller and the pc health monitor you have created, and I want to learn as much as possible about this.
I have therfore bought equipment and set up a home lab for this purpose.
My knowledge is low but hopefully I will understand more the next weeks.

Have now tryed to connect the parts on the breadboard, following your schematic and reading the datasheet of the components.
The mosfet schematic from the datasheet, look a bit different from what you have in your schematic.

Hopefully I bought the correct Mosfet?

I need 2 different voltages in this circuit, 12 and 5 volts.
I have a feeling that using two different powersupply might cause problems as they will be connected together via ground in this circuit?

For this reason I have not dared to set power to the circuit yet. (click image for larger picture)



  • Jr. Member
  • **
  • Posts: 73
For a cheap but extremely useful home project power supply look at pike's project

Get an old power supply from a no longer used PC chassis, or get a new one from a PC supplier.

Hope this helps and good luck with your efforts.


  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
Hello Teza.

First of all, some words regarding the PC Health monitor. I began making this project without knowing what size i would end, so it really became huge.  The latest PCBs that i made were 3 x 80 by 65 stackable, one had the 2 PIC micros, one with 8 fan interface and one with temperature and other interfaces. I've never ended this project because i just cannot put an end.

Now, regarding the mosfet, this is indeed the correct one.As for the supplies, you will need 2 different supplies indeed, and you must connect the grounds together. The PC PSU that George suggested is indeed a very good solution for bench power supply ( i use the same one myself for bench supply).


  • Guest
Thanks to both of you for fast reply.

I already have many powersupplies, was just a bit worried about connecting the - 12 and -5 volt together.

I have a faily good feeling of what I need for my project, it is quite close to yours.
Also have a good idea on how everything should be connected and work together.

But before I can continue I'll need to get the fan controller sorted out, and lucy for me, there is a lot to learn as well.

Do you have any pictures of your current setup?
(no need, just curious)


First failure, burned the PIC on first try, it was to hot to be able to hold the finger on it.
What went wrong?

Followed the schematic again and found my 1st mistake straight away.
I am not using the same type of led in my circuit.

The spec on my led is:
Forward voltage: 3,2V min - 3,4V max
Forward current: 20 mA

I need to replace my resistor with one at 82 ohm.
By using a 150 ohm resistor the current should be around 33 mA so this should not kill the PIC.

After checking the datasheet of the PIC it also seems like the circuit is connected correctly.

Checked the PSU and it delivered 6.5V when showing 5V (gives 5V when it shows 3,8V).

I guess this was enough to kill the PIC, or is there also something else that might be wrong?
Can I kill the PIC if I have failed to program it?
« Last Edit: April 30, 2012, 22:27:55 PM by Teza »


  • Guest
PIC and mosfet is replaced, and the fan spins.
By changing on the potmeter i get no visible change in the speed of the fan.
So guess I need to look on the signals to find out what is not as it should be.

Have bought an oscilloscope as well for this project, but the knowledge is poor regarding this instrument.

Is it correct to connect ground on the scope probe to -5V and the probe to the:
- tacho wire of the fan on channel 1 (to read feedback from the fan)(green in your video?)
- pin 9 of the PIC on channel 2 (to read the pwm pulses)(yellow in your video?)
How is the blue channel in your video connected?

Is it possible to damage the oscilloscope in some way on this circuit by connecting it wrongly some how?
« Last Edit: May 01, 2012, 02:09:22 AM by Teza »


  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
why do you need -5V ???? You should use the +12, +5 and gnd. If you connect -5 to ground of the scope then you might get bad results through the grounding of your apartment. Usually, do not do this unless your power supply is isolated (PC PSUs are usually not isolated from mains)

If you connect the ground of the oscilloscope to the ground of the supply (0V), then you can connect the other channel to the positions you mentioned. As for the bluechannel, if i remember well, i had programmed an extra output in the PIC to go high during measurements and low during PWM runtime. I had done this to get synch signal for the oscilloscope, but i'm not sure if this feature exists in the assembly listing that you have. Try porta,2, i think that it still exists in the listing (the LED port).

If you do NOT have negative voltages in your circuit (-5,-12) then it is hard to damage your scope. But this also depends on the protection that your scope has. By the way, which one did you bought? Can you send photos?


  • Guest
It is me mixing different things.
Ground from both psu is connected together in my circuit (was thinking on these as -5V and -12V, but ofc they are 0V)

The fan runs for about a minute before it stops.
The voltage starts climbing slowly from 5 volt when turning the power on (even with the 12V disconnected).
Think I will find another PSU to see if this might be the reason, and replace the components in case some is broken.

The oscillosope is an Agilent Technologies DSOX2024A with activated wavegenerator and education kit.
The 8 digital channels is not yet activated.

More details here

(click on image for larger verson)


Have modifyed the cables on the PSU that will be used in my project, and replaced both of the previous power supplies with this one.
Also found a red LED to replace the one I had as I do not have a 82 ohm resistor.

The circuit now behaves different than earlyer.
The red led is flashing and lights continuous if I stop the fan with my hand.

By adjusting the potmeter there is a visible change in the rpm of the fan.
By turning the pot all the way to the right, I have stable 5.2 volt on my voltneter.
By turning the pot all the way to the left the voltmeter runs up and down from 0,3 to over 2 volt.
Anywhere between minimum and maximum gives the same running in voltage.
(voltmeter is connected to pin 9 of the PIC).

Also tryed to connect the scope to the pin 9 of the PIC (first image) and the tacho wire of the fan (second image)
First image was unexpexted (don't know what this is) and the second at least showed pulses.

« Last Edit: May 01, 2012, 22:15:45 PM by Teza »


  • Guest
Have tryed to connect the LCD to the circuit to read the rpm.
All pixels is lightening, but no text shows.

In the datasheet of my LCD there is added  a 4K7 resistor between pin 6 and ground and 10K resistor between ground and pin 11, 12, 13 and 14. Can this be the problem?

It is a 2 x 16 LCD, but thought it would still show the text as you have used the first two lines on your display?


  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
First regarding the voltmeter, at pin 9 most probably you see the RMS value of the pulses (12x0.707). You should try to scale the time/div of the oscilloscope and measure again at pin 9. You should see pulses there from the PWM
The LED works correct as you describe. The LED pulses when the fan rotates, and remains turned on when the fan is stalled.

The only problem that i notice is the LCD. Pin 6 cannot be connected to ground, since it is the E pin. Are you sure that you use an LCD with the same controller?
Normally, a 2 by 16 LCD with the same controller should work with no change at all.


  • Jr. Member
  • **
  • Posts: 73
Also check the pinouts on your LCD - I've seen some that are not pin1-16, ie one was 15,16,1-14.


  • Guest
I am very grateful for your feedback.

This display belongs to a unused Parallax board I have, bought just before I found this site.
On the parallax board there is some very small resistors before the socket for this LCD. (can't read their value)

If this display is a bad choice I'll order a new one.
From the Parallax datasheet:
The LCD uses the HD44780 series LCD driver from Hitachi, or
equivalent controller. The LCD is connected to a female 14-pin
connector for easy interface with the BS2p24/40 Demo Board
(#45187) and the Professional Development Board (#28138).
Though the device has the ribbon cable and 14-pin connector it may
also be hooked up manually using the diagram on the next page.

From the Hitachi datasheet:
The HD44780U dot-matrix liquid crystal display controller and driver LSI displays alphanumerics,
Japanese kana characters, and symbols. It can be configured to drive a dot-matrix liquid crystal display
under the control of a 4- or 8-bit microprocessor. Since all the functions such as display RAM, character
generator, and liquid crystal driver, required for driving a dot-matrix liquid crystal display are internally
provided on one chip, a minimal system can be interfaced with this controller/driver.
A single HD44780U can display up to one 8-character line or two 8-character lines.
The HD44780U has pin function compatibility with the HD44780S which allows the user to easily
replace an LCD-II with an HD44780U. The HD44780U character generator ROM is extended to generate
208 5 ´ 8 dot character fonts and 32 5 ´ 10 dot character fonts for a total of 240 different character fonts.
The low power supply (2.7V to 5.5V) of the HD44780U is suitable for any portable battery-driven
product requiring low power dissipation.
·  5 ´ 8 and 5 ´ 10 dot matrix possible
·  Low power operation support:
¾  2.7 to 5.5V
·  Wide range of liquid crystal display driver power
¾  3.0 to 11V
·  Liquid crystal drive waveform
¾  A (One line frequency AC waveform)
·  Correspond to high speed MPU bus interface
¾  2 MHz (when VCC = 5V)
·  4-bit or 8-bit MPU interface enabled
·  80 ´ 8-bit display RAM (80 characters max.)
·  9,920-bit character generator ROM for a total of 240 character fonts
¾  208 character fonts (5 ´ 8 dot)
¾  32 character fonts (5 ´ 10 dot)

·  64 ´ 8-bit character generator RAM
¾  8 character fonts (5 ´ 8 dot)
¾  4 character fonts (5 ´ 10 dot)
·  16-common ´ 40-segment liquid crystal display driver
·  Programmable duty cycles
¾  1/8 for one line of 5 ´ 8 dots with cursor
¾  1/11 for one line of 5 ´ 10 dots with cursor
¾  1/16 for two lines of 5 ´ 8 dots with cursor
·  Wide range of instruction functions:
¾  Display clear, cursor home, display on/off, cursor on/off, display character blink, cursor shift,
display shift
·  Pin function compatibility with HD44780S
·  Automatic reset circuit that initializes the controller/driver after power on
·  Internal oscillator with external resistors
·  Low power consumption
« Last Edit: May 02, 2012, 18:21:07 PM by Teza »


  • Guest
When it comes to the pin 9 of the PIC, I can see the changes on the scope while adjusting the potmeter.

Lovely instrument!


  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
so, everything works except the LCD. The controller for the lcd is the same as the one that i use. Give it a shot without the pulldown resistors 4,5,6 and 11 through 14


  • Guest
Ah, I choosed my words poorly.
The LCD is currently connected without these resistors and looks like this:

I was thinking that these resistors might was needed for the display to work propertly.
If so I will buy some to test it. (adjusting the contrast of the LCD don't help)
« Last Edit: May 03, 2012, 00:31:57 AM by Teza »


  • Administrator
  • Hero Member
  • *****
  • Posts: 1849
as i see, the lcd turns on. If it just is powered, you should only see blanks or only one row of black boxes. But i see two black rows, which means that probably you need to set your contrast lower.