Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that changes the speed of the DC motor proportional to the value

ID: 1996388 • Letter: W

Question

Write a program that changes the speed of the DC motor proportional to the value of a potential meter. For example, If the potential meter is on the max the speed of the DC motor should be max you can achieve this by applying a signal with 100 percent duty cycle If the potential meter is on the half of the value the DC motor have to apply a signal with a 50% duty cycle. If the potential meter is on 10% of the maximum value your program should change the duty cycle to 10% and so on so for. To connect your DC motor to the PIC microcontroller you have to use a power switch such as TIP47 or Hbridge.

Explanation / Answer

#include <p18F4520.h> /* Include the PIC18F4520 header file */
#include <pwm.h> /* Include the PWM library */
#include <timers.h> /* Include the Timer Library */
#include <portb.h> // Header files for port B interrupts

void main()
{
short duty = 0; //initial value for duty

TRISD = 0xFF; //PORTD as input
TRISC = 0x00; //PORTC as output
TRISB = 0x00; //PORTB as output
PORTB = 0x02; //Run motor in anticlock wise

PWM1_Init(1000); //Initialize PWM1
PWM1_Start(); //start PWM1
PWM1_Set_Duty(duty); //Set current duty for PWM1

while (1) // endless loop
{
if (ADC_Read(0)==0x0C)

{   
Delay_ms(40);   
duty = 100;   
PWM1_Set_Duty(duty);
}   
if (ADC_Read(0)<=0x0C)

{
Delay_ms(40);
duty = 50;
PWM1_Set_Duty(duty);
}

if (ADC_Read(0)<=0x02)

{
Delay_ms(40);
duty = 10;
PWM1_Set_Duty(duty);
}

Delay_ms(10);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote