PDA

View Full Version : Program for Atmeg 16



Mach
03-21-2009, 09:21 PM
I would like to know the program in C++....For a 2 Wheel robot...
what would be the code .......written in C++...........


Plz provide whole program...............

avinash_g
03-22-2009, 06:59 AM
Can the question be more generic than this?

:evil:

What kinda 2 wheel robot ? A line follower or may be a cat follower?

Also small bit MCUs like ATmega16 can't be efficiently program is C++ the more common language is C.

akshay66
03-22-2009, 04:05 PM
Hi
I agree with avinash.You can search on google for programs they'll give you alot additional info.Which can make your robo better.

rahuljin
03-22-2009, 09:04 PM
i do the programming of atmega in c but how it is inefficient in c++ ?

Mach
03-22-2009, 10:15 PM
The microcontroler which I am using is Atmega 16....and ya I am sorry I was worrng it was C.


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

void Wait()
{
char i;

for(i=0;i<100;i++)
_delay_loop_2(0);

}


int main()
{


//Steup port D pin 2,3,4,5 as output.
//87654321
DDRD=0B00011110;

while(1)
{

//clock wise
// 87654321
PORTD=0B00010100;
Wait();

//Anti Clock wise
//87654321
PORTD=0B00001010;
Wait();


//Stop
PORTD=0B00000000;
Wait();

}

return 1;

}



I have tried running this program......... I have tested it on the AVRStodio but line after //Anticlock wise is not executed and the program does not go futher..........


CAN ANYONE TELL ME WEATHER THIS PROGRAM IS WRITE OR WRONG FOR A
2 WHEEL ROBOT TESTING PURPOSE...................

rahuljin
03-22-2009, 11:07 PM
there is a problem in wait() function. the _delay_loop_2, a delay using counter is causing the problem because of the '0' value passed. the '0' causes a very long delay (i dont why, but there should be not delay for 0 value) and the 'for' loop making delay even larger, so remove the for loop and use value between 10-65000.

u can also use _delay_ms() for millisec delays
and _delay_us() for microsec delays.

for the testing for the motor in which direction they are moving, the code is fine. but remote controlled robo, it is not sufficient.
u need input from the remote, then compare the inputs and accordingly move the motors using h-bridge.

avinash_g
03-23-2009, 07:17 AM
Hello,

What frequency the CPU is running?

Try reducing 100 to 20 in for loop

0 is used to pass the value 65536 i.e. 0 causes 65536 delay loop each burning 4 CPU cycles

Mach
03-25-2009, 06:14 PM
Please can anyone make the changes and post the correct
program.....

rahuljin
03-25-2009, 07:11 PM
#include <avr/io.h>
#include <util/delay.h>

void Wait()
{
char i;

for(i=0;i<5;i++)
_delay_loop_2(10);

}


int main()
{


//Steup port D pin 2,3,4,5 as output.
//87654321
DDRD=0B00011110;

while(1)
{

//clock wise
// 87654321
PORTD=0B00010100;
Wait();

//Anti Clock wise
//87654321
PORTD=0B00001010;
Wait();


//Stop
PORTD=0B00000000;
Wait();

}

return 1;

}

Mach
03-28-2009, 11:30 AM
I have runed the above program
It is skiping the clock wise and anticlock wise statements and directly going on to the stop....
what may be the reason....