Thứ Sáu, 14 tháng 12, 2018

DC Motor Control with Joystick & AVR Microcontroller



In many of the applications it is required to alter the direction of DC motor instantly. Like in washing machine, mixer, drilling machine winding – rewinding machine etc. Changing the direction of DC motor using joystick is most suitable and handy method.

Joystick Control for DC motor is mostly used in different Robotic applications like
·         Moving robotic hand up and down
·         Rotating robotic arm clockwise or anticlockwise
·         Moving robotic vehicle forward or reverse
·         Rotating robotic eye (camera) complete 360o

Also in industries the joystick control is most preferable way to control machinery that is operated with DC motor. The best example is 3 axis or 2 axis DC motor operated crane. In this, 3 (or 2) DC motors  moves crane up or down, rotate it left or right using 3 (or 2) joysticks.

And the biggest application of joystick control for DC motor is in RC (remote control) toys. RC cars, RC helicopters, RC motor boats, RC planes etc all uses wireless joystick control to control DC motor and to rotate it forward and reverse.

So this project illustrates how to change direction of DC motor using simple potentiometer as joystick. Here i have used potentiometer in place of joystick but any standard resistive joystick can be used. It is readily available in market. This is just a demonstration but one can also make real time industrial application with few modifications. Some of the ideas for advancements are discussed at the end of this project.
joystics
Schematic diagram: -
As shown in circuit diagram tab, the application is made using only two ICs, potentiometer and LEDs. AVR microcontroller ATMega32 used as motor controller and H-bridge driver L293D is used as motor driver chip. Potentiometer is used as joystick. It can be replaced by readily available joysticks in which resistance changes as joystick is moved upward or downward (here only difference is resistances changes as pot is rotated clockwise or counter clockwise). Three LEDs of different colours are used to indicate motor is rotating forward, reverse or its stop.  

Connections & Operation

Connections:
·         From three terminals of pot, two are connected to Vcc and Gnd to provide bias to it. The sliding contact is connected to ADC0 input pin PA0 of ATMega32 controller. This gives varying voltage input to ADC
·         The anodes of all three LEDs are connected to PORTD pins PD0 – PD2 through current limiting resistors
·         PORTC pins PC0 and PC1 are connected to input of L293D. DC motor is connected to output pins of L293D. Thus ATMega32 controller drives 12 V DC motor through L293D chip
·         A 16 MHz crystal is connected to crystal input pins. It provides basic clock to controller to do  internal operations
Operation:
·         Initially as power is given to circuit the motor start rotating in either of the directions. This is because the digital value (corresponding to analog voltage at ADC input) is either less than mid range value or more than mid range value
·          
·         As the pot is rotated to middle position, the digital value also comes in the mid range value. This makes motor to stop rotating. The Blue LED indicates motor is stop
·         Now from this middle position as the pot is rotated clockwise the digital value increases (or decreases). This starts rotating motor in one direction.
·         Similarly when pot is rotated counter clockwise digital value decreases (or increases) that rotates motor in another direction
·         One can set motor terminals in such a way that when pot is rotated clockwise motor also rotates clockwise and vice versa.
·         To stop motor again move the pot to mid position

Further Advancement

·         Two or more such pots can be connected to simultaneously control two or more DC motors
·         The speed of DC motor can be changed in 2 or 3 steps in either direction as pot is rotated further fully clockwise or counter clockwise
·         Wireless joystick can be made to control DC motor operation wirelessly from remote place
·         By replacing the motor driver chip with TIP122 – TIP127 bridge or SSR (solid state relay) bridge configuration one can control DC motor of higher ratings (high power, high current) used in industries.
The project is tested on AVR development board with additional DC motor driver as shown in following snap and video
joyastics






Circuit:
Joystick control for DC Motor:Circuit Diagram

Code:

#include <avr/io.h>
#include <util/delay.h>
void adcinitliz()                   // initialize ADC
  {
      ADMUX = (1<<REFS0);
      ADCSRA =(1<<ADPS2) | (1<<ADPS1) | (0<<ADPS0);
      ADMUX=0x00;
  }
void rotate()                       // rotate motor
  {                                                  
      unsigned int tmp1,tmp2,tmp3,t;
      unsigned char asci[4]; 
      tmp1 = (ADCL & 0x0F);         // convert HEX value of ADC 10 bit
      tmp2 = ADCL >> 4;             // output in to decimal
      tmp3 = (ADCH & 0x0F);  
      tmp2 = tmp2*16;
      tmp3 = tmp3*256; 
      t = tmp1+tmp2+tmp3;    
      if((t>=500) && (t<=525))      // if decimal value is in mid range
        {
            PORTD = 0x01;           // stop motor and
            PORTC = 0x00;           // indicate on LED
        }
      else if(t>525)                // if more than mid range
        {
            PORTD = 0x02;           // rotate motor in one direction
            PORTC = 0x01;
            _delay_ms(200);
            PORTD = 0x00;
            PORTC = 0x00;
        }
      Else                          // otherwise
        {
            PORTD = 0x04;           // rotate motor in other direction
            PORTC = 0x02;
            _delay_ms(200);
            PORTD = 0x00;
            PORTC = 0x00;
        }    
     }
void main()
 {
      DDRD=0x07;                    // PD0 – PD2 as output
      PORTD=0x00;                   // all LEDs off
      DDRC=0x03;                    // PC0 and PC1 as output
      PORTC=0x00;                   // motor stop
      adcinitliz();
       agin:ADCSRA = (1<<ADEN) | (1<<ADSC);      // start conversion
      while(!(ADCSRA & (1<<ADIF)));       // wait for conversion end
      ADCSRA = (1<<ADIF);
      rotate();                     // rotate or stop motor
      PORTC=PORTC | 0b00010000;
      _delay_ms(300);               // wait for 300 ms
      goto agin;                    // do this continuously
 }

Không có nhận xét nào:

Đăng nhận xét

Bài đăng mới nhất

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01

Hướng dẫn sử dụng Cân điện tử Fujihatsu FTC-01 # candientu ,  # fujihatsu ,  # candientufujihatsu  #candientu,  # candientufujhatsu , #fuji...

Bài đăng phổ biến