Professional Documents
Culture Documents
Pwm+motor
Pwm+motor
Write a MikroC Programming to control the speed of a simple DC motor using PWM operation by sending directly
from 0 to 255 continuously.
Components
DC Motor (ACTIVE), Relay, 2n2222, RES, DC source, Digital oscilloscope, and PIC16F877A
int cd = 0; // Initialization of variable cd for storing the current duty
void main()
{
PWM1_Init(5000); // Initialization of PWM at 5000 pulses per second
PWM1_SET_Duty(cd); // initially 0% duty
PWM1_start();
while(1)
{
cd++; // Current duty increment
PWM1_SET_DUTY(cd); //Send the value of cd to the CCP1 pin
if (cd>=255) // When cd=255 which is the max. of PWM output, then it should be started from 0.
{
cd=0;
}
delay_ms(70);
}
}
Assignment
Write a MikroC program to control the speed of DC Motor using potentiometer. For the interfacing of DC motor with
PIC16F877A use L298 motor driver chip or board.