Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need atmega 16 c code

Status
Not open for further replies.

inamullah

Newbie level 2
Joined
Apr 1, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,303
Can any one help me by giving code for dc motor speed control
 

sherazi

Banned
Joined
Feb 15, 2010
Messages
388
Helped
61
Reputation
126
Reaction score
61
Trophy points
1,318
Location
Muscat, Oman, Oman
Activity points
0
code is always dependent on the hardware used. so how can we give you code ... further more you should first have some reading and searching on the forum about speed control , then you can ask what you didn't understand or even you can ask for help in coding but at-least you should have done something!

explain your needs, your motor etc
 
Last edited:

inamullah

Newbie level 2
Joined
Apr 1, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,303
i want to make line follower robot,i have control speed of single motor.i want to know what changes needed to control two motors and which snesor i should use IR, LDR or photodiode.
#include<avr/io.h>
#include<util/delay.h>



#define s5 200 // s for speed
#define s4 150
#define s3 100
#define s2 50
#define s1 20
#define s0 0

#define forward 0b00000010
#define reverse 0b00000001
#define right 0b00011010
#define left 0b00010110
#define stop 0b00001111

void move(char speed,char direc)
{

OCR0=speed;

PORTA=direc;
}



void main()
{
///////////I/O Ports setup///////////////

DDRC=0b00000000; //PORTC for PORTC input
PORTC=0x00; //Internal pullup enable

DDRA=0xff; //PA0 & PA1 for right motor control
//PORTA=0x00; //PA2 & PA3 for left motor direction

///////////Setting up Timers/////////////

TCCR0 = 0b01101100; //Fast PWM, Output at OC0


/////////// Variable declarations ///////
char prev=0x00;

/////////// Mian Loop ///////////////////
while(1)
{



if(1)
{
if((PINC & 0xf0)== 0b00000000)
{
move(s5,forward);
}
else if((PINC & 0xf0 )== 0b00010000 )
{
move(s5,left);
}
else if((PINC & 0xf0 )== 0b00100000)
{
move(s3,left);
}
else if((PINC & 0xf0) == 0b00110000)
{
move(s3,left);
}
else if((PINC& 0xf0 )== 0b01000000)
{
move(s3,right);
}
else if((PINC & 0xf0) == 0b01010000)
{
move(s3,right);
}
else if((PINC & 0xf0 )== 0b01100000)
{
move(s3,reverse);
_delay_ms(2000);
}
else if((PINC & 0xf0 )== 0b01110000)
{
move(s3,reverse);
_delay_ms(2000);
}
else if((PINC & 0xf0 )== 0b10000000)
{
move(s5,right);
}
else if((PINC & 0xf0 )== 0b10010000)
{
move(s3,forward);
}
else if((PINC & 0xf0 )== 0b10100000)
{
move(s3,right);
}
else if((PINC & 0xf0)== 0b10110000)
{
move(s3,left);
}
else if((PINC & 0xf0)== 0b11000000)
{
move(s3,right);
}
else if((PINC & 0xf0)== 0b11010000)
{
move(s3,right);
}
else if((PINC & 0xf0)== 0b11100000)
{
move(s3,right);
}
else if((PINC & 0xf0)== 0b11110000)
{
move(s5,reverse);
_delay_ms(3000);
}

}


}
}
thanx for reply.......
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top