Author Topic: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU  (Read 16618 times)

0 Members and 1 Guest are viewing this topic.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #30 on: January 19, 2008, 10:16:40 AM »
nevermind about what I said earlier about the fuses, having a 0 makes it divide by 8 . . . oops . . .

anyway, if you have the serial dongle, you can't use AVR Studio to do the fuses . . . I'm guessing you are using ponyprog, right?

try the delay code yet?

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #31 on: January 19, 2008, 10:35:23 AM »
Quote
-----i am using a 16mhz external crystal with an atmega168

-------built like the $50 Robot

fuse frequency settings= i got this from sparkfun

----avrdude -p m168 -P com1 -c ponyser -U lfuse:w:0xE6:m
i am using AVRlib?

you're using avrlibc? are you sure? AVRlibc is a small C library comparable to glibc. glibc is used in full-blown Linux systems mainly while AVRlibc is designed specifically for use with the Atmel AVR series of MCUs.

if you are using AVRlibc, your code and/or Makefile must have F_CPU defined. verify that all values match before recompiling.

whose code are you using? if you're using the $50 Robot code, the F_CPU definitions are in a file named global.h. find the file and select the F_CPU value that matches your setup.
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline rox2007Topic starter

  • Full Member
  • ***
  • Posts: 95
  • Helpful? 0
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #32 on: January 19, 2008, 10:57:47 AM »
i am using avrlib by procyon not avrlibc. FCPU is defined in the make file as 16mhz. maybe i did not set the fuse bits right. does anyone now how to set the fuse bits for an external 16mhz clock for an atmega168 with pony prog. i am using my own code based on the $50 robot but modified extensively
« Last Edit: January 19, 2008, 10:59:22 AM by rox2007 »

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #33 on: January 19, 2008, 11:24:35 AM »
i also use procyon's libraries. procyon also uses F_CPU. it can also be defined in the Makefile or in the globals.h file.

make sure first that the correct F_CPU is not commented out. from one of my globals.h file:

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

// CPU clock speed
//#define F_CPU        20000000                         // 20MHz processor
//#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
#define CYCLES_PER_US ((F_CPU+500000)/1000000)  // cpu cycles per microsecond

yes you can see F_CPU as 16MHz but it is not used because it is commented out using C++ style comments. to enable the correct F_CPU value just remove the "//" in front of the definition.

Code: [Select]
#define F_CPU        16000000                         // 16MHz processor
//#define F_CPU        14745000                         // 14.745MHz processor
//#define F_CPU        8000000                            // 8MHz processor

how did you connect your oscillator to the MCU? did you precisely follow the requirements/recommendations on page 31 and 32 of the ATmega168 data sheet? personally, the fuse settings that you are using seems to be correct based on the information that you have provided so far.
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline rox2007Topic starter

  • Full Member
  • ***
  • Posts: 95
  • Helpful? 0
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #34 on: January 19, 2008, 11:34:01 AM »
i did connect the oscillator right. i used two capacitors (22pf) connected to the oscillator to xtal pins.

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #35 on: January 19, 2008, 12:03:44 PM »
i'am, at this point, all out of any constructive suggestions. the only thing i can suggest is to go and double, maybe even triple check your settings and setup.
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline rox2007Topic starter

  • Full Member
  • ***
  • Posts: 95
  • Helpful? 0
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #36 on: January 19, 2008, 12:27:12 PM »
ok, thanks for your help

Offline rox2007Topic starter

  • Full Member
  • ***
  • Posts: 95
  • Helpful? 0
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #37 on: January 19, 2008, 10:05:17 PM »
solved it with PWM wooohooo.

Code: [Select]
// Servo test program
// Put your name here
// Put the date here
//----- Include Files ---------------------------------------------------------
#include <avr/io.h>
// include I/O definitions (port names, pin names, etc)
#include <avr/signal.h>
// include "signal" names (interrupt names)
#include <avr/interrupt.h>
// include interrupt support
#include "global.h"
// include our global settings
#include "timer.h"
// include timer function library (timing, PWM, etc)
#include "pulse.h"
// include pulse output support
#include "servo.h"
#include "iocompat.h" 
int i;
// include RC servo support
//----- Function Declarations--------------------------------------------------
void init(void);
//----- Begin Code ------------------------------------------------------------
int main(void)
{
init();
// initialize everything
while(1)
{
for (i = 0; i < 255; i++)
{
servoSetPosition(0, i);
PORTD = 0x00;
timerPause(3000);
//servoSetPosition(0,0);
PORTD = 0xff;
timerPause(3000);
}
}
return 0;
}
// end main()
void init(void)
{
// initialize our libraries
timerInit();
// initialize the timer system
servoInit();
// initialize the servo system
// Setup I/O
DDRC = 0;
// Set PORTA to all inputs
PORTC = 0xff;
// Turn on pullup resistors
DDRD = 0xff; // Set PORTD to all outputs
PORTD = 0xff;
// Set PORTD outputs to high
}
// end init()

Offline rox2007Topic starter

  • Full Member
  • ***
  • Posts: 95
  • Helpful? 0
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #38 on: January 19, 2008, 10:17:00 PM »
the code above works according to avrlib
« Last Edit: January 19, 2008, 10:40:16 PM by rox2007 »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Please, how do i control my servo with an ATMEGA 168, 16Mhz MCU
« Reply #39 on: January 26, 2008, 08:14:12 PM »
I finally wrote that tutorial on calculating delay_cycles . . .
http://www.societyofrobots.com/microcontroller_time_cycles.shtml

Offline GUmeR

  • Jr. Member
  • **
  • Posts: 24
  • Helpful? 0

 


Get Your Ad Here

data_list