go_away

Author Topic: $50 robot using atmega16  (Read 3531 times)

0 Members and 1 Guest are viewing this topic.

Offline xaikouTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
$50 robot using atmega16
« on: March 27, 2008, 07:41:26 PM »
So I made the necessary connections that reflect the atmega 8 chip onto the atmega 16 already.  I am using a STK500 board, so I did not build the onboard programmer as the guide said.  My question is based on the changing of the code.  This is what I have tried so far for the SoR_utils.h

//************CONFIGURE PORTS************
{
        DDRA = 0x00;  //configure all A ports for input

   PORTC = 0x00; //make sure pull-up resistors are turned off

   DDRD = 0xFF;  //configure all D ports for output

   DDRB = 0xC7;  //configure B ports 0, 1, 2, 6, 7 for output
}
                                        .                   
                                        .
                                        .
//*********SIMPLIFIED FUNCTIONS**********

void LED_on(void)

   {

   PORT_OFF(PORTB, 0);//turn LED on

   }

void LED_off(void)

   {

   PORT_ON(PORTB, 0);//turn LED off

   }

void servo_left(signed long int speed)

   {

   PORT_ON(PORTD, 0);

   delay_cycles(speed);

   PORT_OFF(PORTD, 0);//keep off

   delay_cycles(200);

   }

void servo_right(signed long int speed)

   {

   PORT_ON(PORTD, 1);

   delay_cycles(speed);      

   PORT_OFF(PORTD, 1);//keep off

   delay_cycles(200);



For the makefile, I changed:

# MCU name

MCU = atmega16

Should I change timer.c to timerx8.c in the makefile?



When I powered everything up, nothing looks working.  The LED is not lit and the servo does not move. But every so often when I power on and off using the switch on the 4.8V pack, a servo twitches.
« Last Edit: March 27, 2008, 07:45:56 PM by xaikou »

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: $50 robot using atmega16
« Reply #1 on: March 28, 2008, 09:55:49 AM »
check the power supply and see if u have configured the right pins in atmega16 as there are 28 i guess in atmega8

and 40 in atmega16
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: $50 robot using atmega16
« Reply #2 on: March 30, 2008, 03:12:03 PM »
You messed up the code! Change:

PORTC = 0x00;
to
PORTA = 0x00;

PORT_ON(PORTB, 0);//turn LED off
to
PORT_ON(PORTB, 1);//turn LED off

PORT_ON(PORTD, 0);
to
PORT_ON(PORTD, 1);

PORT_OFF(PORTD, 1);//keep off
to
PORT_OFF(PORTD, 0);//keep off


And if that doesn't still fix it, get out a multimeter and check that all the pins are doing what you expect.

Quote
But every so often when I power on and off using the switch on the 4.8V pack, a servo twitches.
This means your servos are being powered correctly, but aren't recieving a signal. By turning it on, the servos are just responding to short term electrical noise, thereby twitching.

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: $50 robot using atmega16
« Reply #3 on: March 31, 2008, 01:27:49 PM »
dont u think admin that the servos wont perform as good as it can at 4.8 v than at 6v?
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,657
  • Helpful? 169
    • Society of Robots
Re: $50 robot using atmega16
« Reply #4 on: April 06, 2008, 12:26:16 PM »
In my experience, 6V is the optimal voltge for most servos (but not all).

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: $50 robot using atmega16
« Reply #5 on: April 06, 2008, 12:27:58 PM »
but wont they work at 4.8 v ?? coz there rating is in betn 4.8-6v
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline xaikouTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: $50 robot using atmega16
« Reply #6 on: April 11, 2008, 12:03:15 AM »
So this is the code that I came up with per Admin's response.
Code: [Select]
//*********SIMPLIFIED FUNCTIONS**********
//functions to make coding easier for a beginner
//but could cause port mixup confusion for intermediate users
void LED_on(void)
{
PORT_OFF(PORTB, 0);//turn LED on
}
void LED_off(void)
{
PORT_ON(PORTB, 1);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
//***************************************

Still no go.  Am I supposed to change anything else (setting wise in programming software/code), or any other files? 
Also when I check the pins, I am just checking for 5 volts on the legs used right?

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: $50 robot using atmega16
« Reply #7 on: April 11, 2008, 12:15:57 AM »
did u actually connect the servos to the changed pins , did u see the makefile and changed the mcu name to atmega16 instead of atmega8, did u use the correct name of the programmer in the makefile, did u define the correct speed of ur microcontroller in the makefile???
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline xaikouTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: $50 robot using atmega16
« Reply #8 on: April 11, 2008, 12:22:36 AM »
did u actually connect the servos to the changed pins?
yes

did u see the makefile and changed the mcu name to atmega16 instead of atmega8?
yes

did u use the correct name of the programmer in the makefile?
is this the same question as before?

did u define the correct speed of ur microcontroller in the makefile?
where do I find that info, or what on the data sheet should I look for? Is that refering to this portion of the code:
Code: [Select]
# Processor frequency.
#     This will define a symbol, F_CPU, in all source code files equal to the
#     processor frequency. You can then use this symbol in your source code to
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
#     automatically to create a 32-bit value in your source code.
#     Typical values are:
#         F_CPU =  1000000
#         F_CPU =  1843200
#         F_CPU =  2000000
#         F_CPU =  3686400
#         F_CPU =  4000000
#         F_CPU =  7372800
#         F_CPU =  8000000
#         F_CPU = 11059200
#         F_CPU = 14745600
#         F_CPU = 16000000
#         F_CPU = 18432000
#         F_CPU = 20000000
F_CPU = 3686400

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: $50 robot using atmega16
« Reply #9 on: April 11, 2008, 12:24:36 AM »
yes in the makefile u have to define the correct speed , in urs it is writeen 38.... whatever so is really a crystal of that speed connected to ur mcu ??

if not what kinda crystal is connected??

if nothing is connected then i guess ur cpu is running at a speed of 1000000 so change that in the makefile
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline xaikouTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: $50 robot using atmega16
« Reply #10 on: April 11, 2008, 12:29:11 AM »
actually thats the original makefile that is on this site.  What is a crystal? 

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: $50 robot using atmega16
« Reply #11 on: April 11, 2008, 12:33:38 AM »
 i saw what the admin told ya and he has done a great mistake , from what i realise
So this is the code that I came up with per Admin's response.
Code: [Select]
//*********SIMPLIFIED FUNCTIONS**********
//functions to make coding easier for a beginner
//but could cause port mixup confusion for intermediate users
void LED_on(void)
{
PORT_OFF(PORTB, 0);//turn LED on
}
void LED_off(void)
{
PORT_ON(PORTB, 1);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
//***************************************

Still no go.  Am I supposed to change anything else (setting wise in programming software/code), or any other files? 
Also when I check the pins, I am just checking for 5 volts on the legs used right?
first of all the turn off led and turn on led are messed up interchange the codes , also if u are turning on the 1st pin of portb why do u turn off the 0th pin of portb , this is a mistake turn off the 1st pin of portb instead

2nd

in the left servo code ur turning on the 1st pin of port d and turning off the 0th pin of portd , that doesnt make any sense if u turn on  pin 1 then turn off the same pin why do u turn off another pin???

the same problem is also with servoright function , change these 1st
« Last Edit: April 11, 2008, 12:34:57 AM by superchiku »
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline xaikouTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: $50 robot using atmega16
« Reply #12 on: April 11, 2008, 12:37:12 AM »
Ya I noticed that when I posted.  BUt back to the makefile, where do I find the information to set the F_CPU ?
« Last Edit: April 11, 2008, 12:37:54 AM by xaikou »

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: $50 robot using atmega16
« Reply #13 on: April 11, 2008, 12:40:15 AM »
ur new code should be like this

Code: [Select]
void LED_on(void)
{
PORT_ON(PORTB, 1);//turn LED on
}
void LED_off(void)
{
PORT_OFF(PORTB, 1);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 0);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}

attach the led to pin 1 of port b and the left servo to pin 1 of port d and the right servo to pin0 of port d

and in the makefile change F_CPU to 1000000
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 108
Re: $50 robot using atmega16
« Reply #14 on: April 11, 2008, 12:56:51 PM »
Regarding the LED then Admins code is CORRECT. Check the circuit diagram. One end of the LED is connected to +5v and the other (via resistor) to the port. So you need to set the port low/off in order to make the LED come on, and set the port hi/on to turn the LED off.

Regarding the F_CPU question then there is an issue with Admins original makefile. Although he defines the variable F_CPU as per the previous attachments it is NOT passed to the compiler (ie it has NO effect at all so the fact that you may have it set to the wrong value doesn't matter as its not used)!

So let's fix it all:-

In the makefile then find the bit that says
Code: [Select]
# Place -D or -U options here
CDEFS =

and change it to say
Code: [Select]
# Place -D or -U options here
CDEFS = -D F_CPU=$(F_CPU)
This means that when the compiler is called it defines (hence -D) a variable called 'F_CPU' which has the value that specified previously.

You will now need to make sure that the F_CPU in the makefile is set correctly. Ie for an atmega8 then the default option should be
Code: [Select]
F_CPU =  1000000
#         F_CPU =  1843200
#         F_CPU =  2000000
#         F_CPU =  3686400
#         F_CPU =  4000000
#         F_CPU =  7372800
#    F_CPU =  8000000
#         F_CPU = 11059200
#         F_CPU = 14745600
#         F_CPU = 16000000
#         F_CPU = 18432000
#         F_CPU = 20000000
#     F_CPU = 3686400

Unless you blow the fuse bit (as discussed in the UART upgrade tutorial) in which case it works at 8MHz and the makefile should say
Code: [Select]
#         F_CPU =  1000000
#         F_CPU =  1843200
#         F_CPU =  2000000
#         F_CPU =  3686400
#         F_CPU =  4000000
#         F_CPU =  7372800
   F_CPU =  8000000
#         F_CPU = 11059200
#         F_CPU = 14745600
#         F_CPU = 16000000
#         F_CPU = 18432000
#         F_CPU = 20000000
#     F_CPU = 3686400

NB This is for an atmega8 - so you will need to check what clock rate an atmega16 runs at. I dont have one  :'( but check the atmel website specs if in doubt.

Next you will need to edit the 'global.h' file that Admin created. Since the makefile didn't used to do anything with the F_CPU info then he set it up again in 'global.h'. Now the makefile is correct then you can delete the following lines from 'global.h' since the value of F_CPU is passed in from the makefile.

Code: [Select]
// project/system dependent defines

// CPU clock speed
//#define F_CPU        16000000                // 16MHz processor
//#define F_CPU        14745000                // 14.745MHz processor
//#define F_CPU        8000000                // 8MHz processor
//#define F_CPU        7372800                // 7.37MHz processor
//#define F_CPU        4000000                // 4MHz processor
#define F_CPU        3686400                // 3.69MHz processor

However: what I would suggest is to replace the lines with the following:-
Code: [Select]
#ifndef F_CPU
#error Your makefile doesn't define the processor clock speed in F_CPU
#endif
This means that the compiler will generate an error if you forget to define F_CPU in the makefile, or you use Admins old version that doesn't pass it in.

Hope this helps.



Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline airman00

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,653
  • Helpful? 21
  • narobo.com
Re: $50 robot using atmega16
« Reply #15 on: April 11, 2008, 01:00:14 PM »
but wont they work at 4.8 v ?? coz there rating is in betn 4.8-6v


they will work at 4.8 V

since there is a motor in a servo the lower voltage 4.8V will make teh servo slower than at 6V
Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

 


Get Your Ad Here