CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PID motor control: Can it be done this way?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tomal



Joined: 20 Nov 2011
Posts: 9

View user's profile Send private message

PID motor control: Can it be done this way?
PostPosted: Thu Jul 18, 2013 2:17 am     Reply with quote

I'm working for a PID motor control (AC/Single phase/220V/50Hz) using CCS C.
In the first step I made it in open loop mode (regular controller) as you see in the picture that the RPM sensor connected to CCP1 with a dotted line. Zero cross, speed variation and rpm count everything works perfect. Now I'm in the way to work for PID. I'm thinking it in the proposed way (pls see the picture).

1. RPM signal is converted using RC filter and connected to comparator 1 (A0) input
2. Cvref (A2) used as feedback for PID error detection (error=set_speed-current_speed)
3. Comparator 1 out is digital tach and connected to CCP1 for RPM count



I would like to know, can it be done in this way...can I configure internal comparator to work in this way?
Or, is there any better way than I'm thinking?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Jul 25, 2013 8:59 am     Reply with quote

You've had no response in a week.
Probable that nobody else can understand what you are trying to do either.
I certainly can't. It all looks rather complex to me.

Why not work on the KISS principal?

All you need to get RPM is one digital input.
You appear to be doing both analogue & digital.
Where do you get set speed from?
The rest, up to motor drive, is software.

Mike
tomal



Joined: 20 Nov 2011
Posts: 9

View user's profile Send private message

PostPosted: Thu Jul 25, 2013 11:30 am     Reply with quote

Thanks Mike. At least you cared to reply. Smile

I did it finally. Just one question though...how much time PID usually takes to stabilize the speed from no load to load contition?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Jul 25, 2013 11:43 am     Reply with quote

How long is a piece of string?

Seriously, can't tell without lots more information:-

Motor size, power, torque at no load & full load etc.
Is overshoot allowed?
List goes on and on ............

Suggest you do some testing.

Investigate whether you have set up optimal conditions.

Mike
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Jul 25, 2013 2:31 pm     Reply with quote

your circuit makes no sense, on several counts.

** why are RA2,3 tied and with a cap to ground ?

**what is the ra4 c2 connection to the freq opto interruptor?

**why the unknown TC of the RC circuit into A0

** you don't even SHOW an output to spin UP the motor
and close the PID loop !!!
what controls motor excitation anyway ??

HINT: its not in the schematic

** and lastly with no values for parts and no code,, what do you expect ??
tomal



Joined: 20 Nov 2011
Posts: 9

View user's profile Send private message

PostPosted: Fri Jul 26, 2013 12:20 am     Reply with quote

@Mike:
The controller I'm experimenting is for 1hp motor, rated for 35k rpm. My desired rpm is 5k-25k. It is actually the router (motor) for CNC router. Since it is an AC/50Hz motor and I have to compensate firing angle to maintain the speed.

This is the first time I worked with PID so some of the points are not cleared to me. Speed stabilization is one of them. i.e. I set the speed for 5k in no-load condition and then starts cutting. But speed drops immediately to 3.5k whenever tip touches the surface. Then slowly stabilizes to the set point (5k). I noticed that the stabilization takes 5-6 seconds. It is not a problem for lower cutting speed but may break the cutter (cutting bit) at higher cutting speed (I haven't experimented higher speed yet). Hope you understand my concern now.

@asmboy:
[EDIT] This is not the circuit I worked with and not the complete one. Here is just the feedback part related to my question.

I was initially not sure to compute the error. I thought I'll feed the RPM as analog (C1, R2 & R3) and (re)generate the pulse using internal comparator. CVref will be used as feedback (instead of digital tacho). However, (regenerated) tacho at RA4 connected to CCP to count and display the RPM. Forget about dotted line. I should'nt have drawn it.

It was a complex concept Mad initially developed in my mind and I left it later. I finally did it in a more simpler way.


Last edited by tomal on Fri Jul 26, 2013 7:49 am; edited 1 time in total
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Jul 26, 2013 7:23 am     Reply with quote

Hi Tomal,

Try to avoid ageist comments, you risk offending the forum members most likely to offer significant help.

Asmboy took the trouble to analyse your offering, I didn't care to.

You now say you've not used most of the 'schematic' shown.

So, in total, you are giving us nothing to work on, either hardware or software.

As for you current problem:-

I'm assuming you have constants Kp,Ki & Kd for each of the P,I & D terms.
Do tests under no-load and full load conditions.
Investigate the effect(s) of varying each of the above constants in a logical and systematic manner.
You will learn how PID works.
You will discover how far away you are from optimal operation.

With little else to guide me, that's my best suggestion.

Mike
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Jul 26, 2013 8:52 am     Reply with quote

Quote:

speed drops immediately to 3.5k whenever tip touches the surface. Then slowly stabilizes to the set point (5k).


fast interpretation , HOWEVER in heck you are doing it:

* the D time constant may be too long ( fast drop in speed )
or
* D gain may be too low

AND

* the I TC may be too long ( slow stabilizes)
or
* I gain too GREAT

OR

plain old P gain too low ( tho least likely )

or some combo of all of this.
I C plenty of places to look for trouble

as Mike said, there is too little data to work with and in the case of a real world PID - you need some better analysis of the hardware you are controlling - since a motor in terms of the physics has its OWN virtual I component inherrent in the effective mass of he spinning rotor.

Be it heat or motion - practical PID controllers need to accommodate a certain amount of physical "I" term in the controlled object. It is always there.

I find that experiment and testing can yield better numbers for
the not-to-be-overlooked ( important) time constant aspects of the I & D terms of your design. It might be the difference between complete success and utter failure.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Jul 26, 2013 4:31 pm     Reply with quote

Again with little else to go on.

How quickly are you measuring rotational speed?
It's crucial.
If your measurement is too slow, then nothing else can happen reasonably quickly.

Just a wild guess.

Mike

EDIT Have you done any kind of analysis?
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Fri Jul 26, 2013 6:25 pm     Reply with quote

I would think an important input to your control algorithm would be load current so you could measure the load on the motor. I would expect the load current to change faster than the rpm of the motor when it starts (or stops) cutting.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jul 26, 2013 6:41 pm     Reply with quote

mikey's right about load current monitoring ! You don't say what material the CNC will will used on,but from first hand experience 'wood' is interesting, MDF is hohum and aluminum is well, just boring (no pun intended)
You should have at least 3 identical runs into whatever material you're going to use and record ALL the data.The more numbers ,the better the guess you an make about the PID constants. If you have access to MATLAB,just import and compute...MATLAB will quickly spit out the numbers for you.

hth
jay
tomal



Joined: 20 Nov 2011
Posts: 9

View user's profile Send private message

PostPosted: Sat Jul 27, 2013 1:02 am     Reply with quote

Thanks guys for your expert opinion.

My feedback is rotation and I'm not monitoring load current at the moment. Target materials are wood, HDPE (plastic) and some aluminium. But I'm using HDPE in current development phase.

I did some fine tune for the constants and reduced the stabilization time from 5-6 sec to 1-2 sec. But sudden drop in load condition has no improvement at all. Is this normal?
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 27, 2013 5:35 am     Reply with quote

Now you know why we've said you must monitor the current. Speed alone won't tell you everything.
Also, we don't know how you're controlling the router's speed,that bit of electronics will need to be 'tweaked' as well.
And depending on the material being used, the 'travel speed' of the router will need to be adjusted in order to maintain proper cutting.You have to go slow when removing 1" of MDF but can go fast if only 1/8" aluminum.

hth
jay
tomal



Joined: 20 Nov 2011
Posts: 9

View user's profile Send private message

PostPosted: Sun Jul 28, 2013 6:21 am     Reply with quote

Thanks jay. Seems I need to look on current monitoring.
But isn't it the same?

Since it's a CNC application and the subject is load or no-load. Load currrent will change only if the cutter touches the surface. I think PID algo never know when it has the load and will immediately compansate whenever noticed the difference. I think same thing happens with the rpm feedback.

By the way, I have a strange thing happened today. I was out of stock for crystal so I worked with the internal osc. My crystal's arrived today and I changed the fuse but PIC runs vey slow with the crystal clock. Is my PIC18F2420 bad?

Internal clock:
Code:

#include <18F2420.h>

#device adc=10
//#device HIGH_INTS=TRUE

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOPROTECT                //NO Code protected
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin not enabled
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#use delay(int=8000000)         //Use 8MHz Internal OSC


With crystal:
Code:

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOPROTECT                //NO Code protected
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin not enabled
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES HS
 
#use delay(clock=8000000)         //Use 8MHz Internal OSC
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group