Skip to content

Commit

Permalink
Merge pull request #31 from UnifiedEngineering/system-fan-control
Browse files Browse the repository at this point in the history
Optional temperature-controlled system fan speed (transistor must be added, see systemfan.c)
  • Loading branch information
xnk committed Dec 23, 2014
2 parents d063bc6 + 4b29843 commit a341901
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void IO_Init(void) {
FIO0MASK = 0b01001101000000100000010001100000; // Mask out all unknown/unused pins
FIO1MASK = 0b11111111000000001111111111111111; // Only LCD D0-D7

FIO0DIR = 0b10000000011011000011101100000001; // Default output pins
FIO0DIR = 0b10000010011011000011101100000001; // Default output pins
FIO1DIR = 0b00000000000000000000000000000000;

FIO0PIN = 0x00; // Turn LED on and make PWM outputs active when in GPIO mode (to help 100% duty cycle issue)
Expand Down
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "nvstorage.h"
#include "version.h"
#include "max31855.h"
#include "systemfan.h"

extern uint8_t logobmp[];
extern uint8_t stopbmp[];
Expand Down Expand Up @@ -195,6 +196,7 @@ int main(void) {
OneWire_Init();
SPI_TC_Init();
Reflow_Init();
SystemFan_Init();

Sched_SetWorkfunc( MAIN_WORK, Main_Work );
Sched_SetState( MAIN_WORK, 1, TICKS_SECS( 2 ) ); // Enable in 2 seconds
Expand Down
2 changes: 2 additions & 0 deletions src/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ typedef enum eTask {
SLEEP_WORK=0,
BUZZER_WORK,
KEYPAD_WORK,
SYSFANPWM_WORK,
MAIN_WORK,
ADC_WORK,
ONEWIRE_WORK,
SPI_TC_WORK,
UI_WORK,
REFLOW_WORK,
SYSFANSENSE_WORK,
NV_WORK,
SCHED_NUM_ITEMS // Last value
} Task_t;
Expand Down
99 changes: 99 additions & 0 deletions src/systemfan.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* systemfan.c - Temperature controlled system fan handling for T-962 reflow controller
*
* Copyright (C) 2014 Werner Johansson, [email protected]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* This utilizes the (previously unused) ADO testpoint that is connected to
* GPIO0.25 to drive a N-ch/NPN transistor to control the (noisy) system fan.
*
* System fan connector pin 1 = GND, pin 2 = ~10VDC
*
* Disconnect fan from GND, connect this wire to transistor drain/collector. Also
* connect the anode of a catch diode here, cathode to pin 2 (~10VDC).
* Transistor source/emitter connects to ground, gate connects directly to ADO testpoint.
* If using a bipolar transistor connect base through a 4k7 resistor to ADO testpoint.
*
* Example transistors that works: 2N7000 (N-ch FET) or BC547B (bipolar NPN)
*/

#include "LPC214x.h"
#include <stdint.h>
#include <stdio.h>
#include "systemfan.h"
#include "sched.h"
#include "reflow.h"

#define SYSFAN_PWM_PERIOD (TICKS_MS( 10 ))

uint32_t syspwmval = 0;

static int32_t SystemFanPWM_Work( void ) {
static uint8_t state = 0;
int32_t retval;

if( state ) {
FIO0CLR = (syspwmval != SYSFAN_PWM_PERIOD) ? (1<<25) : 0; // SysFan off
retval = syspwmval ? (SYSFAN_PWM_PERIOD - syspwmval) : -1;
} else {
FIO0SET = syspwmval ? (1<<25) : 0; // SysFan on
retval = (syspwmval != SYSFAN_PWM_PERIOD) ? syspwmval : -1;
}
state ^= 1;
return retval;
}

static int32_t SystemFanSense_Work( void ) {
//static uint8_t lastsysfanspeed = 0;
uint8_t sysfanspeed = 0;

if( Reflow_IsTempSensorValid( TC_COLD_JUNCTION ) ) {
float systemp = Reflow_GetTempSensor( TC_COLD_JUNCTION );

// Sort this out with something better at some point
if( systemp > 50.0f ) {
sysfanspeed = 0xff;
} else if( systemp > 45.0f ) {
sysfanspeed = 0xc0;
} else if( systemp > 42.0f ) {
sysfanspeed = 0x80;
} else if( systemp > 40.0f ) {
sysfanspeed = 0x50;
}
} else {
sysfanspeed = 0xff; // No sensor, run at full speed as a precaution
}

uint32_t temp = SYSFAN_PWM_PERIOD >> 8;
temp *= sysfanspeed;
if( sysfanspeed == 0xff ) temp = SYSFAN_PWM_PERIOD; // Make sure we reach 100% duty cycle
syspwmval = temp;

Sched_SetState( SYSFANPWM_WORK, 2, 0 );
//lastsysfanspeed = sysfanspeed;
return TICKS_SECS( 5 );
}

void SystemFan_Init( void ) {
printf("\n%s",__FUNCTION__);
Sched_SetWorkfunc( SYSFANPWM_WORK, SystemFanPWM_Work );
Sched_SetWorkfunc( SYSFANSENSE_WORK, SystemFanSense_Work );

syspwmval = SYSFAN_PWM_PERIOD; // Turn on fan briefly at boot to indicate that it actually works
Sched_SetState( SYSFANPWM_WORK, 2, 0 ); // Enable PWM task
Sched_SetState( SYSFANSENSE_WORK, 1, TICKS_SECS( 2 ) ); // Enable Sense task
}
6 changes: 6 additions & 0 deletions src/systemfan.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef SYSTEMFAN_H_
#define SYSTEMFAN_H_

void SystemFan_Init( void );

#endif /* SYSTEMFAN_H_ */
2 changes: 1 addition & 1 deletion src/t962.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* 0.22 LCD RS output (0=cmd, 1=data)
* 0.23 F1 button (active low, with pullup) VBUS input as alt function on LPC214x
* 0.24 (No pin)
* 0.25 AD0.4 accessible on test point marked ADO - DAC output as alt function
* 0.25 AD0.4 accessible on test point marked ADO - DAC output as alt function (now used for sysfan control)
* 0.26 ? USB D+ on LPC214x-series of chips
* 0.27 ? USB D- on LPC214x-series of chips
* 0.28 Temperature sensor input 1 (AD0.1), this was the left-hand one in our oven
Expand Down

0 comments on commit a341901

Please sign in to comment.