Proportional fan control. I suck at math!


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52

    Default Proportional fan control. I suck at math!

    I have a solar collector controller and I need to build a proportional fan controller for it and I need some help with the math. I need it to be proportional from 90 to 120 deg F and off below 90 deg.
    I'm using an LM34 temp sensor that outputs 10mv/degree F and I want to use a PIC with a hardware pwm to drive a DC fan. I haven't chosen the pic yet.
    Below 90deg F I need a 0% duty cycle (off), at 90deg F (.900 volts at the pic) a 50% duty cycle and at 120deg F and above (1.20 volts at the pic) I need 100% duty cycle..
    I know you guys are geniuses so I'm hoping someone can come up with a formula for this.
    Thanks.
    Last edited by polymer52; - 2nd January 2010 at 15:04.

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default

    Hi,

    If I understand correctly your question, when you get .90V out of the temperature sensor that corresponds to 90deg F and 1.20V corresponds to 120deg F. A very simple linear equation crossing the origin (0,0) would be

    Temperature = 100 * Voltage

    Use this simple equation for Temperature in the range between 90F and 120F. I hope this helps.

    Robert

  3. #3
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rsocor01 View Post
    Hi,
    If I understand correctly your question, when you get .90V out of the temperature sensor that corresponds to 90deg F and 1.20V corresponds to 120deg F. A very simple linear equation crossing the origin (0,0) would be
    Temperature = 100 * Voltage
    Use this simple equation for Temperature in the range between 90F and 120F. I hope this helps.
    Robert

    I need the fan to come on at 90 deg and output a PWM signal of 50% at that temp. Then increase the duty cycle of that PWM signal as temperature (voltage) increases to a maximum of 100% at 120deg and above.

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by polymer52 View Post
    I need the fan to come on at 90 deg and output a PWM signal of 50% at that temp. Then increase the duty cycle of that PWM signal as temperature (voltage) increases to a maximum of 100% at 120deg and above.
    So basically, assuming the PWM part has 255 steps, when temp = 90 the PW would = 0, and when its 120 the PW = 255 ?

    So that's a 30 degree range represented by a 255 step. 255 / 30 = 8.5

    That would mean that for every degree the PW is 8.5

    You would then need to write your code so that if temp < 90 PW=0 and if temp >120 then PW =255 to give you your range. I would then use a variable to give you the 30 degree steps you need, something like range value = temp - 90, and then use this for the steps, sorta PW= range value X 8.5

    This may not be the ideal way, and I'm sure it could be simplified, but it's the way I would approach the problem. You need to choose a PIC and set the resolution of the PWM you wish to use, the more steps the smoother the fan control will be

    EDIT:

    just re-read your post, you want the fan to run at 50% at 90 degrees, if so then wouldn't that be a simple case of a statement like
    If temp >90 and <120 then PW=127
    If temp > 120 then PW=255

    Hope this helps
    Last edited by malc-c; - 3rd January 2010 at 14:09.

  5. #5
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Hi Polymer
    try this - I used a 12F683
    Take care
    Alec


    '************************************************* ***************
    '* Name : fan controller_forum *
    '* Author : Alec Noble *
    '* Notice : Copyright (c) 2010 Alec Noble *
    '* : All Rights Reserved *
    '* Date :1/3/2010 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    @DEVICE=PIC12F683
    define OSC 8
    OSCCON = %01110001 ' Internal 8MHz osc
    CMCON0 = 7 ' Comparators off
    WPU = 0 ' Internal pull-ups = off
    'GPIO = %00000000 ' All outputs = 0 on boot
    TRISIO = %000000001 ' GPIO.0=data in, GPIO.2=PWMout, GPIO,1,3,4,5 unused

    '******************** set up ADC ************************************
    ANSEL = %00010001 'gpio.0 analog, others digital, ADC clock fosc/8
    DEFINE ADC_BITS 10 ' ADCIN resolution (Bits)
    DEFINE ADC_CLOCK 1 ' ADC clock source (Fosc/8)
    DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec)
    adcon0.7 = 1

    '********************* define variables *******************************
    sensor var word
    temp var word
    span var byte
    duty var word
    '********************** intitialize variables *************************
    duty = 0
    temp = 0
    span = 0

    '********************** Program starts here **************************
    main:
    HPWM 1, duty, 5000 'set PWM output
    adcin 0, sensor 'read temperature sensor
    sensor = sensor * 500
    temp = div32 1023 'convert ADC to degrees
    span = temp - 90 'get range above 90 degrees

    if temp < 90 then 'less than 90 degrees PWM off
    duty = 0
    endif

    if temp > 90 and temp < 120 then
    duty = 130 + (span * 4) 'between 90 and 120 start with 50% and linearly
    endif 'raise rate up to 120 degrees

    if temp > 120 then 'above 120 degrees 100%
    duty = 255
    endif

    pause 100 'pause to avoind to frequent cycling
    goto main 'do it again

  6. #6
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    I think Malcolm had it... it's about 8.5 PWM steps per degree, over a 30 degree span.

    So, something like this?


    Code:
    If temp < 90 then 
    	duty = 0
    else
    	duty = (temp - 90)  * 85 /10   'subtract 90 from temp, and multiply * 8.5
    endif


    steve

  7. #7
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    EDIT:
    just re-read your post, you want the fan to run at 50% at 90 degrees, if so then wouldn't that be a simple case of a statement like
    If temp >90 and <120 then PW=127
    If temp > 120 then PW=255
    Hope this helps
    I think I have settled on the 12F683. It has an 8mhz internal osc, A/D converter and hardware PWM so it doesn't have to be constantly strobed.
    Also the 2k words program memory is a nice touch. I can be as sloppy with my code as I want and still have room to spare.

    Getting closer..Anything below 90deg fan is off so:
    If Temp<90 then HPWM=0
    Then at 90 deg fan comes on at 50%:
    If Temp=90 then HPWM=127 (50% of 255 leaving 127 remainder). 'Minimum fan speed

    Here is the part I don't understand. From 91 to 120 the fan speed needs to vary according to temperature so:
    From 91 to 120 each degree needs to widen the HPWM by 4.23 (remaining 127 / 30 deg) speeding up the fan incrementally by temp.

    Finally
    IF Temp>= 120 then HPWM=255 'Full fan speed at or above 120 deg

    The actual PBP command is: HPWM Channel,Dutycycle,Frequency
    so at 90 deg on channel 1, 50% duty cycle and 1khz rate the command
    would be HPWM 1,127,1000. I can replace the 127 with a variable.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I can replace the 127 with a variable.
    I f you are asking then yes. You can use a variable.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Ahh, that's right, the minimum on speed is 50%... (duty = 128)

    So then you've got to increase duty by about 4.2 for every degree between 90 and 120 ...

    How about something along these lines:

    If temp < 90 then duty = 0

    If temp > 120 then duty = 255

    If temp > 89 AND temp < 120 then duty = 128 + ((temp - 90) * 42 / 10)

    steve

  10. #10
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Perfect!
    I knew you guys were brainie.
    I'll buy you a virtual beer.. Cheers!

  11. #11
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Nice one Steve !

    Good teamwork

  12. #12
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    And thanks to alec also. Somehow I missed his post earlier but he did a lot of the work for me and between Steve and Alec I think we've got it..
    I have a solar hot air furnace which I'm building this control for. It is just a relay controlled fan right now which, early in the morning, kicks on at 110 degrees then cools the collector down too much and shuts off at 90 deg then cycles again. It also outputs data to a serial LCD module such as ambient temp, collector temp, fan relay on/off and vent servo position.
    With the proportional control I can have it to come on at 90 degrees and only move the amount of air that it can heat without shutting off and cycling increasing the heating time.
    As the sun rises and it gets hotter in the collector the fan can move ever increasing amounts of air until it gets to full speed. Full collector temperature ranges from 90 at cut in to around 140-170 deg at noon depending on outside temperature.
    Last edited by polymer52; - 3rd January 2010 at 23:23.

Similar Threads

  1. How do I give a radio control car autonomous control
    By Kenjones1935 in forum General
    Replies: 190
    Last Post: - 17th January 2010, 15:40
  2. Transistor selection, PWM fan control
    By 124C41 in forum Schematics
    Replies: 5
    Last Post: - 22nd December 2008, 15:33
  3. Control RC servo via Parallax Servo Control
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th September 2005, 08:18
  4. Replies: 9
    Last Post: - 30th August 2005, 06:33

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts