Need help on controlling speed of a motor using PWM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help on controlling speed of a motor using PWM

Jump to solution
1,195 Views
admin
Specialist II

Hi. I'm using a MC9S08AW60 MCU. Below is part of the code for controlling the speed of a DC motor using PWM. The motor is able to rotate but I'm not sure how to control the speed.

 

  TPM1SC=0x00;
  TPM1MOD=0x0800;
  TPM1C0V=0x0666;   //driverB    
  TPM1C1V=0x0666;   //driverA  
  TPM1SC=0x08;
  TPM1C0SC=0x00;  
  TPM1C1SC=0x00;

 

Can anyone advice me which parts of the above code controls the speed? This code is not written by me, so I'm quite clueless on this. Below is the link to the MCU datasheet. The PWM topic is at chapter 10. Thx

 

http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S08AW60.pdf?fpsp=1

Labels (1)
Tags (1)
0 Kudos
1 Solution
327 Views
BlackNight
NXP Employee
NXP Employee

Hello,

first off, you will need something which measures the speed of the motor. Typically optical shaft encoders are used for this:

http://engknowledge.com/shaft_absolute_encoder_gray_code.aspx

 

Then, you can use a closed loop control algorithm like this one:

http://en.wikipedia.org/wiki/PID_controller

 

Good luck!

 

BK

View solution in original post

0 Kudos
1 Reply
328 Views
BlackNight
NXP Employee
NXP Employee

Hello,

first off, you will need something which measures the speed of the motor. Typically optical shaft encoders are used for this:

http://engknowledge.com/shaft_absolute_encoder_gray_code.aspx

 

Then, you can use a closed loop control algorithm like this one:

http://en.wikipedia.org/wiki/PID_controller

 

Good luck!

 

BK

0 Kudos