 
					
				
		
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
Solved! Go to Solution.
 
					
				
		
 BlackNight
		
			BlackNight
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		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
 
					
				
		
 BlackNight
		
			BlackNight
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		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
