Pages

Wednesday, 18 April 2018

ARM-LPC1768 -Interface and Control a DC Motor.


Interface and Control a DC Motor.


Program

/**
  * @brief Run DC motor clockwise when switch is 1
*        and rum anticlockwise when switch is 0.
*        The Speed of the DC Motor can be changed using dutyCycle (using PWM technique).
* SDA  ------------------>  P2.2
* SCL  ------------------>  P2.3
  * 5V   ------------------>  P2.0
* switch ---------------->  P2.5
  */

#include <lpc17xx.h>     
#include "dcmotor.h" 
#include "pwm.h"  
#include "blink.h"

/* switch is connected to P2.5 */
#define    Switch  5    
#define    Pin_1   2 
#define    Pin_2   3 

uint8_t dutyCycle = 50;


/* start the main program */
int main() 
{   
uint32_t switchStatus;

/* Initialize the DC Motor */
  DC_Motor_Init(Pin_1, Pin_2);
  
/* Initialize PWM for Motor Speed Control */
PWM_Init();

/* Set PWM for Motor Speed Control, 100 = Max Speed, 1 = Min Speed */
PWM_Set_Duty(dutyCycle);

while(1)
  {  
/* Turn On all the leds and wait for one second */ 
switchStatus = GPIO_Read(Switch);  /* Read the switch status */

if(switchStatus == 1)                 /* If switch == 1, motor runs in clockwise direction */
Motor_Rotate_Clockwise(Pin_1, Pin_2); 

else                              /* If switch == 0, motor runs in anticlockwise direction */
Motor_Rotate_AntiClockwise(Pin_1, Pin_2); 

  }

}

Hardware Connection
ENA (L298 driver) to P2.0 (PWM pin)
IN1 (L298 driver) to P2.2
IN2 (L298 driver) to P2.3
VMS (L298 driver) to Vin (12Volts, development board)
GND (L298 driver) to
Any one of the screw connector of MOTOR A (L298 driver) to one of the DC motor pin
Another screw connector of MOTOR A (L298 driver) to another DC motor pin

Output
DC Motor starts running with the speed given by dutycycle in the function “PWM_Set_Duty(dutyCycle)”. With respect to the code above, motor runs with full speed as the dutycycle = 100.

FOR DETAIL INFORMATION ABOUT ARM CORTEX DEVELOPMENT KIT : CLICK HERE

No comments:

Post a Comment