Aaron's Homepage Forum
Aaron's Homepage Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Electronics
 Basic Electronics
 Problems about Controlling DC motor
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

milk1995
New Member

3 Posts

Posted - Aug 23 2017 :  04:16:36 AM  Show Profile  Reply with Quote
Greetings~
I am confusing about controlling DC motor by L298N. My program is as following:
#include <reg51.h>
#define uchar unsigned char 
#define uint unsigned int
sbit ENA=P1^2;
sbit IN1=P1^3;
sbit IN2=P1^4;
sbit ENB=P1^5;
sbit IN3=P1^6;
sbit IN4=P1^7;

uint MA=0;  
uint speedA=50;
int flag=0;

void timeinit()
{
    TMOD=0x01;
    TH0=(65536-10000)/256;
    TL0=(65536-10000)%256;
    EA=1;
    ET0=1;
    TR0=1;
}

void Ques1()
{
    switch(flag/10)
    {
        case 0: TR0=0;
                        if(MA<speedA)
                        {
                                ENA=1;ENB=1;
                                IN1=1;IN2=0;
                                IN3=0;IN4=1;
                        }
                        else
                        {
                            if(speedA<=MA<100) 
                            {
                                    ENA=0;
                                    ENB=0;
                            }
                            else   
                            {
                                    MA=0;   
                                    flag++;                                                                     
                            }                           
                        }
                        TR0=1;
                        break;
        case 1: TR0=0;
                        if(MA<speedA)
                        {
                                ENA=1;ENB=1;
                                IN1=0;IN2=1;
                                IN3=1;IN4=0;
                        }
                        else
                        {
                            if(speedA<=MA<100) 
                            {
                                    ENA=0;
                                    ENB=0;  
                            }
                            else
                            {
                                    MA=0;   
                                    flag++;                             
                            }   
                        }
                      TR0=1;
                        break;
        default : flag=0;
                            break;
    }
}

void time0() interrupt 1
{
    TH0=(65536-10000)/256;
    TL0=(65536-10000)%256;
    MA++;   
}

void main()
{   
    timeinit();
    while(1)
    {
        Ques1();
    }
}
This is the datasheet of L298N: http://www.kynix.com/uploadfiles/pdf9675/L298N.pdf .
Why can’t this program control positive and negative rotation of motor at the same time. Now my question is the motor controlled by IN1 and IN2 work after pressing RESET,and the motor controlled by IN3 and IN4 will stop rotating after 5 seconds. Why? ? #65311;
Your help will be appreciated!

Aaron Cake
Administrator

Canada
6717 Posts

Posted - Aug 24 2017 :  09:03:48 AM  Show Profile  Visit Aaron Cake's Homepage  Send Aaron Cake an ICQ Message  Send Aaron Cake a Yahoo! Message  Reply with Quote
What microcontroller is this for?

You can't rotate a motor positive and negative at the same time. That would just lock the shaft.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Aaron's Homepage Forum © 1995-2020 AARONCAKE.NET Go To Top Of Page
This page was generated in 0.06 seconds. Snitz Forums 2000