Temperature Fan Control

Mad Professor

Senior Member
Good Day All.

I own four Sun Cobalt RaQ 550 1U Web Servers.
Each of the web servers are fitted with three cooling fans

Make: Delta
Model: FFB0412VHN.
Rated Voltage: 12Volts.
Operating Voltage Range: 4.5 to 13.2Volts.
Rated Current: 0.16Amps.
Rated Power: 1.92Watts.
Speed: 9500Rpm.
Max Air Flow: 0.447m3/min (15.79 CFm).
Noise: 41.9dB-A.

With all four units powered up, 12 fans in total it is almost impossible to hear your self think.

So I would like to be able to regulate the fan speeds based on temperature.

The 1st idea was to just use temperature sensors and control the fan speed via pwm, and that’s where I hit my 1st problem, all of the fans are the 3 wire type so the servers are monitoring if the fans are working, and by using pwm the server gets really confused about the speed of the fans and ends up shutting them down.

I could possibly fit caps across the input to the fan to try and smooth the pwm to run more like dc, but I don’t think this will work very well.

My next idea was to use stepped fixed voltages so I can have low, mid, high fan speeds, yes I could do this but I would much more like to have a linear fan speed control.

So to my question what is the best way about making linear 4.5volt to 12volt DC output that is based on temperature.

Thanks for your time.

Best Regards.
 

BeanieBots

Moderator
To answer you question, feed your PWM into an RC and buffer with an op-amp. Feed the op-amp output into an emmitter follower.

However, I think that method is very inefficient and will generate a fair amount of heat in the output transistor.

How about, measuring the fan signal which is fed back to the server and then try to replicate it with a second PWM signal to fool the server into thinking the fans are on full speed. You could then use PWM to control the fan speed and the server would never know;)
 

hippy

Ex-Staff (retired)
I've got a couple of 1U racks and was surprised how loud they were. Luckily two-wire fans so just connected between +5V and +12V so they run at 7V and are much, much quieter. I don't use them for very long at a time so over-heating isn't a likely occurance.

You could use a PICAXE to generate the RPM signals for the M/B so it thinks all is okay no matter what the fans are doing, then use another PICAXE PWM to control them -- Added: Devious minds think alike :)

A PICAXE with HPWM can control four fans individually although all on will be at same speed and with a second PWMOUT that could control the M/B. The PICAXE-28X1 should fit the bill.
 

inglewoodpete

Senior Member
The third wire on from the fan is so that the computer/server can monitor the fan speed. From memory, the fan outputs one pulse per revolution. Some computers actually control their fan's speed according to their temperature, so your project is do-able.

I have used PWM into the gate of a 2N7000 MOSFET via a 220ohm resistor. The MOSFET was used as a low-side switch to control the speed of a (single) computer fan. I put a 0.1uF capacitor across the fan motor to calm the electrical noise without taking away the benefits of using PWM for speed control. It worked for me: refer to discussion http://www.picaxeforum.co.uk/showthread.php?t=9891
 

tater1337

Member
replace the fans.

some fans are more noisy than others. lowest bidder is usually the loudest.

once replaced a fan and had to take the machine apart because I swore it wasnt runnin. was that quiet.
 

papaof2

Senior Member
replace the fans.

some fans are more noisy than others. lowest bidder is usually the loudest.

once replaced a fan and had to take the machine apart because I swore it wasnt runnin. was that quiet.
I had to do research to find a fan that quiet to replace the fan in my son-in-law's high end DVD player. This is where datasheets are useful. Good fans will have their air flow (CFM) and noise rating (dba) on the datasheet. Sometimes the surplus houses nclude the noise specs: http://www.allelectronics.com/make-a-store/item/CF-356/12VDC-40MM-COOLING-FAN/1.html

John
 

gengis

New Member
I made a picaxe controller for my computer fan. I've got this 120 mm fan that will suck in every bit of dust in the room if it has half a chance. One solution was to control the speed (and the other to replace one side panel with a large heating/ventilation filter).


I never could get completely satisfactory results trying to us PWM directly on the fans I had. The frequency range where it would work was very narrow - too high and the fan would ignore the voltage. At around 5,000 hertz I could get control but it was in and out of control and annoyingly noisy. Lower than that, and it would ignore it again. (yet there are people that claim to do it so there must be some fans that are more tolerant than others)

I settled on pulsing the fan - sounds like its wheezing at 70 degrees where it comes on for 300 ms pulses - at 75 it is on more on than off and the sound is almost gone. It works very well - even added a little alarm buzzer to tell me if its too hot or the thermistor is open or shorted.

BUT a picaxe has all the same ability that a switching regulator has. There's no reason one can't replace a regulator (linear or switching) and give pulse free voltage to a load.

The linear application would be easiest in some respects. Its easy enough to integrate the PWM to an analog voltage with just a resistor and cap. That could control a pass transistor, but would require another A/D channel to look at the voltage and compare it to temperature to close the loop. My fan is 12 volts 600 milliamps and start turning at 5 volts. Worst case power loss for a linear controller is only 3.5 watts.

So that's plan A when the weather cools and I can stop using it and start modifying what I have now.

A switching regulator might waste less power (if a couple of watts is that significant or you have a giant fan) On the upside, there'd be no need to watch the voltage with a A/D channel and it would waste less power. On the downside it would take more tinkering.
 

hippy

Ex-Staff (retired)
Some PC-style fans contain their own PWM controllers within them and the controller doesn't like PWM being applied. You need to vary the voltage to control them, or run intermittantly on and off much more slowly.
 

Mad Professor

Senior Member
Thanks for eveyones replys so far.

I have to be very carfull about air flow and cooling, as the 1U servers do not have fans for the CPU, it's only the intake and ext fans that give the air flow for the CPU, and Hard Drives.

That is why I have not just stuck lower rpm or flow rate fans in.

I am not sure about using the picaxe to fake a fan speed to the server, as I would like the server to monitor the fan speed still.

As I would still like the server to react if any of the fans fails.

After a quick bit of testing, i.e finger on the fan to slow it down, I slowed the fan down to around 1000rpm before the server started kicking up a fuss about the fan.
 
Last edited:

hippy

Ex-Staff (retired)
Take the fan RPM signals to the / another PICAXE and either generate a valid RPM signal for the M/B or not; that way the M/B will still be monitoring if fans are working but it will be a yes/no indicator it gets rather than actual RPM.

You could even use the RPM to M/B to indicate how fast the fans are - 0 RPM failed, 1000 RPM slow to 9000 RPM fastest. That way you can get an idea of what the PICAXE is doing just by accessing the PC's BIOS / diagnostics.
 

Dippy

Moderator
If it is that crucial/sensitive should you really be messing about with it?

Can you get better quality fans? You tend to get what you pay for.
Can you use larger/slower fans with a manifold?
Can you put a sound-absorbing cover over the fans / box (obv with common-sense approach of not restricting air-flow but effectively putting a sound absorber in front of fans with a suitable gap , and obv if space permits)

... or are you bursting to do a project ;)
 

gengis

New Member
Some PC-style fans contain their own PWM controllers within them and the controller doesn't like PWM being applied. You need to vary the voltage to control them, or run intermittantly on and off much more slowly.
I did some research and posted to the alt.electronics.design newsgroup - the general consensus was that pwm should not be used with brushless DC fans due to the nature of their construction. A spinning magnet (fan assembly) alternately triggers hall sensors pulling the magnet to the next coil along the circumferance. Not a lot of electronics and not sophisticated.

I did find some manufacturers do allow external speed control via a voltage level or PWM to the third wire and sometimes the extra wire is a pulse to tell RPM and fan working or a thermistor signal. All that stuff was buried in the model number and data sheet for that model fan. The two fans I had to play with were strictly RPM pulse output on the extra wire, so I assume that is most common.

From the number of times the subject comes up (in one form or another) there seems to be a need for a good, efficient, way of controlling an analog (low impedance power supply) voltage with an axe.
 

BeanieBots

Moderator
From the number of times the subject comes up (in one form or another) there seems to be a need for a good, efficient, way of controlling an analog (low impedance power supply) voltage with an axe.
The circuit I described in post #2 is probably as good as you'll get for a 'general pupose' method. Though not very efficient.

The problem with anything more efficient such as a 'switcher' is that any (simple) design would need to be fairly specific to the fan in question. A more 'general' PICAXE -> voltage efficient design is simple enough in theory but requires care and slightly more 'obscure' components than found in the average hobby box of parts.
 

Mad Professor

Senior Member
I have been working on this on and off since my last post, but I have not had alot of free time.

Just a quick recap, the aim of the project is to fit some kind of temp vs. fan speed control to my 1U RaQ 550 servers.

I have four of these servers, and each server has three 40mm Delta FFB0412VHN 9500rpm fans, so with a total of 12 fans running flat out, it is very noisy.

So I want to be able to monitor the temp of the CPU and the Pri Hard Drive, and adjust the fan speed.

The servers monitor the tach signal from the fans at all times, the tach monitoring can not be switched off this seems to be hardware based.

I have run the fans as low as 5volts, so low fan speed and stable tach out, and the server has no problem with this.

But as soon as I tried driving the fan with a Low-Side PWM even at 95% DC the server would say there is a fan fault and power down.

The last problem I need to overcome is as the server is U1 there is very little room side, so my control PCB needs to really only be 50x40mm or pushing it can be as big as 70x40mm.

So it looks like I need to do High-Side PWM, but holding the fan at 5volts when off, so instead of PWM 0-12volts I need to PWM 5-12volts.

Heres what I have come up with so far.



Code:
#Picaxe 08M

main:
pause 1000
ReadAdc10 1, w0
ReadAdc10 4, w1
w2 = w0 Min w1
debug
if w2 >= 753 then temp_50		'ADC 753, 50.0c, 100% Fan Speed.
'if w2 >= ??? then temp_47.5		'ADC ???, 47.5c, 95% Fan Speed.
if w2 >= 712 then temp_45		'ADC 712, 45.0c, 90% Fan Speed.
'if w2 >= ??? then temp_42.5		'ADC ???, 42.5c, 85% Fan Speed.
if w2 >= 667 then temp_40		'ADC 667, 40.0c, 80% Fan Speed.
'if w2 >= ??? then temp_37.5		'ADC ???, 37.5c, 75% Fan Speed.
if w2 >= 619 then temp_35		'ADC 619, 35.0c, 70% Fan Speed.
'if w2 >= ??? then temp_32.5		'ADC ???, 32.5c, 65% Fan Speed.
if w2 >= 567 then temp_30		'ADC 567, 30.0c, 60% Fan Speed.
'if w2 >= ??? then temp_27.5		'ADC ???, 27.5c, 55% Fan Speed.
if w2 >= 512 then temp_25		'ADC 512, 25.0c, 50% Fan Speed.
'if w2 >= ??? then temp_22.5		'ADC ???, 22.5c, 45% Fan Speed.
if w2 >= 455 then temp_20		'ADC 455, 20.0c, 40% Fan Speed.
'if w2 >= ??? then temp_17.5		'ADC ???, 17.5c, 35% Fan Speed.
if w2 >= 398 then temp_15		'ADC 398, 15.0c, 30% Fan Speed.
'if w2 >= ??? then temp_12.5		'ADC ???, 12.5c, 25% Fan Speed.
if w2 >= 342 then temp_10		'ADC 342, 10.0c, 20% Fan Speed.
'if w2 >= ??? then temp_7.5		'ADC ???, 7.5c, 15% Fan Speed.
if w2 >= 289 then temp_5		'ADC 289, 5.0c, 10% Fan Speed.
'if w2 >= ??? then temp_2.5		'ADC ???, 2.5c, 5% Fan Speed.
if w2 >= 240 then temp_0		'ADC 240, 0.0c, 0% Fan Speed.
goto main


temp_0:
pwmout 2 , 49, 0				' PWM 20,000Hz @ 0% Duty Cycle.
goto main

temp_2.5:
pwmout 2 , 49, 10				' PWM 20,000Hz @ 5% Duty Cycle.
goto main

temp_5:
pwmout 2 , 49, 20				' PWM 20,000Hz @ 10% Duty Cycle.
goto main

temp_7.5:
pwmout 2 , 49, 30				' PWM 20,000Hz @ 15% Duty Cycle.
goto main

temp_10:
pwmout 2 , 49, 40				' PWM 20,000Hz @ 20% Duty Cycle.
goto main

temp_12.5:
pwmout 2 , 49, 50				' PWM 20,000Hz @ 25% Duty Cycle.
goto main

temp_15:
pwmout 2 , 49, 60				' PWM 20,000Hz @ 30% Duty Cycle.
goto main

temp_17.5:
pwmout 2 , 49, 70				' PWM 20,000Hz @ 35% Duty Cycle.
goto main

temp_20:
pwmout 2 , 49, 80				' PWM 20,000Hz @ 40% Duty Cycle.
goto main

temp_22.5:
pwmout 2 , 49, 90				' PWM 20,000Hz @ 45% Duty Cycle.
goto main

temp_25:
pwmout 2 , 49, 100			' PWM 20,000Hz @ 50% Duty Cycle.
goto main

temp_27.5:
pwmout 2 , 49, 110			' PWM 20,000Hz @ 55% Duty Cycle.
goto main

temp_30:
pwmout 2 , 49, 120			' PWM 20,000Hz @ 60% Duty Cycle.
goto main

temp_32.5:
pwmout 2 , 49, 130			' PWM 20,000Hz @ 65% Duty Cycle.
goto main

temp_35:
pwmout 2 , 49, 140			' PWM 20,000Hz @ 70% Duty Cycle.
goto main

temp_37.5:
pwmout 2 , 49, 150			' PWM 20,000Hz @ 75% Duty Cycle.
goto main

temp_40:
pwmout 2 , 49, 160			' PWM 20,000Hz @ 80% Duty Cycle.
goto main

temp_42.5:
pwmout 2 , 49, 170			' PWM 20,000Hz @ 85% Duty Cycle.
goto main

temp_45:
pwmout 2 , 49, 180			' PWM 20,000Hz @ 90% Duty Cycle.
goto main

temp_47.5:
pwmout 2 , 49, 190			' PWM 20,000Hz @ 95% Duty Cycle.
goto main

temp_50:
pwmout 2 , 49, 200			' PWM 20,000Hz @ 100% Duty Cycle.
goto main
Please let me know your toughts.

Thanks for your time.
 

boriz

Senior Member
Modern MBs use 4 wire fans. The fourth wire is PWM speed control. Just replace your fans with modern 4 wire types and send PWM down the fourth wire. Dunno the frequency, but it shouldn’t be hard to find out.
 

Mad Professor

Senior Member
boriz: Thanks for your reply.

As you say a 4 wire PWM fan would be best, but I am yet to find a 40x40x28mm 4 wire pwm fans in the UK.
 
Last edited:

Mad Professor

Senior Member
Good day all.

I am still working on this project on and off in my spare time.

I have scraped the high-side switching of the fans, and have gone for low-side switching.

Here is the code I am using at this point in time.
Code:
#Picaxe 18X

main:
pause 1000
ReadAdc10 0, w0
ReadAdc10 1, w1
'ReadAdc10 2, w2
w3 = w0 Min w1
debug
if w3 >= 753 then temp_50		'if ADC =>753, Then temp is =>50.0c, Set fan speed to 100%.
if w3 >= 731 then temp_47.5		'if ADC =>731, Then temp is =>47.5c, Set fan speed to  95%.
if w3 >= 712 then temp_45		'if ADC =>712, Then temp is =>45.0c, Set fan speed to  90%.
if w3 >= 689 then temp_42.5		'if ADC =>689, Then temp is =>42.5c, Set fan speed to  85%.
if w3 >= 667 then temp_40		'if ADC =>667, Then temp is =>40.0c, Set fan speed to  80%.
if w3 >= 642 then temp_37.5		'if ADC =>642, Then temp is =>37.5c, Set fan speed to  75%.
if w3 >= 619 then temp_35		'if ADC =>619, Then temp is =>35.0c, Set fan speed to  70%.
if w3 >= 591 then temp_32.5		'if ADC =>591, Then temp is =>32.5c, Set fan speed to  65%.
if w3 >= 567 then temp_30		'if ADC =>567, Then temp is =>30.0c, Set fan speed to  60%.
if w3 >= 538 then temp_27.5		'if ADC =>538, Then temp is =>27.5c, Set fan speed to  55%.
if w3 >= 512 then temp_25		'if ADC =>512, Then temp is =>25.0c, Set fan speed to  50%.
if w3 >= 481 then temp_22.5		'if ADC =>481, Then temp is =>22.5c, Set fan speed to  45%.
if w3 >= 455 then temp_20		'if ADC =>455, Then temp is =>20.0c, Set fan speed to  40%.
if w3 >= 425 then temp_17.5		'if ADC =>425, Then temp is =>17.5c, Set fan speed to  35%.
if w3 >= 398 then temp_15		'if ADC =>398, Then temp is =>15.0c, Set fan speed to  30%.
if w3 >= 368 then temp_12.5		'if ADC =>368, Then temp is =>12.5c, Set fan speed to  25%.
if w3 >= 342 then temp_10		'if ADC =>342, Then temp is =>10.0c, Set fan speed to  20%.
if w3 >= 313 then temp_7.5		'if ADC =>313, Then temp is => 7.5c, Set fan speed to  15%.
if w3 >= 289 then temp_5		'if ADC =>289, Then temp is => 5.0c, Set fan speed to  10%.
if w3 >= 262 then temp_2.5		'if ADC =>262, Then temp is => 2.5c, Set fan speed to   5%.
if w3 >= 240 then temp_0		'if ADC =>240, Then temp is => 0.0c, Set fan speed to   0%.
goto main


temp_0:
'sertxd ("=> 0.0c,   0% Fan Speed",13,10)
pwmout 3 , 49, 0				' PWM 20,000Hz @ 0% Duty Cycle.
w6 = 0
goto main

temp_2.5:
'sertxd ("=> 2.5c,  5% Fan Speed",13,10)
pwmout 3 , 49, 10				' PWM 20,000Hz @ 5% Duty Cycle.
w6 = 5
goto main

temp_5:
'sertxd ("=> 5.0c,  10% Fan Speed",13,10)
pwmout 3 , 49, 20				' PWM 20,000Hz @ 10% Duty Cycle.
w6 = 10
goto main

temp_7.5:
'sertxd ("=> 7.5c,  15% Fan Speed",13,10)
pwmout 3 , 49, 30				' PWM 20,000Hz @ 15% Duty Cycle.
w6 = 15
goto main

temp_10:
'sertxd ("=>10.0c,  20% Fan Speed",13,10)
pwmout 3 , 49, 40				' PWM 20,000Hz @ 20% Duty Cycle.
w6 = 20
goto main

temp_12.5:
'sertxd ("=>12.5c,  25% Fan Speed",13,10)
pwmout 3 , 49, 50				' PWM 20,000Hz @ 25% Duty Cycle.
w6 = 25
goto main

temp_15:
'sertxd ("=>15.0c,  30% Fan Speed",13,10)
pwmout 3 , 49, 60				' PWM 20,000Hz @ 30% Duty Cycle.
w6 = 30
goto main

temp_17.5:
'sertxd ("=>17.5c,  35% Fan Speed",13,10)
pwmout 3 , 49, 70				' PWM 20,000Hz @ 35% Duty Cycle.
w6 = 35
goto main

temp_20:
'sertxd ("=>20.0c,  40% Fan Speed",13,10)
pwmout 3 , 49, 80				' PWM 20,000Hz @ 40% Duty Cycle.
w6 = 40
goto main

temp_22.5:
'sertxd ("=>22.5c,  45% Fan Speed",13,10)
pwmout 3 , 49, 90				' PWM 20,000Hz @ 45% Duty Cycle.
w6 = 45
goto main

temp_25:
'sertxd ("=>25.0c,  50% Fan Speed",13,10)
pwmout 3 , 49, 100			' PWM 20,000Hz @ 50% Duty Cycle.
w6 = 50
goto main

temp_27.5:
'sertxd ("=>27.5c,  55% Fan Speed",13,10)
pwmout 3 , 49, 110			' PWM 20,000Hz @ 55% Duty Cycle.
w6 = 55
goto main

temp_30:
'sertxd ("=>30.0c,  60% Fan Speed",13,10)
pwmout 3 , 49, 120			' PWM 20,000Hz @ 60% Duty Cycle.
w6 = 60
goto main

temp_32.5:
'sertxd ("=>32.5c,  65% Fan Speed",13,10)
pwmout 3 , 49, 130			' PWM 20,000Hz @ 65% Duty Cycle.
w6 = 65
goto main

temp_35:
'sertxd ("=>35.0c,  70% Fan Speed",13,10)
pwmout 3 , 49, 140			' PWM 20,000Hz @ 70% Duty Cycle.
w6 = 70
goto main

temp_37.5:
'sertxd ("=>37.5c,  75% Fan Speed",13,10)
pwmout 3 , 49, 150			' PWM 20,000Hz @ 75% Duty Cycle.
w6 = 75
goto main

temp_40:
'sertxd ("=>40.0c,  80% Fan Speed",13,10)
pwmout 3 , 49, 160			' PWM 20,000Hz @ 80% Duty Cycle.
w6 = 80
goto main

temp_42.5:
'sertxd ("=>42.5c,  85% Fan Speed",13,10)
pwmout 3 , 49, 170			' PWM 20,000Hz @ 85% Duty Cycle.
w6 = 85
goto main

temp_45:
'sertxd ("=>45.0c,  90% Fan Speed",13,10)
pwmout 3 , 49, 180			' PWM 20,000Hz @ 90% Duty Cycle.
w6 = 90
goto main

temp_47.5:
'sertxd ("=>47.5c,  95% Fan Speed",13,10)
pwmout 3 , 49, 190			' PWM 20,000Hz @ 95% Duty Cycle.
w6 = 95
goto main

temp_50:
'sertxd ("=>50.0c, 100% Fan Speed",13,10)
pwmout 3 , 49, 200			' PWM 20,000Hz @ 100% Duty Cycle.
w6 = 100
goto main
The above code does work well, but as I am using steps of 5% Duty Cycle, when the temp(s) are just on the edge of change you get the fan jumping up and down in speed.

So I have been thinking about redoing the above code so that I can dynamically use the hole duty cycle range, and not have 5% jumps, by using steps.

But I don't know where to start, so can someone please tell me the best route?

Thanks for your time.

Best Regards.
 

Andrew Cowan

Senior Member
Easy - use maths.

When Temp=753, PWM needs to be 200
When Temp=240, PWM needs to be 0.

So;

PWM=(Temp-240)/2.57 Min 0 Max 200

should do it.

To convert that to PICAXE code (where PWM_duty and Temp are word variables):

let PWM_duty = Temp - 240 min 0
let PWM_duty = PWM_duty *100 / 257 max 200


pwmout 3,49,PWM_duty

A
 
Last edited:

hippy

Ex-Staff (retired)
let PWM_duty = Temp - 240 min 0
let PWM_duty = PWM_duty *100 / 257 max 200


That's the way I'd do it, though you need to jiggle the first line as the PICAXE doesn't handle the underflow to negative; it's just a big positive number so "MIN 0" is always true. This is what you want ( assuming your maths okay, I didn't check ) ...

let PWM_duty = Temp min 240 - 240
let PWM_duty = PWM_duty *100 / 257 max 200
 

Mad Professor

Senior Member
Andrew Cowan: Thank you for your reply.

So the code should look more like this then.
Code:
#Picaxe 18X

symbol ADC_Reading0 = w0
symbol ADC_Reading1 = w1
symbol ADC_Reading2 = w2
symbol ADC_ReadingH = w3
symbol PWM_Duty = w4


main:
ReadAdc10 0, ADC_Reading0
ReadAdc10 1, ADC_Reading1
'ReadAdc10 2, ADC_Reading2
ADC_ReadingH = ADC_Reading0 Min ADC_Reading1

let PWM_Duty = ADC_ReadingH - 240 min 0
let PWM_Duty = PWM_Duty *100 / 257 max 200

pwmout 3,49,PWM_Duty

debug

goto main
I have just given the above code a quick test, and it seems to adjust the fan speed ok.

But once the input ADC go's above 753, the dutycycle drops back to 0.

Also tried hippy adjustment but also does the same.

Can you please advice.

Best Regards.
 

Mad Professor

Senior Member
I have just re-adjusted the code so my simple brain can try and debug what is going on.

Code:
#Picaxe 18X

symbol ADC_Reading0 = w0
symbol ADC_Reading1 = w1
symbol ADC_Reading2 = w2
symbol ADC_ReadingH = w3
symbol PWM_Calc = w4
symbol PWM_Duty = w5

main:
ReadAdc10 0, ADC_Reading0
ReadAdc10 1, ADC_Reading1
'ReadAdc10 2, ADC_Reading2
ADC_ReadingH = ADC_Reading0 Min ADC_Reading1

let PWM_Calc = ADC_ReadingH - 240 min 0
let PWM_Duty = PWM_Calc *100 / 257 max 200
pwmout 3,49,PWM_Duty

debug

goto main
I can now see in debug mode when the ADC input go's under or over the min / max that you get big numbers in the PWM_Calc (w4) field.

The problem happens when the ADC input is =<239, and => 896.

ADC Reading of 239 gives PWM_Calc (w4) 65535, and PWM_Duty (w5) 200.
ADC Reading of 896 gives PWM_Calc (w4) 656, and PWM_Duty (w5) 0.

How do I go about telling the picaxe to only use a ADC range of 240 to 753?

Best Regards.
 
Last edited:

hippy

Ex-Staff (retired)
The equations have to be adjusted for the particular range of values you are using. My fix in the previous post will solve the underflow issue, this will fix the overflow -

let PWM_duty = Temp max 753 min 240 - 240
let PWM_duty = PWM_duty *100 / 257 max 200
 

gengis

New Member
I ran into the same thing. The word variables can't exceed ~65,000 so anytime you start multiplying by 100 it is easy to exceed that. Doubtless there are ways to limit it or some way to use more than one variable, but that's outside my ken.


After laboriously rewriting my program to integrate the zero (where the fan begins to turn) and change the span of the fan (speed range possible with the fan) and span of the thermistor, it became apparent that a simple op amp on the themistor could set Zero and Span to something the axe could use without exceeding a 65K variable, I gave up. Easier to add an op amp and massage the zero and span before ever sending it over to the axe.


I did find a way to cheat with a combination of tweaking the variable a tad then (the times two minus 52) increasing my pwm frequency a tad (>double - but still lower than you are going for). It is working to my satisfaction doing that. I'm still tweaking it but here's what I have so far. (with the increase in frequency the fan makes no noise and the speed control is smooth from fan barely turning to max speed)

Code:
symbol analogcontrol = 1
symbol analogvalue = w0
symbol pwmport = 2
symbol buzzer = 4
goto runn

runn:    

    readadc10 analogcontrol ,analogvalue      'read an analog value into W0 from thermistor on pin 6
    'debug analogvalue
    analogvalue = analogvalue *2
    analogvalue = analogvalue -52

    if analogvalue <= 1 then alarm2    'sensor failure alarm (open)
    if analogvalue >= 1000 then alarm2    'sensor failure alarm (shorted)
    if analogvalue <= 120 then stop1    'fan set to off if temp too low

    pwmout pwmport, 100, analogvalue    'on/off pwm ratio based on temperature

    if analogvalue >= 900 then alarm3    'temperature approaching meltdown
    'pause 5000
    goto runn                

stop1:
    pwmout pwmport, 0, 0            'stops fan entirely when temperature is low
    if analogvalue >= 150 then stop2    'gooses fan into overcoming friction
                            'these lines provide hysterisis on restarting -
    if analogvalue >= 130 then runn    'temperature must be higher than where it cuts off
                            'prevents multiple goosing when its on the cusp of 
                            'turning on
    goto runn

stop2:
    high pwmport
    pause 50                    'goose
    goto runn
    

alarm3:
    high buzzer         'turn on buzzer for 1/3 second
    pause 300
    low buzzer            'slow buzzer hi temp alarm
    pause 2000
    goto runn

alarm2:
    pwmout pwmport, 0, 0    'fast buzzer sensor failure alarm
    high pwmport
    high buzzer 
    pause 300
    low buzzer
    pause 400
    low pwmport
    goto runn
 
Last edited:
Top