How to use a potentiometer resistor to control speed of motor fan manually?Thanks


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    mengckid's Avatar
    mengckid Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by markedwards
    Hi Mengckid,

    Your Pic has the hardware PWM built-in so it is your best choice.
    Your program can read the ADC (pot) and update the speed variable
    and the hardware PWM does the rest.
    Depending on your motor voltage & current draw you may need to
    consider your Mosfet circuit. Your Mosfet's voltage rating should be
    at least twice your DC supply voltage. You need a clamp diode connected
    across your motor (cathode to M+ anode to M-).
    Your Mosfet has 2 losses that generate heat, conduction loss (dc current squared times the rds on resistance). example 2 Amps x 2 Amps x .1 ohm = .4 watts, requiring a heat sink. The Mosfet has a large gate capacitance that can give slow turn on & turn off times (switching losses). I prefer to use a mosfet driver IC such as TC4426 or TC4427.

    Mark
    HiHi,yaya, thanks u again

    i got few problem here:

    for the code above, I cannot compile this part: The code:
    IF SPEED > SPD THEN SPD = SPD + 1 'accelerate
    IF SPEED < SPD THEN SPD = SPD - 1 'de-accelerate

    the error message is mismatching if loop..then...endif. Thus, i dunno how to fixed it. Thus, here is my code, hopefully you can help me a bit, thanks ya


    INCLUDE "modedefs.bas"
    DEFINE OSC 4

    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 10 ' Set sampling time in microseconds
    AD1 var byte
    SPEED var byte
    SPD var byte

    TRISB = %10000000 ' set output for led portb.0
    TRISC = %11111000 ' set output for pwm portc.2
    TRISA = %111111 ' Set PORTA to all input

    ADCON1 = 0 ' for 10-bit ADC and Set all PORTA is analog
    ADCON0 =%10000101 'SET A/D Fosc/32, [4MHz], CHANNEL-0 = ON

    main:

    ADCIN 0,AD1 'read chanel 1...AN1
    AD1 = AD1 >> 6 'justify data
    gosub ADJUSTFAN
    hpwm 2,SPD,300 ' PWM 20,000 Hz

    IF SPEED > SPD THEN goto acce
    endif
    if speed <= SPD then goto deacce
    endif

    ADJUSTFAN:

    IF AD1 < 2 then
    SPEED = 153
    endif '60% min speed
    IF AD1 >= 3 then
    SPEED = 178
    endif '70%
    IF AD1 >= 5 then
    SPEED = 204
    endif '80%
    IF AD1 >= 7 then
    SPEED = 229
    endif '90%
    IF AD1 >= 9 then
    SPEED = 255
    endif '100%
    return

    acce: SPD = SPD + 1 'accelerate
    hpwm 2,SPD,300
    return

    deacce: SPD = SPD - 1 'de-accelerate
    hpwm 2,SPD,300
    return

    P/s : The code above is Pic Basic Pro code...


    Another problem is how do I get the ADC scaling. Actually, what is ADC scaling mean?? If I wanna do the ADC scaling from 1-32, so how to write in pic basic code? Is it neccessary to iniatiate first, the 1-32 values?

    Thanks u,cheers

    Regards
    Mengckid

  2. #2
    mengckid's Avatar
    mengckid Guest


    Did you find this post helpful? Yes | No

    Default

    I need some helps~~Can anybody tell me how to scale ADC or ADC scaling meaning if i wanna scale a voltage value from 0V to 5V in ADC Scaling from 1-32 values? How to do that?

    In Pic Basic Pro, Do I need to initiate the ADC scaling 1-32 values? like assembely language.

    If I wanna do a increasing speed or decreasing speed continuesly, i wanna create a mathematical equations Pic Basic Pro?Can I...anyone got any ideas,can share here....hehe,thanks a million...I really need a help here,thanks you

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    a range from 0-32!!

    if you use a 10Bit resolution
    Code:
    Adcin 0,Initial
    Final=Initial>>5
    change 5 for 3 if you use a 8 bit resolution.

    32= 2^5 or 5 bit resolution

    Im i still mixed in my head... maybe, as now, it looks good to me.

    10 bit resolution = range of 1024
    8 bit resolution = range of 256

    1024/32 =>32
    256/32 =>8

    and blah blah blah... i feel like a pre-school teacher today
    Last edited by mister_e; - 28th August 2005 at 17:11.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    mengckid's Avatar
    mengckid Guest


    Did you find this post helpful? Yes | No

    Default

    Hi...I need some helps here...once again,i will post my Pic Basic Pro Code below,hopefully somebody will help me fixed my code, bcoz i just cant get the result that i want...

    The Code:

    include "modedefs.bas"
    DEFINE OSC 4

    ' Define ADCIN parameters
    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 10 ' Set sampling time in microseconds

    B0 var BYTE ' Create B0 to store result

    TRISB = %10000000 ' set output for led portb.0
    TRISC = %11111000 ' set output for pwm portc.2
    TRISA = %111111 ' Set PORTA to all input

    CCP1CON = %00001100 ' Set CCP1 to PWM
    ADCON1 = 0 ' for 10-bit ADC and Set all PORTA is analog

    HIGH PORTB.0

    GOSUB GETMBAT 'read voltage variable
    main:

    ADCIN 0,B0 ' Read channel 0 to B0
    B0 = B0 >> 3 'justify data

    if (B0>0) and (B0<5) THEN
    PWM PORTC.1,10,100
    endif
    if (B0>5) and (B0<10) THEN
    PWM PORTC.1,30,100
    endif
    if (B0>10) and (B0<15) THEN
    PWM PORTC.1,60,100
    endif
    IF (B0>15) AND (B0<20) THEN
    PWM PORTC.1,100,100
    endif
    IF (B0>20) AND (B0<25) THEN
    PWM PORTC.1,127,100
    endif
    IF (B0>25) AND (B0<28) THEN
    PWM PORTC.1,160,100
    endif
    IF (B0>28) AND (B0<30) THEN
    PWM PORTC.1,200,100
    endif
    if (B0>30) and (B0<32) then
    PWM PORTC.1,254,100
    endif

    GOTO main

    GETRESULT:
    PAUSEUS 50 'WAIT FOR ADC SETUP
    ADCON0.2 = 1 'START CONVERSION BY SETING GO/DONE BIT HIGH

    LOOP: ' WAIT FOR GO/DONE BIT TO CLEAR
    IF ADCON0.2 = 1 THEN
    GOTO loop
    ENdif
    goto main


    GETMBAT:
    ADCON0 =%00000101 'SET A/D Fosc/32, [4MHz], CHANNEL-0 = ON
    GOSUB GETRESULT 'START CONVERSION
    B0 = ADRES 'STORE THE A/D CONVERSION VALUE IN RESULT
    RETURN


    The PIC that I am using is PIC 16F874A, and i am trying use a 10k potentiometer to control the motor speed (increase or decrease the speed). Thus, I try the HPWM before, just cant get the result also.

    Hopefully, somebody will help me...thanks u

Similar Threads

  1. brushless speed control
    By jetpr in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 24th December 2009, 16:23
  2. Replies: 14
    Last Post: - 26th September 2007, 06:41
  3. Speed Control (help Idea)
    By jetpr in forum General
    Replies: 0
    Last Post: - 1st November 2005, 02:51
  4. speed control
    By Kees Reedijk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 1st April 2005, 00:07
  5. Electronic speed control
    By actionplus in forum Schematics
    Replies: 10
    Last Post: - 21st June 2004, 20:01

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