PHPoC is the hardware platform which allows to embed the web application to monitor/control sensors/actuators.
By stacking Brushed DC motor controller on PHPoC, we can easily monitoring/control DC motor via webpage.
As we known, DC motor is controlled using PWM signal. There are many factors effect to speed of DC motor such as duty cycle of PWM, power supply, load... By changing the duty cycle of PWM, we can change the speed of motor. If increasing PWM width, motor rotates faster. If decreasing PWM width, motor rotates slower.
If the brushed DC motor does not have the encoder, we can not know the value of speed.
With some simple lines of code, we can control speed of brushed DC motor.
spc_request_dev(14, "dc1 pwm set period 1000"); //Set PWM cycle time in micro-seconds
spc_request_dev(14, "dc1 pwm set dir +"); // Set direction
spc_request_dev(14, "dc1 pwm set width $pwm"); // Control motor by set PWM width
If motor has an encoder, we can get speed of motor
//get duration of pulse emitted from encoder in micro-second
$enc_period = (int)spc_request_dev(14, "dc1 enc get period");
//calculate the value of speed (pulse per second)
if(!$enc_period)
$speed = 0;
else
$speed = 1000000 / $enc_period;
Combining with web user interface, we can control how fast motor rotate and monitor the speed of motor (see demonstration and source code).
Future workIn the above example, we can control how fast motor rotate, but cannot control the speed of motor to the specific value. Since the value of speed can be known by using encoder, I will use the PID control algorithm to control the speed to the determinable value in the near future.
Comments
Please log in or sign up to comment.