Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Frequency for PWM using PIC

Status
Not open for further replies.

XIST

New Member
Can Any one Tell me!!
What frequency of PWM output pin should be for the DC Motor speed control. IS it should low or High...
I want to Control my motor very accurately...:confused:
 
Last edited:
To control your motor "very accurately", a method PWM control based on speed feedback will be more important than the PWM frequency.

Ken
 
Last edited:
With PWM you have frequency and pulse width. To implement speed control, you alter your pulse width up and down to alter your speed up and down. The implement this, you'd use the PIC's built in PWN function as you already mentioned.
 
Yah i m getting your point..yah i know its ccp1con register is for the PWm generation...brother do u have any code for this...i really need this code very much...thank you...waiting for ur reply...
 
The frequency you use for PWM can vary. I have one robot whose motor is run at 16KHz and then two motors in a different robot run at 980Hz. Try out different frequencies and you'll see a difference. In my limited experience it seems that tiny motors do better at lower frequencies? But you definitely get more PWM resolution with lower frequencies (see PWM section of PIC datasheet).
 
DC motor speed is proportional to motor voltage and inversely proportional to motor current (load). It is therefore impossible to get accurate control with a simple PWM, you must have feedback and in fact most speed control applications would not need speed feedback given current feedback and power rail voltage feed forward since motor voltage is rail voltage times duty cycle.
 
The PWM frequency should be selected so that it does not create too much current ripple in the motor windings. Current ripple results in heating of the motor. If you know the terminal inductance L and the terminal resistance R of the motor, you can calculate the electrical time constant of the motor (t = L/R). With the time constant, t , calculated you should make the PWM frequency (much) higher than 1/t [Hz]. Good servomotors can have time constants as low as 50 to 150 microseconds, requiring PWM frequencies up to 40 kHz to 60 kHz.

For controlling the motor speed (or position) efficiently, you must have a good closed-loop control of the motor speed and torque (current). Good commercial controllers have the speed (or position) control circuits clocked at 1 kHz. For a dynamic reaction of the motor, the torque required for the correction of speed (or position) must be reached as quickly as possible. Therefore the current controller is clocked approximately ten times faster (10 kHz).

The accuracy of the entire system depends on the accuracy of the sensors and the quality of the control algorithm.
 
Last edited:
You could have some kind of disk attached to the motor with reflective and non-reflective spaces to make or break an optocoupler beam and use that as your feed back. You would just need to teach the PIC how to recognise the frequency of the pulses as a form of speed.

It will also depend on what kind of load you have on your motor. It would be a lot easier to help you if you could tell us what this is for.
 
The PWM frequency should be selected so that it does not create too much current ripple in the motor windings. Current ripple results in heating of the motor. If you know the terminal inductance L and the terminal resistance R of the motor, you can calculate the electrical time constant of the motor (t = L/R). With the time constant, t , calculated you should make the PWM frequency (much) higher than 1/t [Hz]. Good servomotors can have time constants as low as 50 to 150 microseconds, requiring PWM frequencies up to 40 kHz to 60 kHz.

For controlling the motor speed (or position) efficiently, you must have a good closed-loop control of the motor speed and torque (current). Good commercial controllers have the speed (or position) control circuits clocked at 1 kHz. For a dynamic reaction of the motor, the torque required for the correction of speed (or position) must be reached as quickly as possible. Therefore the current controller is clocked approximately ten times faster (10 kHz).

The accuracy of the entire system depends on the accuracy of the sensors and the quality of the control algorithm.

But for most hobbyist purposes open loop is fine as long as they are monitoring rail voltage and current. taking those to numbers into account is fine unless you need absolute control instead of relative
 
But for most hobbyist purposes open loop is fine as long as they are monitoring rail voltage and current. taking those to numbers into account is fine unless you need absolute control instead of relative

If you measure the input voltage and current, and use that information in your control algorithm, you have a closed loop system.

To original poster XIST: Could you explain in more detail what do you mean by: "I want to Control my motor very accurately"? I assumed that you want to control the speed of the motor accurately, but is the application a constant speed regulation or a more dynamic servo control where the motor must follow a varying speed reference very accurately? What kind of motor do you have? Do you use H-bridge to amplify the PWM signal or some other amplifier?

If the application is a constant speed regulation and does not require fast responses to load disturbances, then open loop (direct PWM control without feedback) speed control works fine (because of the inherent integrator in the dc-motor transfer function). For a dynamic servo control you need a closed loop system with good feedback (accurate and fast ie. no delays). Usually a PD controller is used with DC-motors (the PD controller practically becomes a PID controller because of the integrator in the motor).
 
Last edited:
If you measure the input voltage and current, and use that information in your control algorithm, you have a closed loop system.

To original poster XIST: Could you explain in more detail what do you mean by: "I want to Control my motor very accurately"? I assumed that you want to control the speed of the motor accurately, but is the application a constant speed regulation or a more dynamic servo control where the motor must follow a varying speed reference very accurately?

If the application is a constant speed regulation and does not require fast responses to load disturbances, then open loop (direct PWM control without feedback) speed control works fine (because of the inherent integrator in the dc-motor transfer function). For a dynamic servo control you need a closed loop system with good feedback. Usually a PD controller is used with DC-motors (the PD controller practically becomes a PID controller because of the integrator in the motor).
Actually it is still open with respect to speed.

Motor speed is proportional to the ideal motor voltage which is the power rail voltage time the PWM duty cycle.

The actual motor voltage includes the voltage drop across the armature resistance, which responds directly to the motor load causing the motor to slow down under load by robbing the "ideal armature" of voltage. Adding an error term in to the command proportional to the motor current maintains speed as the motor is loaded down-to much and it oscillates since you are adding positive feedback.

There is good dynamic response since the motor current changes as quickly as the motor inductance allows it to and the supply voltage is compensated, both factors are normally absorbed into the "loop response" making the system finickier than it need be.

There is no control loop in the normal sense since speed is not measured. Speed feedback is needed at that point more for extreme dynamic response (overcoming motor inductance), interchangeability (being able to swap motors or controllers with out recalibration), and absolute accuracy (compensate for system tolerance impact on speed verses command)
 
Actually it is still open with respect to speed.

Motor speed is proportional to the ideal motor voltage which is the power rail voltage time the PWM duty cycle.

The actual motor voltage includes the voltage drop across the armature resistance, which responds directly to the motor load causing the motor to slow down under load by robbing the "ideal armature" of voltage. Adding an error term in to the command proportional to the motor current maintains speed as the motor is loaded down-to much and it oscillates since you are adding positive feedback.

There is good dynamic response since the motor current changes as quickly as the motor inductance allows it to and the supply voltage is compensated, both factors are normally absorbed into the "loop response" making the system finickier than it need be.

There is no control loop in the normal sense since speed is not measured. Speed feedback is needed at that point more for extreme dynamic response (overcoming motor inductance), interchangeability (being able to swap motors or controllers with out recalibration), and absolute accuracy (compensate for system tolerance impact on speed verses command)

You are right, if you use the measurements just to compensate for changes in the supply voltage, it is not a closed loop system. But you can use the input voltage measurement, motor current measurement and the output signal (the PWM duty cycle) to create a closed loop control. It gets a bit complicated and you will need a good model of your system, but with state estimation, it is possible.
 
Last edited:
You are right, if you use the measurements just to compensate for changes in the supply voltage, it is not a closed loop system. But you can use the input voltage measurement, motor current measurement and the output signal (the PWM duty cycle) to create a closed loop control. It gets a bit complicated and you will need a good model of your system, but with state estimation, it is possible.

actually the motor speed is a direct result of the armature voltage... the PWM is command times the rail voltage times a constant plus the current times a constant. but you still need to worry about tolerances and motor inductance.
 
actually the motor speed is a direct result of the armature voltage... the PWM is command times the rail voltage times a constant plus the current times a constant. but you still need to worry about tolerances and motor inductance.

Are you trying to describe a control law there? Or was there something in my posts that you disagree with? That was all very confusing to me.
 
Are you trying to describe a control law there? Or was there something in my posts that you disagree with? That was all very confusing to me.
sorry no ... simple math and fact only.

An ideal brushed motor has no inductance, no resistance, no friction, and no mass. It's shaft rotates at a speed that equals the applied voltage times the motor constant and it draws current equal to supplied horse power divided by supplied voltage times 750 (approximately, I think it might actually be 754)

A fair approximation of a real motor is simply adding the armature resistance and inductance. It gets a bit better if you can add motor mass to the inductance and core losses to the resistance, but not necessary in most cases since in well designed motors they are relatively inconsequential.

Many PID loops, especially hobbyist created ones, are straddled with compensating for power supply changes and current changes due to dynamic loads. it is much easier to stabilize a system if these artifacts are offset in the command rather than the loop since they are readily measured. The dynamic loads themselves, on the other hand, are not readily measured. Here at work it would be the pulsating load of the user on the treadmill, yet even this "random" (from the hardware's point of view) load is fairly well canceled with a current times resistance error factor added to the commanded speed. And this still has nothing to do with PID or speed control, that still runs open loop.

Dan
 
misterT, KMoffett and Ubergeek63 thanks for the kind help!!
Actually i m making plane for that purpose i use simple dc motor with direct attached a 11x4.7 propeller on it...so i want to control the speed of the motor...i make a c code for the pwm...but the problem is motor speed is varying to little extent automatically...and the motor drays 15amps of current...also my mosfet burns out. i used IRFZ44N...what could be the solution for that...
 
XIST,

Please post a schematic of your circuit.

Ken
 
misterT, KMoffett and Ubergeek63 thanks for the kind help!!
Actually i m making plane for that purpose i use simple dc motor with direct attached a 11x4.7 propeller on it...so i want to control the speed of the motor...i make a c code for the pwm...but the problem is motor speed is varying to little extent automatically...and the motor drays 15amps of current...also my mosfet burns out. i used IRFZ44N...what could be the solution for that...

bare minimum you need two of those with at least one gate driver and a schottky diode across the motor

EDIT: being that it is an RC your battery voltage is drooping as well since the motor is likely pulling 5C (five times the amp hour rating of the battery) so you are getting losses on the batteries internal resistance as well.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top