speed control


Closed Thread
Results 1 to 4 of 4

Thread: speed control

  1. #1
    Kees Reedijk's Avatar
    Kees Reedijk Guest

    Default speed control

    I want to do simple speed control of a small dc motor with gearbox and optical encoder. Proportional control will be accurate enough, only one direction. Since the motorspeed will be quite low I thought of using the pulsin command to measure pulse length for the feedback.
    Has anyone done this before?
    thanks

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


    Did you find this post helpful? Yes | No

    Default

    you can use pulsin for sure... if you read few times and do an average, it can provide great results if your pulses are short enough to avoid an overflow of pulsin variable.

    BUT i'll prefer to convert pulses to voltage and read from a/d converter.

    have a look to this thread can give you some hints...
    Click Here
    Steve

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

  3. #3
    Kees Reedijk's Avatar
    Kees Reedijk Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Steve
    Today I managed to get it working using the pulsin command. I use a surplus maxon motor with a 32 step optical encoder, pulse length is not a problem. It works really well. I'm using a pic16F628A.
    Here's part of the code I used:
    p.s.for some reason all my indentation disappears when I posted this message, don't know why
    regards, Kees

    motor CON 3
    sensor VAR PORTB.0
    temp VAR WORD
    setspeed VAR BYTE 'speed set by user
    power VAR WORD 'control variable (CV) , PWM dutycycle
    PV VAR WORD 'process value, or actual speed
    error VAR BYTE 'difference between set speed and actual speed
    Kprop VAR BYTE 'constant for proportional feedback control
    Kprop = 4

    run:
    Pot 5,25,setspeed
    PulsIn sensor,0,temp ' measure speed
    IF temp2 > 0 Then ' check if motor is running
    PV = 10000 / temp ' depends on encoder and motor
    IF PV >255 Then PV = 255
    IF setspeed > PV Then
    error = setspeed - PV
    power = power + (error / Kprop) 'new PWM value
    IF power > 255 Then power = 255 'otherwise overflow
    Else
    error = PV - setspeed
    power = power - (error / Kprop) 'new PWM value
    IF power > 255 Then power = 0 'otherwise overflow EndIF
    Else
    power = setspeed ' so a motor without optical sensor
    EndIF ' can also be used
    HPwm motor,power,10000 ' Send a PWM signal at 10kHz, drive motor
    LCDOut $FE,1,"spd ",DEC3 setspeed 'show on screen
    LCDOut $FE,$C0,"pv ", DEC3 PV 'for debugging
    GoTo run
    Last edited by Kees Reedijk; - 31st March 2005 at 20:24.

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


    Did you find this post helpful? Yes | No

    Default

    hi kees, great to know that's working for you now.

    p.s.for some reason all my indentation disappears when I posted this message, don't know why
    must use VB code click here to know how

    after that your code can look something like that
    Code:
    motor CON 3
    sensor VAR PORTB.0
    temp VAR WORD
    setspeed VAR BYTE 'speed set by user
    power VAR WORD 'control variable (CV) , PWM dutycycle
    PV VAR WORD 'process value, or actual speed 
    error VAR BYTE 'difference between set speed and actual speed
    Kprop VAR BYTE 'constant for proportional feedback control
    Kprop = 4
    
    run:
         Pot 5,25,setspeed 
         PulsIn sensor,0,temp ' measure speed 
         IF temp2 > 0 Then ' check if motor is running
              PV = 10000 / temp ' depends on encoder and motor
              IF PV >255 Then PV = 255
              IF setspeed > PV Then
                   error = setspeed - PV
                   power = power + (error / Kprop) 'new PWM value
                   IF power > 255 Then power = 255 'otherwise overflow
              Else
                   error = PV - setspeed 
                   power = power - (error / Kprop) 'new PWM value
                   IF power > 255 Then power = 0 'otherwise overflow EndIF 
         Else
              power = setspeed ' so a motor without optical sensor 
         EndIF ' can also be used
    
         HPwm motor,power,10000 ' Send a PWM signal at 10kHz, drive motor 
         LCDOut $FE,1,"spd ",DEC3 setspeed 'show on screen
         LCDOut $FE,$C0,"pv ", DEC3 PV 'for debugging
         GoTo run
    and once it's done, it appear that there's one ENDIF missing
    Steve

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

Similar Threads

  1. brushless speed control
    By jetpr in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 24th December 2009, 15:23
  2. Replies: 14
    Last Post: - 26th September 2007, 05:41
  3. Speed Control (help Idea)
    By jetpr in forum General
    Replies: 0
    Last Post: - 1st November 2005, 01:51
  4. Replies: 9
    Last Post: - 30th August 2005, 06:33
  5. Electronic speed control
    By actionplus in forum Schematics
    Replies: 10
    Last Post: - 21st June 2004, 19: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