Some questions on motor speed control


Closed Thread
Results 1 to 8 of 8
  1. #1

    Default Some questions on motor speed control

    Hi everyone,
    I'm starting to explore on motors specifically on 12v DC motor. Basically first I want to make it stop, turn it half speed and full speed using 10K resistor on PortA.0. Can I apply the following code from markedwards?
    Code:
    ADCIN 1,AD1 'read channel 1...AN1
    AD1 = AD1 >> 6 'justify data
    
    ADJUSTFAN: 
    IF AD1 < 2 then FANSPEED = 153 '60% min speed
    IF AD1 >= 3 then SPEED = 178 '70%
    IF AD1 >= 5 then SPEED = 204 '80%
    IF AD1 >= 7 then SPEED = 229 '90%
    IF AD1 >= 9 then SPEED = 255 '100%
    IF SPEED > SPD THEN SPD = SPD + 1 'accelerate
    IF SPEED < SPD THEN SPD = SPD - 1 'de-accelerate
    hpwm 2,SPD,32760 ' PWM 20,000 Hz
    As I understand I need a pic that support HPWM, please forgive me if this may sound very basic but how I connect the assigned port pin to the motor?

    I have tried using L298N, which I can stop, turn cwise and ccwise the motor, can I also control the speed and can anyone show simple code how to do this?

    Thanks in advance,
    joe

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Some questions on motor speed control

    A lot of motors (most of the brushless ones) don't really like it when you simply "chop" the voltage. While, they will vary their speed, but it is awfully hard on them, and you will probably shorten their lifetime. Remember, there is an IC inside the fan, and there isn't enough capacitance inside that little motor to smooth the voltage to it. What you are attempting to do isn't the same as using an H-bridge to drive motor windings directly!

    A far better approach is to use a more sophisticated circuit using a FET driver, a FET, an inductor, a Schottky diode and a capacitor. You will also have to write to the PIC registers directly, because you should increase the PWM frequency to above 100Khz as well.
    The result is basically pure DC, with very little ripple. A true switching power supply with
    variable output voltage.

    Let me know if you really want to try the approach I outlined, and I'll send you a simple schematic.
    Charles Linquist

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Some questions on motor speed control

    Thanks Charles Linquis to the quick reply, please do send me your schematic where I can learn how to work on these motor. I'm willing to try what you are suggesting.

    regards,
    joe

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: Some questions on motor speed control

    This circuit is good for up to about 5 amps. Make certain you choose an inductor that can handle 7 Amps or so without saturation.
    Attached Images Attached Images
    Charles Linquist

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Some questions on motor speed control

    Quote Originally Posted by joseph Degorio View Post
    Hi everyone,
    I'm starting to explore on motors specifically on 12v DC motor. Basically first I want to make it stop, turn it half speed and full speed using 10K resistor on PortA.0. Can I apply the following code from markedwards?
    Code:
    ADCIN 1,AD1 'read channel 1...AN1
    AD1 = AD1 >> 6 'justify data
    
    ADJUSTFAN: 
    IF AD1 < 2 then FANSPEED = 153 '60% min speed
    IF AD1 >= 3 then SPEED = 178 '70%
    IF AD1 >= 5 then SPEED = 204 '80%
    IF AD1 >= 7 then SPEED = 229 '90%
    IF AD1 >= 9 then SPEED = 255 '100%
    IF SPEED > SPD THEN SPD = SPD + 1 'accelerate
    IF SPEED < SPD THEN SPD = SPD - 1 'de-accelerate
    hpwm 2,SPD,32760 ' PWM 20,000 Hz
    As I understand I need a pic that support HPWM, please forgive me if this may sound very basic but how I connect the assigned port pin to the motor?

    I have tried using L298N, which I can stop, turn cwise and ccwise the motor, can I also control the speed and can anyone show simple code how to do this?

    Thanks in advance,
    joe
    I am not sure about the logic of the code.
    But a very easy way of having the control of a motor by analog pin (with a pot) should be like:

    Code:
    ADCIN 0, CCPR1L ' Read Pot, and put the result directly to PWM register. Assuming 8-bit adc reading.
    Why don't you first try to see the result of this one line of code and then go on?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Some questions on motor speed control

    ADCIN 0, CCPR1L ' Read Pot, and put the result directly to PWM register. Assuming 8-bit adc reading
    Hi sayzer, thanks for the time. I settle to use L298 because that's what I have right now. Can you help me check my connection between the PIC and L298..is this okay? Like I said in first post I was able to control the L298 but without PWM conttrol on PortB. Now I want to apply the PWM on PortC.1, but not really sure how is the connections...

    thanks in advance,
    joe
    Attached Images Attached Images  

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Some questions on motor speed control

    Quote Originally Posted by joseph Degorio View Post
    Hi sayzer, thanks for the time. I settle to use L298 because that's what I have right now. Can you help me check my connection between the PIC and L298..is this okay? Like I said in first post I was able to control the L298 but without PWM conttrol on PortB. Now I want to apply the PWM on PortC.1, but not really sure how is the connections...

    thanks in advance,
    joe

    I never used L298, I always made my own H-Bridge.
    Using PWM on L298, some people drive Enable pin by PIC's PWM output. I am not sure how effective this is.
    I would, however, use 7408 AND gate (two gates, one pin common to PWM pin), others to direction pins.
    This way, you always have a PWM channel, and also have the control of the direction.

    ______________________
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: Some questions on motor speed control

    thanks, sayzer. I will try to take time to study it.

    regards,
    joe

Members who have read this thread : 1

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