 
 
		
		
				
				
		
			
				
					Clodoaldo, you cannot transfer the pulsin value to the duty cycle without some math manipulation. 
Let's assume you want keep the velocity constant.
You measure the pulse width using the pulsin function (use a word variable)
You will have your motor running with duty cycle = 50%
Now the millisecs returned in the word variable is the speed of your motor and you have to decide which value rappresent the speed that you want to keep put this value into the variable Your_Speed.
Once you have done that, then the math could be as follow:
	Code:
	Read_Speed  Var Word
Your_Speed  Var Word
Deviation      Var Word
Duty            var Byte
Error_Flag       Var Bit
Duty = 50
Your_Speed = ?????
Calculation:
Deviation = Read_Speed * 100 / Your_speed
Error_Flag = 0
If Deviation > 100 then Duty=Duty-(Deviation-100)
If Deviation <100 the Duty = Duty +(100-Deviation)
If Duty > 100 the Error_Flag = 1
Return
 Check Error_Flag before passing the new duty value to the PWM comand.
A Pause value, to give the motor the time to gain the new speed is recommended.
Al.
				
			 
			
		 
			
			
			
				
					Last edited by aratti; - 14th July 2009 at 08:19.
				
				
			
			
			
                        	
		         
			
			All progress began with an idea
			
			
		 
	
Bookmarks