Many applications in industry such us robotics controls, swing machines, electronic bikes, winding machines, Spinning and Weaving machines and many others applications need a variable speed of DC motor. The best method for speed control of DC motor is the use of Pulse Width Modulation technique. This is a method to control the output voltage with the of constant frequency switching and by adjusting on duration of switching and in other words by changing duty cycle of switching.
unsigned short current_duty1, current_duty2,dt;
void main()
{
ADCON1 |= 6; // all ports as digital
CMCON |= 7; // comparators off
TRISD = 0X03;
PORTD=0;
PWM1_Init(5000); // Initialize PWM module at 5KHz
PWM1_Start(); // start PWM1
while (1) { // endless loop
if (RD0_bit==1 && RD1_bit == 0) // button on RD0 pressed
{
Delay_ms(40);
//current_duty1=127; // Set duty ratio to 50%
current_duty1=64; // Set duty ratio to 25%
// duty ratio can be calculated as (Percent*255)/100
PWM1_Set_Duty(current_duty1);
}
else if (RD1_bit==1 && RD0_bit == 0 ) // button on RD1 pressed
{
Delay_ms(40);
//current_duty1=192; // Set duty ratio to 75%
current_duty2=216; // Set duty ratio to 85%
// duty ratio can be calculated as (Percent*255)/100
PWM1_Set_Duty(current_duty2);
}
else
{
Delay_ms(40);
dt=0;
PWM1_Set_Duty(dt);
}
Delay_ms(10); // slow down change pace a little
}
}
That's all for today, thanks for reading Speed Control of DC Motor using PIC Microcontroller. I hope you have enjoyed this tutorial. In the end, I again wanna thanks to my dear friend Salah Dahouathi who has spend time in designing this great simulation, programming code and tutorial. You should also like his Facebook Group where he keeps on posting such Arduino related projects, name of his Facebook group is Let's Think Binary. So, will see you guys in next tutorial, till then take care and have fun !!! :)
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w