controlling 6 servos using atmega128a

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello all i'm trying to control 6 servos "50hz" by using all the o/p channels of atmega128a i read the data sheet and here is the code but it doesn't work can anyone tell me what i'm missing in the servo_init function and thanks in advance

 

void servo_init(void)
{
    DDRB|=(1<<PB5)|(1<<PB6)|(1<<PB7); //making OC1A, OC1B, OC1C as o/p
    DDRB|=(1<<PE3)|(1<<PE4)|(1<<PE5); //making OC3A, OC3B, OC3C as o/p

    TCNT1=0;
    ICR1=4999;
    TCNT3=0;
    ICR3=4999;
    TCCR1A=(1<<COM1A1)|(1<<COM1B1)|(1<<COM1C1)|(1<<WGM11);
    TCCR3A=(1<<COM3A1)|(1<<COM3B1)|(1<<COM3C1)|(1<<WGM11);
    TCCR1B=(1<<WGM13)|(1<<WGM12)|(1<<CS11)|(1<<CS10);
    TCCR3B=(1<<WGM33)|(1<<WGM32)|(1<<CS31)|(1<<CS30);
}

void servo_write(unsigned char degree)
{
    switch(degree)
    {case 0:
    OCR1A = 65;    /* Set servo shaft at -90° position 'OCR=output compare register */
    
        break;
    case 45:
    OCR1A = 120;
    break;
    case 90:
    OCR1A = 175;    /* Set servo shaft at 0° position */
    
    break;
    case 180:
    OCR1A = 300;    /* Set servo at +90° position */
    
    break;
    default:
    //Default code
    break;}
}

Last Edited: Sun. Apr 15, 2018 - 06:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you remembered to disable the M103 compatibility mode fuse that is the default for the M128?

 

Jim

 

Mission: Improving the readiness of hams world wide : flinthillsradioinc.com

Interests: Ham Radio, Solar power, futures & currency trading - whats yours?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no , is that necessary ??

also i'm using the uart without disabling M103 compatibility mode fuse and it works fine

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amrbadr wrote:
s that necessary

Read the DS and see if you need any of the resources disabled by the M103 fuse.  If so, yes it is necessary.

 

Jim

Mission: Improving the readiness of hams world wide : flinthillsradioinc.com

Interests: Ham Radio, Solar power, futures & currency trading - whats yours?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

maybe that's why eclipse doesn't get the registers and giving errors ??

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See Tip #1 for how to embed your image in the post - where we can see it

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

maybe that's why eclipse doesn't get the registers and giving errors ??

Yes, M103 has no Timer3. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm intrigued, how could Eclipse know that to underline refs to xxx3 in red ?

 

Did you actually tell Eclipse this was a project being built for atmega103 instead?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
how could Eclipse know that

There would have to be a Project setting somewhere that said "M103 mode only" - and excluded the definitions that are not available in "M103 mode"

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amrbadr wrote:
eclipse doesn't get the registers

Is it just Eclipse - or are you getting actual build errors?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm guessing the "32 errors" shown in the picture suggest these are real errors, not just source browsing errors. As iom128.h has:

D:\atmel_avr\avr8-gnu-toolchain\avr\include\avr>grep TCCR iom128.h
#define TCCR2     _SFR_IO8(0x25)
#define TCCR1B    _SFR_IO8(0x2E)
#define TCCR1A    _SFR_IO8(0x2F)
#define TCCR0     _SFR_IO8(0x33)
#define TCCR1C    _SFR_MEM8(0x7A)
#define TCCR3B    _SFR_MEM8(0x8A)
#define TCCR3A    _SFR_MEM8(0x8B)
#define TCCR3C    _SFR_MEM8(0x8C)

then I'm guessing the build system is possibly using iom103.h:

D:\atmel_avr\avr8-gnu-toolchain\avr\include\avr>grep TCCR iom103.h
#define TCCR2   _SFR_IO8(0x25)
#define TCCR1B  _SFR_IO8(0x2E)
#define TCCR1A  _SFR_IO8(0x2F)
#define TCCR0   _SFR_IO8(0x33)

but that would only happen if the project is set to "mega103" rather than "mega128" so that -mmcu=atmega103 is being passed

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I'm guessing the "32 errors" shown in the picture suggest these are real errors, not just source browsing errors.

No - browsing errors do get included in that list.

 

So it is possible to have that list showing errors, and yet the build succeeds!

 

But we can't tell from the images shown whether that does apply here.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

i've changed the target hardware to M103 then M128 again and the errors are gone

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You didn't answer the question: were they actual build errors, or just the Eclipse browser complaining ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No it's look like eclipse just complaining but servos on OCR1A ,OCR1B ,OCR1C are working well

but those on OCR3A ,OCR3B ,OCR3C are not is there is any thing i'm missing in servo_init() function ???

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is Eclipse smart enough to detect the 103 compatibility fuse status and provide different -mmcu= switches?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

amrbadr wrote:
No it's look like eclipse just complaining

This is easy to confirm: either the build works, or it doesn't!

 

If the build works - then it is just the Eclipse editor/browser complaining.

 

Otherwise, the build fails - with actual compiler errors for these symbols

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

westfw wrote:
Is Eclipse smart enough to detect the 103 compatibility fuse status

That would mean that it would have to actually query the hardware ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
   DDRB|=(1<<PE3)|(1<<PE4)|(1<<PE5); //making OC3A, OC3B, OC3C as o/p

DDRE not DDRB.

/Lars