Let's assume you want to controll the velocity and you have no feedback from the motor.
You will give the word variable Max_Speed an arbitrary value that you will never exceed (this will reppresent duty = 100%).
You measure the pulse width using the pulsin function (using a word variable)
Once you have done that, then the math could be as follow:
Code:
Read_Speed Var Word ' value that you will send via RC
Max_Speed Var Word ' arbitrary value = to 100 Duty cycle
Duty var Byte
Error_Flag Var Bit
Max_Speed = ????? ' you enter here your arbitrary value
Calculation:
Error_Flag = 0
Duty = (Read_Speed * 100 / Max_speed)
IF Duty > 100 Then Duty = 100 : Error_Flag = 1
Return
If Error_Flag = 1 then you have sent a value greater than the permissible one.
You can add a line saying that if Read_Speed is minor then X duty = 0
(If Read_Speed < xxx then Duty = 0) in case Read_Speed could never be zero.
Remember that HPWM duty cycle 100% = 255.
Al.
Last edited by aratti; - 14th July 2009 at 09:16.
All progress began with an idea
Bookmarks