Need help on controlling speed of a motor using PWM

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Need help on controlling speed of a motor using PWM

跳至解决方案
1,740 次查看
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

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
872 次查看
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 项奖励
回复
1 回复
873 次查看
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 项奖励
回复