The Godfather talking
You think I am funny guy huh?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 22, 2024, 05:33:34 17:33


Login with username, password and session length


Pages: [1]
Print
Author Topic: pic dc motor controller  (Read 8429 times)
0 Members and 1 Guest are viewing this topic.
chip2007
Guest
« on: November 07, 2007, 06:53:50 18:53 »

i need to make a dc motor controller with quadrature encoder feedback
using pic micro.

i need a link of simlar circuits

tanks
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #1 on: November 07, 2007, 07:55:58 19:55 »

Hi, have you check out the Microchip Application Notes?

Many motor control app notes there, one of them is AN696 - PIC18CXXX/PIC16CXXX DC Servomotor

Regards, Ichan.
Logged

There is Gray, not only Black or White.
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #2 on: November 08, 2007, 07:30:15 07:30 »

i need to make a dc motor controller with quadrature encoder feedback
using pic micro.

i need a link of simlar circuits

tanks

What kind of control are you looking for?
Do you need the encoder for absolute position or for speed feedback?
Logged

- Brain juice -
chip2007
Guest
« Reply #3 on: November 08, 2007, 08:09:19 08:09 »

i need control the position of
motor to make a controlled position movement
Logged
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #4 on: November 08, 2007, 09:39:40 09:39 »

Ok, then.
What kind of encoder are you going to use?
How many steps(single) does it have?
Do you wish a simple design or a complex one?
In what range the position will be?
It is enough a 16bit counter or do you need a larger one?
You need to control the motor in both ways(forward/reverse)?
Logged

- Brain juice -
chip2007
Guest
« Reply #5 on: November 08, 2007, 11:32:06 11:32 »

with 16 bit counter maximum number of pulses is 65535 with incremental encoder
500 impulse/revolution the maximum number motor revolution is 131

for my projets is good.  the motor turn in bot sense of rotation

the start , stop and position is transfered to micro with serial port rs232
 
Logged
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #6 on: November 08, 2007, 11:37:07 11:37 »

You need also speed control?
Logged

- Brain juice -
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #7 on: November 08, 2007, 02:55:02 14:55 »

Hi!
I have solution for Yr. problem(unless it draws too much current). It is also able to reverse along with speed.

Rotate numbers, rotate motor!
 
If You rotate the number in the register even the stepper motor rotate. A bipolar stepper motor attached to a 4-bit register. If You rotate in the register, the stepper motor also rotate CW or CCW.
A steppermotor with 2 coils (bipolar) can be attached to a 4-register. The current through the coils passes the registercells containg “1” through 0, therefore the drivers has semi-bridges. The register initially contains 1100H and the steppermotor is in neutral.
If You rotate the number 1100 one step between each cell, You get 0110. This transition forces new current in the coils, thereby forces the stepper motor to a new position. If You increase the rotation twice, the stepper motor follows accordingly. After that You’re back to 1100H. Totally the sequence contains 4 steps and the stepper motor is rotating as long as You repeat this.
 If You on the other hand reverse the number, the stepper motor goes in the reverse order. Look below:
 
Stepper motors with 4 coils(unipolar) are suitable for simpilified drivers. The current only have to move to the register cells(never from)
If You use 4-coil  stepper motor(unipolar), the register driving stag can be simplified. The register cells only have to deal with current from the coils, and they can normally use MOS-FET transistors(or the instead of half-bridges. Regardless of construction, the principle of rotating the number 1100 is the same.
________________________________________
Skift and rotationinstructions
 
2 rotation instructions in the PIC-processors
 The PIC-processors has 2 rotation instructions, RLF and RRF. They can be rotated one step via the Carry flag. In that way, You can remove bits from the register with the Carry flag.
The C_language has 2 skift operators rightshift >> and leftshift<<
The CC5X-compiler solves this with two internal functions: char rr(char); and char rl(char);
________________________________________
Program:
In order to rotate the 4-bit number 1100 in an 8-bit register,we need to load it “twice” as 11001100. The instructions RLF and RRF shifts the number through the Carry flag while we will shift it directly in the register. By loading the Carry flag before we instruct Carry-flag with the bit we want to shift to the register, we get the desired function.
The RPM of the stepper motor is determined by the time delay between the steps. The following program could be a part of driving a stepper motor.
STATE = 0b1100.1100;  /* magic number 1100 twice because 8-bit register         */
TRISB = 0b1111.0000;  /* Stepper motor Windings at Z2-Z0, Z3-Z1 outputs      */

/* one step CW  */
Carry = STATE.0;   /* Bypass old Carry */
STATE = rr( STATE );
PORTB = STATE;

/* one step CCW */
Carry = STATE.7;   /* Bypass former Carry */
STATE = rl( STATE );
PORTB = STATE;

//pwmspeed.c Here's a convenient, fast and small method using the CC5X

/* toggle.c  Motor cw/ccw */
#include "16F84.h"
#pragma config |= 0x3ff1  /*This terminology I dislike, it doesn't say how the fuses are configured without a hex-calculator.
                     It's like naming registers in hex instead of in binary*/
                     
#pragma bit button @ PORTB.3 // special for CC5X
#define ON 1
#define OFF 0
#define Z0 0b00  //here are the 4 quadrants
#define Z1 0b01
#define Z2 0b11
#define Z3 0b10
void delay10( char );
void main()
{
char Input;
char State=Z0;
TRISB=0b11111.1.00;
while(1)
{
switch(State)
{
case Z0:                              //case statements take less instructions than for();
if( button == OFF ) State = Z0;
if( button == ON ) State = Z1;
break;
case Z1:
if( button == OFF ) State = Z2;
if( button == ON ) State = Z1;
break;
case Z2:
if( button == OFF ) State = Z2;
if( button == ON ) State = Z3;
break;
case Z3:
if( button == OFF ) State = Z0;
if( button == ON ) State = Z3;
}
PORTB = State;
delay10(50); /* 0,5 sek delay */
}
}
void delay10( char n) /* CC5X delayfunction */
{
char i;
OPTION = 7;
do
{
i = TMR0 * 39; /* 256 microsec * 39 = 10 ms */
while ( i != TMR0) ;
} while ( --n > 0);
}


//Cheers robban


« Last Edit: November 09, 2007, 12:29:18 12:29 by robban » Logged

Code Warrior
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #8 on: November 09, 2007, 12:33:06 12:33 »

Ok, then.
What kind of encoder are you going to use?
How many steps(single) does it have?
Do you wish a simple design or a complex one?
In what range the position will be?
It is enough a 16bit counter or do you need a larger one?
You need to control the motor in both ways(forward/reverse)?


More questions than answer!
Logged

Code Warrior
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #9 on: November 09, 2007, 12:36:59 12:36 »

More questions than answer!
LOL Robban.
For answering you need to know what exactly the person it's trying to do.
He said "pic dc motor control", for this there are a lot of solutions like:
- open loop control
- closed loop control
- speed control
- position control
I have recently worked at a DC Motor project and seen that is something very complex, so that's way I asked those questions. Is there a problem?
Logged

- Brain juice -
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #10 on: November 09, 2007, 01:09:27 13:09 »

OK Tavioman!  Sorry for being rude.
Have a look at my suggestion in section "CC5X". I admit it's a bit tricky due to special commands in the CC5X, but it uses less code and smaller PIC:s. Less is more!

Cheers robban!
Logged

Code Warrior
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #11 on: November 09, 2007, 01:20:16 13:20 »

I have done some motor control using PIC18F, it has come out a good motor control.
But there was a lack of freedom in using PWM pins so I have decided to move this project to ATMEL.
They give much more freedom to the PWM pins. The drawback instead is the resolution of PWM I'm using.
I don't know very much about low level steper motor driving. Now I'm working(@ work) with some excellent Stepper Drivers board that we manufacture. It's ultra complex stuff(closed loop, open loop, ramping, move profiles, etc)
We drive the steper from a Freescale MCU trough a FPGA. It's not a hobby stuff...
Now I'm finding the advantages of steppers.
Logged

- Brain juice -
Xwing
Active Member
***
Offline Offline

Posts: 211

Thank You
-Given: 591
-Receive: 1530



« Reply #12 on: November 09, 2007, 01:25:18 13:25 »

i need to make a dc motor controller with quadrature encoder feedback
using pic micro.

Use PIC18F4431, it's perfect for pid controller, hardware quadrature encoder with position and velocity feedback.
Logged
mandoanaiz
Newbie
*
Offline Offline

Posts: 11

Thank You
-Given: 242
-Receive: 2


« Reply #13 on: November 21, 2007, 05:39:50 17:39 »

what type of motor can I use in proteus for pid?
 thanks in advance
Logged
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #14 on: November 21, 2007, 07:13:37 19:13 »

I have done some motor control using PIC18F, it has come out a good motor control.
But there was a lack of freedom in using PWM pins so I have decided to move this project to ATMEL.
They give much more freedom to the PWM pins. The drawback instead is the resolution of PWM I'm using.
I don't know very much about low level steper motor driving. Now I'm working(@ work) with some excellent Stepper Drivers board that we manufacture. It's ultra complex stuff(closed loop, open loop, ramping, move profiles, etc)
We drive the steper from a Freescale MCU trough a FPGA. It's not a hobby stuff...
Now I'm finding the advantages of steppers.
I do beleive You master dc-motor control. That's why I ask You; Isn't possible to use one of the unused bits in the MCU to actually reverse the order of roation(f.ex.) the carry bit. If You flip the carry bit(or maybe the unused ninth bit in a RSR232, it can be used as a reverser). This can implie a lot smaller MCU:s
Logged

Code Warrior
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #15 on: November 22, 2007, 06:18:32 06:18 »

I do beleive You master dc-motor control. That's why I ask You; Isn't possible to use one of the unused bits in the MCU to actually reverse the order of roation(f.ex.) the carry bit. If You flip the carry bit(or maybe the unused ninth bit in a RSR232, it can be used as a reverser). This can implie a lot smaller MCU:s
Stepper is totally different from PMDC motors. In fact we use two H-Bridge's to control one stepper. We do not control steppers directly from MCU but trough a FPGA. I don't know what's in it. The hardware guys know...
Logged

- Brain juice -
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #16 on: November 22, 2007, 06:19:35 06:19 »

I do beleive You master dc-motor control. That's why I ask You; Isn't possible to use one of the unused bits in the MCU to actually reverse the order of roation(f.ex.) the carry bit. If You flip the carry bit(or maybe the unused ninth bit in a RSR232, it can be used as a reverser). This can implie a lot smaller MCU:s
The one with encoder ofcourse. Smiley
Logged

- Brain juice -
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #17 on: November 23, 2007, 04:03:41 16:03 »

I'm not sure what kind of DC-motor we're talking about... What I mean is if You use a PIC(don't know much abt. FPGA) is that if You change the rotation of the motor by inverting the PWM-signal at "switch-over point"(when the pulsegenerator goes beyond the 255(or whatever resolusion) soo that ground level changes from "0" to "1". With the 8-bit PIC:s, You loose one bit and the resolution will be +127 to -128. Of course You have much more versatility with FPGA:s. But, as I always say: Less is more.

Anyway, how many bits do You have at Yr. FPGA disposal?
Anybody want a CC5X small reversible motor(16F628)?
« Last Edit: November 23, 2007, 09:16:04 21:16 by robban » Logged

Code Warrior
tavioman
Active Member
***
Offline Offline

Posts: 151

Thank You
-Given: 14
-Receive: 17



« Reply #18 on: November 27, 2007, 05:19:27 17:19 »

There are several motors:
PMDC - permannent magned DC motor(the usual one)
SR - switched reluctance motors
BLDC - brushless DC motor
Stepper motors.
I believe that your example is for stepper motors.
Stepper motors and PMDC motors have completely different ways of approach.
Logged

- Brain juice -
fernandodiaz
Junior Member
**
Offline Offline

Posts: 73

Thank You
-Given: 1
-Receive: 18


« Reply #19 on: November 28, 2007, 01:02:40 01:02 »

Hi friends a little contribution for build dc servocintrol  cuple this samples to feedback encoder

PID control for temperature and position control    can use proton



kp = 10  'adjust depening gain this
ki =  10  'adjust depening gain this
kd = 10  'adjust depening Gain this




While 1 = 1

Error = set_point - position
Error_now = Set_point - position
P = Kp * Error_now
I = I + Ki * Error_now
D = Kd * (Error_now - Error_last): Error_last = Error_now
PID = P + I + D
IF PID > 1023 THEN PID = 1023    '10 BIT LIMIT
IF PID > 255 THEN PID = 255     ' 8 BIT LIMIT
HPWM 1, PID, 1000

Wend

___________________________________


INTEGRAL = 0
LOOP:
    ERROR = REFERENCE_VALUE - MEASURED_VALUE
    RATE = (ERROR - ERRORLAST) / COMPUTATION INTERVAL
    ERRORLAST = ERROR
    INTEGRAL = INTEGRAL + ERROR * COMPUTATION INTERVAL

    PROP = KPROPORTIONAL * ERROR
    DERIV = KRATE * RATE
    INTEG = KINTEGRAL * INTEGRAL

    OUTPUT = PROP + DERIV + INTEG
ENDLOOP




IF (PWMcommand > upperPWMlimit) THEN PWMcommand = upperPWMlimit
IF (PWMcommand < lowerPWMlimit) THEN PWMcommand = lowerPWMlimit

or for this example:

IF (PWMcommand > 100) THEN PWMcommand = 100
IF (PWMcommand <-100) THEN PWMcommand = -100





LOOP:
    RATE = (ENCODER - ENCODERLAST) / COMPUTATION INTERVAL
    ENCODERLAST = ENCODER
    ERROR = SPEED_COMMAND - RATE

IF     ((ERROR > 0 AND PWM_COMMAND <= upper PWMlimit)
   OR (ERROR < 0 and PWM_COMMAND >= lowerPWMlimit))    THEN
         INTEGRAL = INTEGRAL + ERROR * COMPUTATION INTERVAL

    PROP = KPROP * ERROR
    INTEG = KINT * INTEGRAL

    PWM_COMMAND  = PROP + INTEG
    IF (PWM_COMMAND > upperPWMlimit) THEN PWM_COMMAND = upperPWMlimit
    IF (PWM_COMMAND < lowerPWMlimit) THEN PWM_COMMAND = lowerPWMlimit

ENDLOOP




   IF (SPEED_COMMAND >   40) THEN SPEED_COMMAND =  40
        IF (SPEED_COMMAND < -40) THEN SPEED_COMMAND = -40






RATE_LIMIT = 10 * computation interval

        SPEED_CMD_ERR =  SPEED_COMMAND - SPEED_COMMAND_RL
        IF (SPEED_CMD_ERR  > +RATE_LIMIT ) THEN SPEED_CMD_ERR = +RATE_LIMIT
        IF (SPEED_CMD_ERR  < - RATE_LIMIT ) THEN SPEED_CMD_ERR = - RATE_LIMIT
        SPEED_COMMAND_RL =  SPEED_COMMAND_RL + SPEED_CMD_ER





        INTEGRAL =  0        ' initialize integrator
        SPEED_COMMAND_RL = (current actual speed)   

LOOP:

        IF (SPEED_COMMAND >   40) THEN SPEED_COMMAND =  40
        IF (SPEED_COMMAND < -40) THEN SPEED_COMMAND = -40

        RATE_LIMIT = 10 * computation interval
        SPEED_CMD_ERR =  SPEED_COMMAND - SPEED_COMMAND_RL
        IF (SPEED_CMD_ERR  > +RATE_LIMIT ) THEN SPEED_CMD_ERR = +RATE_LIMIT
        IF (SPEED_CMD_ERR  < - RATE_LIMIT ) THEN SPEED_CMD_ERR = - RATE_LIMIT
        SPEED_COMMAND_RL =  SPEED_COMMAND_RL + SPEED_CMD_ERR

        RATE = (ENCODER - ENCODERLAST) / COMPUTATION INTERVAL
        ENCODERLAST = ENCODER
        ERROR = SPEED_COMMAND_RL - RATE

        IF     ((ERROR > 0 AND PWM_COMMAND <= upper PWMlimit)
           OR (ERROR < 0 and PWM_COMMAND >= lowerPWMlimit))    THEN
                  INTEGRAL = INTEGRAL + ERROR * COMPUTATION INTERVAL

       PROP = KPROP * ERROR
       INTEG = KINT * INTEGRAL
       SpeedFF = SPEED_COMMAND_RL * KFFspeed
       AccelFF  = SPEED_CMD_ERR * KFFaccel

        PWM_COMMAND  = PROP + INTEG + SpeedFF + AccelFF
       IF (PWM_COMMAND > upperPWMlimit) THEN PWM_COMMAND = upperPWMlimit
       IF (PWM_COMMAND < lowerPWMlimit) THEN PWM_COMMAND = lowerPWMlimit

ENDLOOP   

Logged
underworld
Guest
« Reply #20 on: December 17, 2007, 09:36:29 21:36 »

i'm not sure b/w pic16F and pic18F ,now i'm trying pic16F

and u can use ic(L293D) for drive 2 or more dc motor
« Last Edit: December 17, 2007, 09:55:25 21:55 by underworld » Logged
charnyutk
Newbie
*
Offline Offline

Posts: 32

Thank You
-Given: 7
-Receive: 5


« Reply #21 on: December 24, 2007, 04:55:33 04:55 »

Are there a servo motor or DC motor
Logged
suresh kumar
Guest
« Reply #22 on: January 07, 2008, 12:52:05 12:52 »

if you need your motor to rotate to a desired position and stay locked in that position, you must try using servo motors.
the servos make for good positional control and also have a very good torque(pulling power)
Logged
mayditia
Guest
« Reply #23 on: April 25, 2008, 05:10:47 05:10 »

Let's make things move


Posted on: April 25, 2008, 06:02:15 06:02 - Automerged

I'm working with BLDC servomotor with NJM2624 motor encoder, AVR uController, and Speed control
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC