Thursday, 10 August 2017

Salvaging electronic parts - Part 1

Summary
Prompting this blog was my dismay which was caused during a recent scrounge through some component draws for a humble load resistor. The culprit is shown below, just an innocuous resistor right!


Old Resistor
Old resistor
Before using the resistor a standard multimeter check was performed. This measurement indicated that the resistance was unexpected high resistance. After pulling lightly on the two legs of the resistor simultaneously the reason for the high resistance was apparent, mechanical failure. This faulty resistor would have been moved around in a draw of spare parts for the better part of ten years before it was used, possibly adding to its demise.


Old faulty resistor
Old faulty resistor
Whether mechanical failure of the resistor occurred during manufacturing or more likely as a result of being mistreated during storage, this highlighted the limited shelf life for salvaged or even new electronic parts. Certainly some electronic parts are more susceptible to the rigors of handling, storage damage and part aging.

Salvaging Parts
This blog and subsequent blogs on the same subject, intend on showing some of the parts than can be salvaged from electronic equipment and possible issues that can be experienced with these parts. Whilst not all factors that damage electronic parts has been accounted for, the factors mentioned should serve as a guideline for those performing salvaging themselves.

A fully functioning control board from a NESS security system (D8X D16X) will serve as the example. For any board being salvaged a check with a multimeter can save the hassle of removing an already faulty component.


Ness Alarm Control Board
Ness alarm control board
The NESS control board has had the heatsink situated within the blue box shown above, however this was removed for visibility of surrounding components. In fact this heatsink would be considered the first salvaged part!

Power Supply
Within the bounds of the blue box shown in the image, are parts associated with a linear power supply. Parts to be salvaged could include the red varistors (V56ZA05P), DIP bridge rectifier, large electrolytic, linear regulator and associated surface mount capacitors.

Microcontroller
The red box identifies the alarm panel processor and another smaller power supply. Due to the age of the alarm panel board the processor, a Cypress Semiconductor MB89F538, this part is listed a obsolete which may preclude it being removed. The remaining crystal, fuse, DIP8 regulator, surface mount capacitors and logic level FET - BUK9245 could all be removed.

Line Out
For the telephone interface, shown by the yellow box, are parts such as optocouplers, a relay and an LMV324 rail to rail op amp. All these parts can be readily used in new projects.

Input Section
The input section has not been particularly noted for parts to salvage although the MELF and larger surface mount resistors come in useful for higher voltage designs. Of interest in this section is the PCB design itself and use or lack of components. More on spark gaps in a following blog.

Sections Not Noted
In the remaining sections are more logic level FET's BUK9245, ULN2803 driver and connectors would also come in useful when designing.

Salvaging Equipment
The tools required for removing salvaged electronics will vary depending on the equipment and budget. For most types of salvage work equipment such as needle nose pliers, SMT tweezers, a second gas or mains powered soldering iron and a range of drivers for different types of screws and bolts. On occasion equipment designers use TORX or HEX bolts to secure equipment.

As an example a computer power supply, which is commonly a single side circuit board, can be stripped of electronics using a soldering iron and a solder sucker or wick.

For circuit boards with tracks on both sides, with plated thru holes, desoldering can use more consumables such as solder wick especially for parts with multiple legs.

Surface mount components can be removed using additional equipment such as a soldering station with tweezers or a reflow oven can reduce issues relating to mechanical stress on electronic parts or over-heating when compared to using traditional solder wick. For the higher end user a hand held air convection tool offers timed temperature control however it is usually out of the price range for most hobbyists.

One noteworthy item not commented enough in other blogs for my liking, is the use of Personal Protective Equipment (PPE) when handling equipment made with lead based solder. This should not be taken as an alarmist comment although viewed as a simple measure to limit ones exposure to lead during the salvaging process.
Ansell Cotton Gloves
Ansell cotton gloves

Workpiece Holding
When small to medium sized circuit boards, up to 150mm in width, are worked on for salvaging, a circuit board holder of any variety assists when changing between the component and solder sides of the board. 


Circuit board holder
Circuit board holder

For the salvaging process with the Ness control board a PCB holder from Altronics, T2356 shown above, was used.


Salvaging Components
To begin with the two and three pin components, with thru-hole (TH) leads, will be removed from the NESS board. As mentioned above these components consist of capacitors, varistors and regulators.


Flooding capacitor pins with solder
Flooding capacitor pins
Capacitor - Thru Hole
In order to transfer more heat from the soldering iron to the pad on the circuit board, adding a small amount of solder to the pads, of the part being removed, usually helps. The component can then be pulled and rocked out of its original position.


Capacitor removed
Capacitor removed
Excessive pulling force applied to the leads of the capacitor whilst desoldering may lead to the pins being partly lifted from the capacitor body. When a visible change is lead length can be seen, then the part should be discarded. Overheating a leaded capacitor is possible although unlikely in most instances. Many leaded capacitors have the maximum working temperature listed on the capacitor.

Regulator - Thru Hole
A similar method to the capacitor removal can also be applied to three terminal regulators such as the 78xx series.


Flooding Regulator Pins
Flooding regulator pins
As with the capacitor, it should be noted than one or more of the regulator pins may be connected to large PCB tracks, fills or entire planes on the circuit board. These larger areas of copper require more heating to melt the solder, so flooding the pins with some extra solder can facilitate a better transfer of heat from the soldering iron.


Regulator removed
Regulator removed
Post removal the regulator, and similarly any other removed parts, would benefit with clean-up to remove the excess solder from the pins. A 78xx series leaded regulator from ST has a storage temperature of 150C, damaging these robust parts is also difficult.

Relay- Thru Hole
A through hole relay, which usually has 6 or more leads, can be removed with the old favourite desolder braid or a solder sucker.


Desoldering through hole relay
Desoldering through hole relay
While using desolder braid to remove any electronic component, a fan or fume extractor is strongly recommended. Well known brand Weller has an article "Health Hazards From Inhaling and Exposure To Soldering Fumes" describing the risks of inhaling fumes created as a result of desoldering with braid.

Desoldered relay
Desoldered relay
One benefit of using the desolder braid is that during the process of desoldering, while the solder is being wicked from the solder joint, the position of the soldering iron tip can be moved around the component pin. This allows for cleanly desoldered pin and prevents the pin from sticking to the wall of the pad.

Surface Mount Components
Removing a surface mount component can pose its own difficulties. Some components can be glued, part of the reflow soldering process, or held to the board with Silastic for mechanical stability. In these instances removal of the component may require some more inventive solutions.

Capacitor - Surface Mount
For removal of a surface mount capacitor the soldering iron tip can usually be applied directly to the exposed pad of the capacitor to melt the solder and the component leg lifted away from the circuit board pad.


Capacitor Surface Mount
 Surface mount capacitor
To remove smaller capacitors, each of the exposed legs may need to be heated more than once and the part rocked free. This method is recommended because beneath the capacitor is a plastic former which holds the component flush with the circuit board. This plastic former can be melted if the soldering iron is kept on the component leg for several seconds.

Removed surface mount capacitor
Removed surface mount capacitor
Opto-Coupler - Surface Mount
For removal of a surface mount opto-coupler the soldering iron tip can used to heat the two circuit board pads located on one side of the component. There is usually more solder on the opto-coupler pads than components such as resistors and capacitors so additional solder should not be required.


Opto-coupler tweezer removal
Opto-coupler tweezer removal
A tip for removing these types of devices is to insert the arms of some stainless tweezers beneath the component. When the two pads on the same side of the device are heated, only a small amount of force is needed to lift the component from the circuit board.

Opto-coupler removed
Opto-coupler removed
The same technique is applied to the remaining fixed side of the component. Using the tweezers also allows removal of the heated component without the need to touch it directly.

MOSFET - Surface Mount
The last part to removed in this blog is a MOSFET in a DPAK case type. As with the opto-coupler using tweezers can be helpful to lift the component legs.


Desoldering leg of MOSFET
Desoldering leg of MOSFET
With no additional solder and the soldering iron applied to the leg of the MOSFET, only a small amount of force is needed to lift each component leg from the circuit board using the tweezers. It may also pay at this stage of the removal to use desolder wick to ensure that the legs of the MOSFET are in no way connected to the circuit board.

To heat the soldered tab of the MOSFET, adding some solder to the tab joint aids in heating the surface mount pad and MOSFET itself.


Heating MOSFET tab
Heating MOSFET tab
Heating the device and the pad may take several seconds. When the solder near the tab begins to melt, applying horizontal force to the component usually allows the part to be slid off the pad. Heating the tab of the MOSFET for an extended time should be avoided.

Desoldered MOSFET
Desoldered MOSFET
The maximum time a component should be heated can be based partly on the soldering process reflow curve. This curve is not always available from manufacturer data sheets especially for discrete devices so the peak temperature could also be used.

For the MOSFET that was removed from the NESS circuit board, BUK9245-55A, the device is several years old and the MOSFET 'storage temperature' of 175 degrees the only details listed.

BUK9245-55A Characteristics
BUK9245-55A Characteristics
As a general rule of thumb the solder reflow peak temperature should not be exceeded for more than 30 seconds. Applying this to the MOSFET removal, with a 260 degree soldering iron set temperature, then it should be safe to use 15 seconds of heating on such a device.

Finally as with any component it should be tested thoroughly before entering the confines of any spare part storage system!

Sunday, 16 July 2017

Paralleling Diodes with Resistors

Summary
This blog demonstrates how diodes can be connected in parallel with a suitable series resistance per diode. These current sharing resistors are required for each paralleled diode primarily to handle the negative temperature coefficient (NTC) effect on diode forward voltage.

Using resistors with multiple diodes may be required for a number of reasons such as design costs, package size, availability of required diode(s) or something as novel as limited space on a printed circuit board (PCB).

The method using current sharing between diodes is particularly useful for designs where space is a premium and adding a thermal mass between diodes is not possible.

Literature
There is documentation relating to paralleling diodes although it can be difficult to locate online. ST Micro published an Application Note AN599: Parallel Operation of Power Rectifiers in 1993 and Application Note AN4381: Current Sharing in Parallel Diodes.

Diode Matching
Diodes bearing the same part number are made with similar characteristics however devices are never identical. Slight variations in diode characteristics such as forward voltage 'Vf', during parallel diode operation, can result in one diode sharing more current than others.

Diode matching, similar to LED binningcan be performed through a process of measurements targeting diode forward voltage drop for various currents (VI curves). Attention should also be made to the diode temperature. The solution of matching diodes may be suitable for low volume specific designs or product prototyping however this is not suited for volume (mass) production.

Diode Testing - No resistance
To illustrate how one diode, in a two diode parallel setup, will eventually end up at a higher temperature than the other a bench test was conducted.


Dual Schottky Diodes in Parallel
Dual Schottky diodes in parallel

Two Schottky diodes (ON Semiconductor parts) were soldered in parallel. A 1.8R 5W resistor was used to limit the 
power supply current. 


Temperature of one Schottky Diodes when operated in parallel
Temperature of one Schottky Diodes when operated in parallel
Temperature measurements were performed at regular intervals using a FLIR C2 thermal camera and the power supply used for testing was a Rigol DP832.

The power supply voltage was under 2.5VDC. The total power supply power was limited to 1.3W.

Temperature Measurements: Schottky Diodes no resistor
Temperature Measurements: Schottky Diodes no resistor 
As shown in the table above, one of the diodes began to heat more rapidly in under thirty seconds. After four minutes the test was not continued because the diode junction temperature Tj was approaching the devices specified rating of 125C.

Diode Testing - 0.01R resistance
For the second test the two diode setup was modified to include a 0.01R resistor on the cathode of each of the diodes. This resistor is the standard type used for current sensing.

These resistors were added to test if a small resistance, such as a PCB traces or the resistance in leaded components, would balance the current between the diodes.

Dual Schottky diodes in parallel with serial 0.01R resistors
Dual Schottky diodes in parallel with serial 0.01R resistors
The power supply power was again limited to 1.3W and temperature measurements conducted.

Temperature Measurements: Schottky Diodes 0.01R resistor
Temperature Measurements: Schottky Diodes 0.01R resistor
The results above show that the diodes began to heat at a more consistent rate compared to no series resistance until five minutes. After six minutes one of the diodes had begun to heat more than the other and was drawing most of the current.

This test indicated that such as low resistance was insignificant and unable to balance the drop in diode forward voltage caused by the heating of the diode.

Diode Testing - 1.3R resistance
The two diode setup with resistors was modified to use a 1.3R resistor (0805) on the cathode of each of the diodes. These resistors values were guided by the formula shown below.
Measuring each of the diodes forward voltage Vf with a digital multimeter, diode 1 read 0.64V and diode 2 read 0.65V. With approximately 250mA being equally passed by each diode the series resistance calculates to 2.6R, this value was halved to reduce the resistor power dissipation and tested.

Dual Schottky diodes in parallel with serial 1R3 resistors
Dual Schottky diodes in parallel with serial 1R3 resistors
Resistors with the case size 0805 were fitted as shown in the image above.

Temperature Measurements: Schottky Diodes 1R3 resistor
Temperature Measurements: Schottky Diodes 1R3 resistor
The test results showed the diode temperature stabilized after two minutes.

The above results however were a brief snapshot of a lengthy soak test which did show that some variation in diode temperature did eventuate. The difference in the temperature of the two diodes was stable and no runaway was seen during testing.

Temperature of one Schottky diodes when operated in parallel with series resistance
Temperature of one Schottky diodes when operated in parallel with series resistance
When viewed thermally the balance between the diodes can easily been seen when compared to the test where no series resistance was fitted.

Current Sharing - 1.3R resistance
Using a multimeter the forward voltage across the resistors was measured after 10 minutes. One resistor showed a voltage drop of 0.374V and the send 0.363V. 

Using the voltage across the resistors to determine currents showed that 0.289A and 0.279A flowed through each resistor diode legs.

It should be noted that the current through each resistor diode leg is dynamic and should never be considered exact. Additionally the current through each leg should not be thought of as balanced. When the third test was allowed to run for a considerable time a temperature delta of 10 degrees was often seen between the two diodes.

Summary
For the tests conducted in this blog, with a pair of ON Semiconductor Schottky diodes, adding a suitable value series resistor to each of the diodes facilitated current sharing, without the need for thermal bonding.

Fitting the two diodes to a common thermal mass or thermally coupling the diodes may also be another solution to balancing the current sharing although not investigated in the scope of this blog.

Additionally the tests employed a benchtop DC power supply as the source. Other supplies such as AC or pulsing supplies (PWM) with shaped waveforms and parallel diodes may require more specific testing to determine operational characteristics for a parallel diode design.

Design Suggestions
Listed below are some design suggestions when using diodes in parallel.

1. Choose diodes with the lowest forward voltage (Vf) that can be afforded for the design. This aids in reducing heat dissipated which is especially a concern for enclosed spaces.

A single bigger diode is not always a better solution if it is dissipating significantly more heat.



2. For the current and voltage rating of the diode, add an appropriate safety margin suitable for the design.


3. A design with parallel diodes operating with continuous DC current may experience less stress than parallel diodes operating as freewheeling (flyback) diodes for inductive loads and therefore should be rated accordingly.


4. For the current sharing resistor select an appropriately rated device for power dissipation. When designs use PWM at high currents the resistors may also benefit from being rated for pulse withstanding.


5. Test, test and test. Testing does not refer to the product operational or consumer specifications but the working limits of the design. To understand your product it should be tested to failure!

Monday, 26 June 2017

Recover Mac Files Old SCSI

Summary
This blog demonstrates how a Linux PC and SCSI PCI card can be used to retrieve the files from the SCSI hard disk of a twenty year old Power Mac.

Power Mac
The Power Mac 6100/66 was possibly the third Mac that I had the pleasure of owning back in the day. The 'pizza box' as it was affectionately known, had 24MB of RAM, 16bit colour, a proprietary Ethernet interface and no USB connection or CD burner.


Power Mac 6100/66
Power Mac 6100/66
Somehow twenty years later, my belief was that the machine had long been retired from use, the old Mac turns out to have a family members five year old files stored on the hard drive. To make life a bit more interesting the floppy drive, similar to most of the plastic in the old Mac, has degraded to the point of failure. 
Inside a Power Mac 6100/66
Inside a Power Mac 6100/66

Fortunately the Mac still booted verifying that the internal SCSI drive was mountable. After removing the cover from the Power Mac the non-Apple drive was easily visible at the bottom left hand corner of the above image.

SCSI Controller
After performing price comparisons between a second hand Apple Network adaptor and a replacement floppy drive, it turned out that there was alternative solution. One of the online stores was selling off some AdvanSys ABP 3922 SCSI Controllers.


AdvanSys PCI SCSI Controller
AdvanSys PCI SCSI Controller
CNET had a basic specification for the ABP 3922 which indicated this card was suitable for PC or Mac. 


AdvanSys PCI SCSI Controller Rear
AdvanSys PCI SCSI Controller Rear
The online store price for the card ended up significantly cheaper than purchasing an Apple Network adaptor and also less than a suitable replacement Panasonic 1.44Mb Superdrive.
AdvanSys ABP 3922 SCSI Controller
AdvanSys ABP 3922 SCSI Controller

Linux
Fitting the SCSI Controller into an existing Linux tower running Mint, a quick check of the PCI bus using LSPCI this indicated that the card has been detected.


PCI SCSI Card Identification
PCI SCSI Card Identification
With the card detected in Linux the Mac SCSI drive was hot plugged to the 50 way IDC connection and powered.


Mac Formatted SCSI Drive Connection
Mac Formatted SCSI Drive Connection

Under Linux Mint the drive auto mounted and could be located in the usual location under the Computer icon.


Linux Mint Computer Icon
Linux Mint Computer Icon
As part of basic troubleshooting, a drive that has not auto mounted could be checked in the Linux 'Disks' tool.

Linux Mint Disks with Mac Drive
Linux Mint Disks with Mac Drive

Old Mac drives were formatted in HFS or HFS+ both of which Linux will commonly mount without any issues.

File Retrieval
With the SCSI drive mounted the required files could be accessed and copied off the SCSI drive. It should be noted that some specific files relating to preference files for games were not able to be copied.

Summary
Using an older model SCSI PCI card, which suits an existing motherboard together with Linux, was an inexpensive solution to retrieve files from an old Mac drive. The same methodology may even work for some of the single board computers with the addition of a USB to PCI bridge or for other platforms a suitable USB interface such as the discontinued but still available Adaptec USBXchange adaptor.

Saturday, 17 June 2017

PSoC4 DC Fan Controller with I2C

Summary
This blog implements the end to end design of a temperature measurement and fan speed control project using the PSoC 4. The project utilizes the OneWire temperature sensor component for the Cypress PSoC with speed control of a DC fan using PWM, fan speed measurement and an optional communications over an I2C (SMBus) interface. 

CY8CKIT-049 - Courtesy Cypress Semiconductor
CY8CKIT-049 - Courtesy Cypress Semiconductor
I2C connection could be implemented using another Cypress PSoC, Arduino, Raspberry Pi (RPI) or by even breaking out the internal I2C bus on a standard PC motherboard.

Most of the features mentioned in this project have already been implemented or tested as separate projects by other bloggers or in this electronics blog. More specific information regarding each feature used in this project will be linked accordingly.

Project Features

Fan Controller
- Input voltage: 6 to 30VDC
- Operation: Standalone or bus controlled

Fan Control Output
- 6 to 30VDC @ 10A
- PWM control
- Tachometer feedback

Temperature Sensor
- OneWire Bus (single sensor)

Communications
- Optional I2C (SMBus) compatible

Hardware: CY8CKIT-049
For hardware testing the OneWire interface and DC fan control functionality, the Cypress CY8CKIT-049 prototype development board was used. A previous blog showing the use of a OneWire component by Evg Pavlov for the Cypress 049 development kit was used as the template for this project.

Hardware: Comair DC Fan

The 4 wire Comair Rotron DC Fan, model CD24R7X, was used for this project. This fan includes a tacho output and a program aka 'speed control' input. When the program input connects to 0V by any resistive element, the speed of the fan can be changed within a range. The change in fan speed is from 50% to 100%.

Hardware: Temperature Sensor

The DS18B20 digital thermometer with communication over a single wire bus was used for the project. Specifically Adafruits probe MPN#381 was used.
As tested in a previous temperature sensing project, the One Wire library from Pavlov was used.

Hardware: Raspberry Pi

A Raspberry Pi (RPI) 2 Model B was used during the testing of this project. This Single Board Micro (SBC) was used to verify that the PSoC SMBus was connected. Only the address of the PSoC I2C device was read by the RPI.

Bread-boarding 
Pin headers were soldered to the bottom side of the CY8CKIT-049 kit so that the board could be plugged into 25.4mm (0.1") standard breadboard. Shown below was the preliminary setup on solderless breadboard.


DC Fan Controller
DC Fan Controller
The following is a breakdown of the coloured boxed sections shown in the image below:
Black -  Cypress CY8CKIT-049 kit
Yellow - Temperature probe (DS18B20)
Green - Comair CD24R7X DC PWM fan
Blue - Optocoupler isolation
Purple - MOSFET for DC fan

Breadboard Sectional Breakdown for PSoC DC Fan Controller
Breadboard Sectional Breakdown for PSoC DC Fan Controller
Design and Parts Selection
Optocouplers 'opto' were initially chosen to provide isolation between the PSoC digital lines and the DC fan during testing. The two signals connected to the fan are the tacho feedback (PSoC input) and the program control line 'speed' (PSoC output).

The tacho feedback from the fan is an open collector output meaning than only an on-board pullup resistor was required to drive the LED of the opto.

For control of the DC fan program input, a series current limit resistor between the PSoC and LED of the second opto was also required.

For the final design discrete components were used to provide protection for the PSoC digital lines instead of optical isolation. This aids in reducing cost and final board area.

A MOSFET, of the N channel persuasion, for controlling power to the DC fan was chosen with four criteria. Firstly a gate to source voltage below 5V DC so the device could be driven from the PSoC directly without a separate gate driver, a drain to source current above 10A and a drain to source resistance less than 20mR when the gate voltage was at 5V DC. The maximum drain to source voltage, could be considered the fourth criteria, which was selected to be well above the nominal 24V DC supply voltage.

Using the above criteria for on an online search on Digikey yielded a number of results, some 500 plus 
MOSFET's. The device that appeared interesting was the On Semiconductor - NTTFS5C673NLT although there were several other candidates such as the NTTFS5820NLT or the BSC100N06LS3. The ON Semi device has been released only three months after writing of this blog, and the footprint was a small 3.3mm square.

To drive the MOSFET during testing a 100R gate resistor was added in series with the output of the PSoC. Additionally to ensure the state of the MOSFET gate while the PSoC was starting a 220k pulldown was added between the gate and 0V.

PSoC Development
At the time of writing PSoC Creator 4.1 was earmarked for release so this project was initially developed in Creator 4.0 then migrated to 4.1 to make use of the most recent Cypress components and bug fixes.

To ensure the CY8C4245AXI-483 would have the resources available to facilitate a bootloader, One Wire bus, UART, PWM and tacho frequency measurement the project was built on the bench before proceeding with the hardware PCB design.


PSoC Creator DC Fan Controller
PSoC Creator DC Fan Controller

Bootloader / Bootloadable

Cypress includes both a bootloader and bootloadable component in PSoC Creator which allows the PSoC to be field programmed (upgraded) over communications interface without the need for an In Circuit Programmer (ICP) such as the MiniProg3.

This project utilised the UART component for the bootloader interface together with an external FTDI USB device. Having serial communications on the board provides an interface for debugging and initial testing.

One Wire Bus
The One Wire component, written by Evg Pavlov, was used for the communications to the external Temperature probe (DS18B20 based). Only one of the temperature sensors channels was required for this project.

Tacho Measurement

For measurement of the fan rotational speed, a time gated approach was selected. A PWM component was used to produce an output pulse of almost one second, with a very small interval between pulses, which served as the gated window for the Timer. The timer component was configured to count the number of pulses from the DC fan tacho input over the one second period. Since the DC fan produced two pulses per rotation the result was divided by two.

DC Fan Speed Control (PWM)

To control the fan speed, in the range of 50% to 100% of full speed, a PWM component was utilised. An output pin which was driven by the PWM component was configured as a strong drive in order to drive the MOSFET. This section of the PSoC Creator Schematic also included a Power pin which allowed the fan to be controlled software.

Communication (option)

For future expansion or communications interfacing with a PMBus or I2C, two components were added to the project. Testing was to be conducted with a Raspberry PI SBC so the I2C component was disabled.

Test Code
To test the temperature sensor, tacho reading and PWM fan control test code was created for the 049 kit.



//==============================================================================
//
// Thermometer controlled DC Fan
//
//==============================================================================
#include <project.h>
#include <stdio.h>
#include <stdbool.h>

/* Global Variables */
static volatile CYBIT flag_Timer    = 0;
volatile uint8 tacho_data_ready     = 0;

/* Function Prototypes */
void Initialize(void);
void ReportTemperature (void);          /* convert temperature code to deg C and send to UART */

//==============================================================================
// Timer Interrupt
//==============================================================================
CY_ISR(isr_Timer)                       /* ISR Timer to report temperature at regular intervals */
{
    flag_Timer = 1;
    isr_Timer_ClearPending();
    PWM_1_ClearInterrupt(PWM_1_INTR_MASK_CC_MATCH);
}


//==============================================================================
// Timer Interrupt
//==============================================================================
CY_ISR (isr_CounterResult) {
    tacho_data_ready = 1;      
    Timer_3_ClearInterrupt(Timer_3_INTR_MASK_CC_MATCH);
    isr_Counter_ClearPending();
}

//==============================================================================
// Init PSoC 
//==============================================================================
void Initialize(void)
{
    UART_Start();                       /* UART start */
    UART_UartPutString("Temperature sensor Maxim DS18B20:\r\n");
    OneWire_Start();                    /* OneWire start */
    if (OneWire_CheckPresence() == 0x1) {
        UART_UartPutString("Sensor detected\r\n");
    }
    Timer_2_Start();                    /* Start clock for measurement and report timing */
    isr_Timer_StartEx(isr_Timer);       /* Attach handler */  
    PWM_1_Start();                      /* One second window timer for tacho measurement */
    Timer_3_Start();                    /* Pulse counter for tacho, 2PPR */
    isr_Counter_StartEx(isr_CounterResult);
}



//==============================================================================
// Convert temperature code to degC and 
// Send result to Terminal using UART
//==============================================================================
void ReportTemperature(void) 
{
    char strMsg[80]={0};                /* output UART buffer */
    char buf[8];                        /* temp buffer */
    static uint32 counter = 0;          /* sample counter */
    float res;
    counter++; 
           
    strcat(strMsg, itoa10(counter, buf)); 
    strcat(strMsg, "\t");
    strcat(strMsg, OneWire_GetTemperatureAsString(0)); strcat(strMsg, "\r\n");
    UART_UartPutString(strMsg);
    
}


//==============================================================================
// Main
//==============================================================================
int main()
{
 uint8_t i;
 char c;
    char buf[8];
    char strMsg[20]={0};
    uint8 temp = 0;

 CyGlobalIntEnable;                  /* Enable global interrupts */
    
 while(Operating_Mode_Read());       /* Wait for button press to continue (gives time to switch to a terminal window) */
    Initialize();
    PWR_Fan_Write(true);                /* Fan ON for initial testing */
    flag_Timer = 1;                     /* Force first measurement */
    
    for(;;) 
    {     
        if(flag_Timer)                  /* read DS18B20 on timer, intervals 1sec */
     {   
            flag_Timer = 0;
            OneWire_SendTemperatureRequest();
        }
        
        if (OneWire_DataReady)          /* DS18 completed temperature measurement - begin read data */
     {   
            OneWire_ReadTemperature();
            ReportTemperature();
        }
        
        if (tacho_data_ready == 1) {
            temp = Timer_3_ReadCaptureBuf(); /* Divide by 2; */
            sprintf(buf, "%03d ", temp);
            UART_UartPutString(buf);
            tacho_data_ready = 0;
        }
    }  
}

/* [] END OF FILE */



Testing
With most of the interfaces to the Cypress PSoC previously tested, any MOSFET losses at full load were of most interest. The datasheet for the MOSFET shows that the drain to source resistance is 13.3mR for a 4.5V gate drive.

Instead of testing with the fan and needing to handle the commutation caused by the fan itself, a 1R 1% resistor was used in place of the fan. The current limit on the power supply was set to 1.2A and the voltage measured across the 1R resistor, approximately 2.22V and across the MOSFET 0.056V. Gate voltage was 2.50V.

For the 0.056V drop across the MOSFET the resistance drain to source was around 47mR. No issue with heat dissipation at such low current through the device.

Schematic Design
For the controllers power supply, a Texas Instruments LMR14203 was used for the 5V supply. The switch mode device was set for 5V rather than a lower voltage so that MOSFET controlling power to the DC fan could be driven directly from the PSoC.

A last minute addition to the design was an optional voltage monitor for the input supply (24V). Monitoring of the input supply could be achieved using the ADC in the PSoC.


DC Power Supply
DC Power Supply
The PSoC used in the schematic was the same as the development board, a CY8C4245AXI-483. Using the Design Wide Resources window from PSoC Creator as a reference connections were drafted in the schematic.


PSoC Creator Design Wide Resources for DC Fan Controller
PSoC Creator Design Wide Resources for DC Fan Controller

Connections to the PSoC are shown in the capture below.


PSoC Connections
PSoC Connections
The above image shows the connections for the digital and analogue power, programming header for a MiniProg and option resistors.


PSoC Input Protection
PSoC Input Protection
For the prototype board some basic input protection was added by means of a series 10R resistor and rail to rail steering diodes as shown in the above capture.

PSoC Filtered Power
PSoC Filtered Power
To complete the PSoC portion of the design, the capture above shows the filtered 5VDC power for the digital and analogue supplies. This type of filtering and decoupling of the main supply is essential considering that a switch mode is being used for the main 5V supply rail.


Comair Fan Connections
Comair Fan Connections
The above capture shows the external connections for the Comair Rotron DC fan. Pins 1 and 6 are the main 24VDC power supplying the controller board and the remaining pins 2 to 5 are the connections to the Comair fan. There is a reason that the 0VDC for the fan and the main 0V supply are side by side on the connector which has to do with the routing of the circuit board.

One Wire Connection
One Wire Connection
One Wire connection is shown in the capture above.

I2C Bus Driver Connection
I2C Bus Driver Connection
I2C connections is optional on this design and the capture above is a datasheet implementation for testing. Protection could be added to the line facing side of the PCA9615 by means of TVS diodes and even small series resistance.

Schematic Top Sheet
Schematic Top Sheet
Finally for this Altium design, which uses a top sheet to connect all lower level sheets, the capture above illustrates the connections between sheets with power connections being global to all sheets.

Controller Enclosure
In selecting an enclosure for the controller the two requirements were the price and size, cheap and small as possible.


Altronics enclosure H9404
Altronics enclosure H9404
A supplier, Altronics, has some very affordable snap together enclosures and out of this selection the H9404 model looked fit for the purpose. Inside the enclosure are four posts to mount the controller circuit board then the removable lid snaps back on. 

PCB Design
Beginning with a blank layout in the PCB layout software, the datasheet for the plastic enclosure was consulted to determine the dimensions of the circuit board to be mounted inside. Instead of using the actual dimensions specified by the datasheet, the circuit board was reduced in size in both dimensions by 1mm to account for changes in the enclosure during manufacturing or inaccuracies when the circuit board is cut, although the latter is rare for most manufacturers.


Circuit board dimensions with guides
Circuit board dimensions with guides
The above capture shows the circuit board with dimensions of 64 x 44 mm and work guides for setting the mounting post locations. For such as small circuit board work guides are hardly required, however if they are available in the circuit board layout software it can be good practice to use guides.


Circuit board unrouted with double sided placement
Circuit board unrouted with double sided placement
To simplify the part placement on the controller circuit board the design was made double sided. The spread of components between top and bottom layer follows a rule often applied to double reflow designs which is one side for heavy components and the opposite side for light. Use of this layout may be suitable for home reflow ovens.
Circuit board routed with double sided placement
Circuit board routed with double sided placement
Shown above is the routed four layer prototype board. The top and bottom are the signal layers with the two middle planes utilised for power.

PCB Population
Back from manufacture at PCBWay the unpopulated circuit board is shown below.


Blank DC fan controller board
Blank DC fan controller board
To begin with, only the power supply section was fitted to the board to ensure the 5VDC supply was stable.


Fan DC power supply section
Fan DC power supply section
After powering up the board to 25VDC the on-board supply was confirmed to be working at 5.05VDC.

The Cypress PSoC and associated components were fitted to the board for initial testing with the One Wire sensor. Utilising a circuit board holder is an efficient tool well when board under test required probing on either side.


DC fan controller bench testing
DC fan controller bench testing
Draft Code
With the OneWire code tested, a first draft of the controllers code was compiled and programmed. Initially a lower temperature was set to trigger the fan. The draft code is listed below.


//==============================================================================
//
// OneWite temperature controlled DC Fan
// 10/10/2017    Greg L      Initial write for functionality testing
//
//==============================================================================


#include <project.h>
#include <stdio.h>                                  /* Required for sprintf */
#include <stdbool.h>


/* Global Defines */
#define debug                           1           /* Debug via serial port */
#define Fan_Hyst_Compare                60u
#define Temp_Low_Thres                  2700u       /* Temperature deg C div 100u */
#define Temp_High_Thres                 2900u       /* Temperature deg C div 100u */


/* Global Variables */
static volatile CYBIT flag_Timer        = false;
volatile uint8 tacho_data_ready         = false;    /* Tacho data ready flag - modified by ISR make volatile */
volatile uint16 Tacho_Counts            = 0;        /* Made global to share with ReportData function */
uint16 Last_Temp_Read                   = 0;


/* Structure */
struct {
    uint8
    Fan_run                             : 1,        /* Start after power cycle */
    Over_temp_trig                      : 1,        /* Over temp triggered */
    Fan_array_full                      : 1,        /* Fan array of measured spped is loaded */
    Fan_sample_fast                     : 1;        /* Fan samples fast at 500msec, if off 10 sec */
} System;                               


/* ISR Prototypes */
CY_ISR_PROTO(isr_Timer);
CY_ISR_PROTO(isr_CounterResult);


/* Function Prototypes */
void Initialize(void);
void ReportData(void);                  /* Temperature to deg C and fan speed send thru UART */


//==============================================================================
// Timer Interrupt
//==============================================================================
CY_ISR(isr_Timer)                       /* ISR Timer to report temperature at regular intervals */
{
    flag_Timer = true;
    isr_Timer_ClearPending();
    PWM_1_ClearInterrupt(PWM_1_INTR_MASK_CC_MATCH);
}


//==============================================================================
// Timer Interrupt
//==============================================================================
CY_ISR (isr_CounterResult) 
{
    tacho_data_ready = true;
    Timer_3_ClearInterrupt(Timer_3_INTR_MASK_CC_MATCH);
    isr_Counter_ClearPending();
}


//==============================================================================
// Init PSoC 
//==============================================================================
void Initialize(void)
{
    UART_Start();                       /* UART start */
    OneWire_Start();                    /* OneWire start */
    #ifdef debug
        UART_UartPutString("\033[2J\033[HTemperature sensor Maxim DS18B20:\r\n"); /* Clear screen and cursor home */
        if (OneWire_CheckPresence() == 0x1) {
            UART_UartPutString("Sensor detected\r\n");
        }
    #endif
    isr_Timer_StartEx(isr_Timer);       /* Attach handler */  
    PWM_1_Start();                      /* One second window timer for tacho measurement */
    Timer_3_Start();                    /* Pulse counter for tacho, 2PPR */
    isr_Counter_StartEx(isr_CounterResult);
    System.Fan_sample_fast = true;      /* Set fan samples to fast */
    if (System.Fan_run == false) {
        PWR_Fan_Write(true);
        Timer_2_WriteCompare(0x2000);   /* Max PWM */
        Timer_2_Start();                /* Fan PWM control */
        CyDelay(5000);                  /* Run fan on start */
        PWR_Fan_Write(false);
        Timer_2_Stop();
    }
}


//==============================================================================
// Convert temperature code to degC and 
// Send result to Terminal using UART
//==============================================================================
void ReportData(void) 
{
    char buf[8] = {0};
                     
    sprintf(buf, "\033[3;0H%d.%02d\t", Last_Temp_Read/100, Last_Temp_Read%100); /* Reset cursor to start of third line */
    UART_UartPutString(buf);
    sprintf(buf, "%04d ", Tacho_Counts);
    UART_UartPutString(buf);            /* Output UART buffer */
}


//==============================================================================
// Main
//==============================================================================
int main()
{
    const uint16 Fan_Time_Hyst          = 300u;     /* Time in seconds temp must be outside of thresholds */
    const uint16 Fan_Time_Max           = 600u;     /* Time in seconds for max continuous fan run time */  
    uint32 Tmr2_Comp_Value              = 200u;
    uint16 Fan_Hyst_Counter             = 0;
    uint16 Fan_Run_Counter              = 0;
    uint16 Fan_Speed[10];                           /* Record mutliple fan readings to average */
    uint32 Fan_Speed_Temp               = 0;        /* Working fan speed temp register */
    uint8 Fan_Speed_Index               = 0;        /* Index for the array */
    uint8 Index_Temp                    = 0;
 CyGlobalIntEnable;                  /* Enable global interrupts */
    Initialize();
    
    for(;;) 
    {     
        if(flag_Timer)                  /* read DS18B20 on timer, interval of 1sec */
     {   
            flag_Timer = false;
            OneWire_SendTemperatureRequest();
            /* Normal state, no alarm, rising temperature */
            if  ((System.Over_temp_trig == false) && (Last_Temp_Read > Temp_High_Thres)) {
                Fan_Hyst_Counter++;
            }
            /* Alarm state, falling temperature */
            if ((System.Over_temp_trig == true) && (Last_Temp_Read < Temp_Low_Thres)) {
                Fan_Hyst_Counter--;
            }
            /* Alarm state, rising temperature */
            if ((System.Over_temp_trig == true) && (Last_Temp_Read > Temp_High_Thres)) {
                Fan_Run_Counter++;
            }
        }
        
        if (OneWire_DataReady) {        /* DS18xx completed temperature measurement - begin read data */
            OneWire_ReadTemperature();
            Last_Temp_Read = OneWire_GetTemperatureAsInt100(0);
        }
                  
        /* Handle temperature */
        /* Exceeded the overtemp for more than specified duration */
        if (Fan_Hyst_Counter >= Fan_Time_Hyst) {           
            System.Over_temp_trig = true;
            PWR_Fan_Write(true);                
        }
        
         /* Exceeded the over time for more than specified duration */
        if ((Fan_Run_Counter >= Fan_Time_Max) && (System.Over_temp_trig = true)) {             
            System.Over_temp_trig = false;
            Fan_Run_Counter = 0;
            Fan_Hyst_Counter = 0;
            PWR_Fan_Write(false);
            Timer_2_WriteCompare(0u);
            Timer_2_Stop();
        }
        
        /* Exceeded the undertemp for more than specified duration */
        if (Fan_Hyst_Counter == 0u) {                           
            System.Over_temp_trig = false;
            PWR_Fan_Write(false);
            Fan_Run_Counter = 0;
            Timer_2_WriteCompare(0u);
            Timer_2_Stop();
        }
        
        /* Handle fan PWM */
        /* Fan speed is adjustable from 50% to 100% using PWM over a range of 1 to 10deg C */
        if (System.Over_temp_trig == true) {
            if (Last_Temp_Read > Temp_Low_Thres) {
                Tmr2_Comp_Value = (Last_Temp_Read - Temp_Low_Thres) * 2;  /* Scale result for PWM */
                if (Tmr2_Comp_Value > 2000u) {
                    Tmr2_Comp_Value = 2000u;    /* Timer 2 total period can't be exceeded */
                }
                Timer_2_Start();
                Timer_2_WriteCompare(Tmr2_Comp_Value);
            }
        }
        /* Handle tacho feedback (reporting only) for sample period - indicative measurement */
        if ((tacho_data_ready == true) && (System.Fan_sample_fast == true)) {
            Tacho_Counts = (Timer_3_ReadCaptureBuf())*30u;                /* Read counts over 1sec, Hz to RPM, 2 pulses per rotation */
            tacho_data_ready = false;
            #ifdef debug
                ReportData();
            #endif
        }
        
        /* Handle tacho feedback (reporting only) for slow sampling (Untested code) */
        if ((tacho_data_ready == true) && (System.Fan_sample_fast == false)) {
            Fan_Speed[Fan_Speed_Index] = Timer_3_ReadCaptureBuf();
            Fan_Speed_Index++;
            if ((Fan_Speed_Index < 10u) && (System.Fan_array_full == false)) {
                Fan_Speed_Index = 0;
                System.Fan_array_full = true;
                for (Index_Temp = 0; Index_Temp < Fan_Speed_Index; Index_Temp++) {
                    Fan_Speed_Temp += Fan_Speed[Index_Temp];  
                }
                Fan_Speed_Temp = Fan_Speed_Temp / Fan_Speed_Index;
            }
            if ((Fan_Speed_Index < 10u) && (System.Fan_array_full == true)) {
                Fan_Speed_Index = 0;
                for (Index_Temp = 0; Index_Temp < 11; Index_Temp++) {
                Fan_Speed_Temp += Fan_Speed[Index_Temp];  
                }
                Fan_Speed_Temp = Fan_Speed_Temp / 10;
            }
            Tacho_Counts = Fan_Speed_Temp * 30u;
            tacho_data_ready = false;
            #ifdef debug
                ReportData();
            #endif
        }
    }  
}



/* END */

Fan Installation
In order to collect some operational data, the fan and the associated controller was earmarked for installation in a hot environment such as a vehicle garage.


Haron 320mm sq vent
Haron 320mm sq vent
A 320mm square vent from a local supplier was selected for use with the fan, no round vents with the required diameter were available at the time so the project ended up becoming a proverbial round fan in a square hole. The manufacturer (importer) of the fan was Haron International.


Instead of using plasterboard, 12mm plywood was utilised. This wood was cut to size including the vent cut out, sealed using sealer binder then coated with ceiling white. The vent and temperature sensor were mounted in the plywood.



Haron vent mounting in plywood
Haron vent mounting in plywood
The plastic spacer, provided for mounting on the read of the vent, was modified by removing the mounting posts. This allowed the spacer to mount flat on the rear of the vent. A suitable hole for the Comair Rotron fan was fashioned with a die grinder.

Mounted Comair Rotron DC fan
Mounted Comair Rotron DC fan
To secure the fan all eight mounting holes were used to attach to the plastic spacer plate. All bolts were given a treatment of Loctite 222 threadlocker.

Comair Rotron DC fan mounting bolts
Comair Rotron DC fan mounting bolts
To mount the plastic spacer plate with fan onto the vent a generous application of clear silicone and four bolts were used.

Plastic plate mounting to vent
Plastic plate mounting to vent
In the image above the retaining clips for the vent can be seen with the fan and plastic plated mounted above.


Mounted controller
Mounted controller
With the controller mounted and wired to power and the temperature sensor, data was collected on a warm day. The fan was disabled while data was collected.


Logged Data
The graph below shows approximately a twenty four hour period of temperature sensor data collection. Shown in blue, is the measurement from the OneWire temperature sensor and the orange line shows the reported local district temperature to a one hour resolution.

Even with the OneWire sensor mounted in a garage, the rise and fall of temperatures resembles the locally reported temperatures.


Temperature measurements, reported against measured
Temperature measurements, reported against measured
Code Changes
For the purposes of testing, code changes were made to increase the set temperatures to 32 degrees for the trigger and 30 degrees for the reset temperatures. This was required due to the higher temperature of the test area.

Hardware Changes
In an effort to reduce the current consumed by the controller, the tacho input was identified as a source of leakage, around 10mA. This was not an issue when optocouplers were used in the original design. The cause was not investigated in detail although appeared to be caused because of the controller input consisting of a 22k pullup to 5V, in combination with the output drive of the Comair fan.

To reduce the current a 470k pullup with a 47k series resistor was used. This changed resulted in a lower current although the PWM switching signal was coupled onto the tacho input, meaning false counts were registered. 

The image below shows the PWM signal in yellow and the tacho input in green. Transitions in the PWM signal can be seen in the tacho input. Both channels shown were set to a vertical scale of 2V.

PWM output and Tacho input false counts
PWM output and Tacho input false counts

To resolve the issue in the short term, a 22nF ceramic capacitor was added from the PSoC tacho input to 0V. This resulted in rounding of the signal but no further counting issues.



PWM output and Tacho input no false counts
PWM output and Tacho input no false counts
Schematically the change is shown in the capture below.


Revised Tacho input for coupled noise
Revised Tacho input for coupled noise

Temperature and Fan Data
Temperature and fan speed data were then collected over a 12 hour period. A visual representation of the data collected is shown below.


Measured temperature vs fan speed
Measured temperature vs fan speed
The plotted data shows the 10 minute blocks where the fan was operational with 5 minute off periods in between. Fan speed can be seen increasing and decreasing with the measured temperature fluctuations. For the final implementation of the controller, in a small temperature test chamber, the off periods could be removed.

With the fan control and PWM cycle operating on the prototype, the I2C communications was checked.

Know Bugs
While connecting to the Raspberry PI, the I2C communications did not function properly. The issue appeared to be the Enable (EN) line on the I2C controller (PSA9615) as shown in the image below circled in blue below. This input should not be pulled to the 5V0 supply but driven, in this case from the PSoC device.


I2C Bus Driver Connection (error)
I2C Bus Driver Connection (error)
Changes will be made to the PCB artwork and published as a revision two prototype.

Prototype Release
For those wanting to use this project, for similar purposes, the updated revision two schematic and PCB, with the untested I2C fix, are available below.

Bug reports or schematic changes are invited, enjoy!


DC Fan Controller Schematics
DC Fan Controller Schematics
DC Fan Controller BOM
DC Fan Controller BOM

DC Fan Controller Gerbers
DC Fan Controller Gerbers

PSoC Creator 4.1 DC Fan Controller
PSoC Creator 4.1 DC Fan Controller