SERVO

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

At First, please don't get angry on me, i know it has been discussed a number of times here..but why does it work for everyone and not me. 

my CODE :

 

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

int main()
{
    DDRD=0xff;
    TCCR1A|=(1<<WGM11)|(1<<COM1A1);                                      //wgm's are for fast pwm select and cs10 for prescaling and com1a1 for non-inverting type
    TCCR1B|=(1<<WGM12)|(1<<WGM13)|(1<<CS10);
    ICR1=19999;
    while(1)
    {
     OCR1A=800;
     _delay_ms(1000);
     OCR1A=1500;
     _delay_ms(1000);
     OCR1A=2200;
     _delay_ms(1000);
      
    }
}

 

when i simulated in PROTEUS it worked as required(moving back and forth) but when i run in hardware it doesn't come back just move from 0-180 remain there (stops as if my code was intended to stop)... what could have i done wrong... checked clock.. and i use servo SG 5010

Last Edited: Fri. Jul 3, 2015 - 08:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Of course he didn't. You expect too much from this guy.

 

Ross McKenzie ValuSoft Melbourne Australia

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

badri,

 

You made an error and posted in the wrong forum. I'll move this to a better place. Can you tell me which model of AVR you are trying to use?

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

atmega 16

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

I think Proteus is right (on this occasion), that code SHOULD work. If it doesn't I would suspect the hardware.

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

But, it does work absolutely when given hardware PWM.

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

I don't understand your last comment. If this works then what is the question?

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

but i have to control 12 servos all together.. so, i want to generate software PWM and control them.

Last Edited: Fri. Jul 3, 2015 - 09:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But the code you showed in the first post is to do hardware PWM on th OC1A pin? You said "when i simulated in PROTEUS it worked as required(moving back and forth) but when i run in hardware it doesn't come back just move from 0-180 remain there". So are you saying it works now?

 

So what has any of the thread so far got to do with software PWM which is an entirely different thing?

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

i don't understand  the problem after reading the  thread...can you please elaborate

computers are good at following instruction

but not at reading your mind.

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

I think it is better once you go through what is software PWM and hardware PWM 

computers are good at following instruction

but not at reading your mind.

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

Hmm.

 

The strategy for working 12 servos?

 

Keep an array of 12 numbers indicating the positions of each of the servos. Then make a variable that counts 0 to 11. Mark both of these volatile.

 

Use a timer to give you an interrupt. On each timer interrupt, look at the counting variable, pick the position from the array, set the pins for the servos low, set the pin for the selected servo high, set the timer according to the servo's entry in the array and increment the counter. Now, when the timer interrupt comes again, it's time to stop this servo's pulse. The array and counter tell your ISR which pin to set for how long and Bob's your uncle. Your timer and ISR are now taking care of driving the servos and your main program can position the servos by setting the elements in the array.

 

You might need to account for the rest of the 20ms down time after looping through all 12 servos, or you might find the down time is a little long. It still should work as servos aren't very critical on the exact frequency.

 

274,207,281-1 The largest known Mersenne Prime

Measure twice, cry, go back to the hardware store