4-wire fan PWM control using a PIC18F4550

Introduction

Once again I am playing around with PIC microcontrollers. Now I finished a complete demo that does this:

  • drive a 4-wire fan, in my case a Noctua NF-S12A using PWM
  • read the fan’s tachometer output to determine its speed
  • show the PWM duty cycle and fan speed on a 16×2 LCD

The demo application starts with a duty cycle of 0, where the fan doesn’t rotate and increases the duty cycle by 5% every 5 seconds, until it reaches 95%. Then it decreases the duty cycle by 5% every 5 seconds until it reaches 0. It keeps repeating this sequence forever.

At the same time it counts the pulses coming in from the fan’s tachometer output and displays the calculated speed every second.

The circuit

The circuit on my breadboard is made after this schematic (click to make it bigger):

pwmdemo

The circuit to drive the fan and to read the tachometer is really simple. The microcontroller runs at 5 Volt and can directly drive the PWM input from a CCP output. The signal from the tachometer needs to be pulled up to 12V, after which simple resistor divider suffices to get that signal at the required TTL levels.

The firmware

The application is written in MPLAB X and uses Microchip’s xc8 compiler. The LCD module is borrowed and adapted from the “PC Case USB LCD” project by Simon Inns. The source is heavily commented so should be quite easy to understand.

The demo

You can see that the fan starts spinning when the system is powered up, but that it doesn’t move at duty cycles of 0 and 5%. It does start spinning at 10%.

The source

PWM_demo_0.1

I sincerely hope that this helps someone.

Secure shell access to the VPS

After setting up the bare VPS, it is time to gain secure access to our Ubuntu Server running on the VPS through a secure shell connection (SSH).

From the standard RFC 4252 that defines SSH:

The Secure Shell Protocol (SSH) is a protocol for secure remote login and other
secure network services over an insecure network.

Of course, the insecure network here is the internet.

We will setup SSH access in two phases:

  1. Setup basic SSH with the normal login credentials
  2. Secure access further with a key

Continue reading “Secure shell access to the VPS”

Driving the 4 digit 7 segment display

Here is the documentation of my next step: driving the LED display. The design and the C code were not really difficult; the steps to put the results here were.

As I noted before I use a PIC 16F887, but CadSoft Eagle didn’t have this component in its library, so I drew a 877 which is pin compatible. Now I wanted to get it right and so I started my own library. Copying the 877 to it and then renaming it to 887 was simple enough. The next step was to get my 4 digit 7 segment display (datasheet in PDF)  in Eagle. I did find a 3 segment display that came close and it took me a bit of time to add the fourth digit. Now my custom library contains two components!

Continue reading “Driving the 4 digit 7 segment display”