DC Motor Control with Microcontroller ATmega8535

  • Sabtu, 31 Juli 2010
  • Posted by Learn Electronic

At mega 8535 microcontroller can use control dc motor that is on pin d where there have PWM control. DC motor can rotate because of the induction when the motor is connected to the DC voltage source. DC motor control with microcontroller if it is done more easily than without the microcontroller. We can change the direction of rotation of DC motor directly by changing the polarity of the voltage source. To change the speed of DC motors can be done by changing the size of a fox-voltage source. Control with a microcontroller as well as principled, but with an automated system. We do not have to change the cable from the motor to the battery if you want to change the direction of rotation, we just provide the logic 0 or 1 to the microcontroller is performed on the program in the microcontroller. To change the velocity is also easier because we simply use the existing PWM feature on the microcontroller. Maybe there are still many who do not know what PWM

PWM (Pulse Width Modulation) is a technique to get the effect of the analog signal from a digital signal to falter. PWM can be generated using only digital i / o which functioned as an output.


 In the example above the waves, the comparison between high signal (1) and low signal (0th) is the same. Above the wave is said to have 50% duty cycle. Duty cycle is the ratio between the width of high signal (1) the overall width of the cycle (cycle). If the PWM wave amplitude is 5 volts, then the average stress (as if to analog) that we get is 2.5 volts. Here's an example of wave PWM with duty cycle 10%, if the amplitude of wave 5 volts then we will get the average analog voltage 0.5 volts.


In  ATMEGA8535 have two way control PWM, the PWM can be generated from the first port input / output is enabled as output. The second is to utilize the facilities of the function of the PWM timer / counter which has been provided. With this facility, the timing of the process of high / low digital signal will not disrupt the sequence of other programs being executed by the processor. In addition, by using this facility to enter how many servings we lived on and off time period on a wave PWM registers. OCR1A, OCR1B and OCR2 is register a place set PWM duty cycle.
 
The following schematic DC Motor Control with Microcontroller ATmega8535 of my own, please trace itself, or if you want to please make my request in the comments section below ini. Click image to enlarge......


I separate the circuit into three main sections so that it is easy to understand and analyze our series, namely the minimum system, motor drivers, and motors (as a major expense). The minimum system the same as in my previous posting, the next part of the driver. in fact we can directly connect the microcontroller to the motor without a driver, this can be done if the motor that we use a small motor. we need a big motor for the drivers, these drivers can be made also with the MOSFET (often called the H-Bridge), we can use a more practical ie L298 driver ic, ni ijenis drivers able to control two motorcycles and also features the legs to control the PWM .
For our experiment we only use a single dc motor alone, here are photos from the series that I created.



For the program you can see below. Use the AVR Studio software (after AVR studio also install WinAVR is installed so that it AVRstudio supports the C language, because the standard AVRstudio using assembly language). To download your program can use the USB downloader downloader atapun series which has also been my post. The following program


#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

#define    DDR_motor    DDRD    //DDR untuk Motor
#define    PORT_motor    PORTD    //PORT untuk Motor

#define en_ka         5        // Enable L298 untuk motor kanan
#define dirA_ka     2        // Direction A untuk motor kanan
#define dirB_ka     3        // Direction B untuk motor kanan
#define pwm_kanan    OCR1A

void delay_ms(int ms)
{for (int i=0;i<ms;i++){_delay_ms(1);}}

void maju(unsigned int pwm)
{
PORT_motor |=(1<<dirA_ka);        //motor maju
PORT_motor &=~(1<<dirB_ka);
pwm_kanan=pwm;                    //pwm motor kanan
}

void mundur(unsigned int pwm)
{
PORT_motor |=(1<<dirB_ka);        //motor maju
PORT_motor &=~(1<<dirA_ka);
pwm_kanan=pwm;                    //pwm motor kanan
}


int main (void)
{

DDR_motor=0xFF;
PORT_motor=0x00;


    TCCR1A= (1<<WGM11)|(1<<WGM10)|
            (1<<COM1A1)|(0<<COM1A0)|
            (1<<COM1B1)|(0<<COM1B0);
           
    TCCR1B= (0<<WGM13)|(1<<WGM12)|
            (0<<CS12)|(0<<CS11)|(1<<CS10);
    TCNT1=0x0000;
    OCR1A=0;
    OCR1B=0;
    sei( );


while(1)
{
mundur(1000);
delay_ms(5000);
maju(700);
delay_ms(3000);

}
}

see the main program, with a PWM motor will resign in 1000 over 5000ms (5 seconds) and then will forward denan PWM motor 700 for 3000ms (3 seconds). and the program will be repeated a maximum of motor-ulang.Kecepatan happen if we gave in 1000 and the minimum PWM value (motor stopped) if the PWM value of 0, see the main program, which is backward (1000) that mean the motor will spin backwards at top speed because the PWM is 1000

0 komentar:

Posting Komentar