Attiny85 servo control issue

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

Attiny85 servo control -servo not holding position

 

1)To control the servo i have used software servo library ,sweep program is running fine 

2)My servo is rotating from 0 to 180 and a delay of 2sec and then again returns to 0  ,so thats working fine

3)But the problem starts from here, when it has stopped at 180 degree it should hold its position at 180 degree ,but if we apply small amount of force then it just slides towards 0 degree i.e its not holding its position at 180degree

4)when im using arduino uno for the same ...servo is holding its position.

5)I have attached the software servo library below

 

**************code***********

#include <SoftwareServo.h> 
SoftwareServo myservo;                      // creates name “my servo” as object to control a servo 
int pos = 0;                                // variable to store the servo position 
 
void setup() 

  myservo.attach(0);                        // attaches the servo on pin 0 to the servo object 

 
void loop() 

  for(pos = 0; pos <= 180; pos += 1)        // goes from 0 degrees to 180 degrees 
  {                                         // in steps of 1 degree 
    myservo.write(pos);                     // tell servo to go to position in variable 'pos' 
    delay(15);                              // waits 15 milliseconds for the servo to reach the position
    SoftwareServo::refresh();               // required by SoftwareServo Library to sweep correctly
  }           
  delay (20);                               // required by SoftwareServo Library to sweep correctly
  for(pos = 180; pos>=0; pos-=1)            // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);                     // tell servo to go to position in variable 'pos' 
    delay(15);                              // waits 15 milliseconds for the servo to reach the position 
    SoftwareServo::refresh();               // required by SoftwareServo Library to sweep correctly
  }
  delay(20);                                // required by SoftwareServo Library to sweep correctly
}

 

*****************************************

 

so pls help me how to control servo using Attiny85

 

* Welcome to AVRFreaks. This is about an Arduino application, so I have moved it to the Arduino forum. Moderator. *

 

 

Attachment(s): 

Last Edited: Tue. Apr 2, 2019 - 05:31 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are you sure you don't have an electrical problem?  Is there plenty of power to run the servo?  Under load it will draw a lot of current.

 

Did you take a look at your PWM waveforms?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

no electrical problem bcoz same servo( Tower Pro SG90 miniServo ) and same power supply(computer SMPS) is working fine with arduino UNO

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

godson.dabre7@gmail.com wrote:

no electrical problem bcoz same servo( Tower Pro SG90 miniServo ) and same power supply(computer SMPS) is working fine with arduino UNO

 

What PCB is your tiny85 on?

 

Can you post a photo of your hardware setup?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

I have mounted the Attiny85 on the breadboard and the connections are quite simple.

 

i have attached the diagram below

Attachment(s): 

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

godson.dabre7@gmail.com wrote:

I have mounted the Attiny85 on the breadboard and the connections are quite simple.

 

No decoupling capacitors?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

godson.dabre7@gmail.com wrote:
but if we apply small amount of force then it just slides towards 0 degree i.e its not holding its position at 180degree
Two things:

 

1) your code doesn't actually say to "hold position"? You sweep (in the first for() loop) from 0 to 180 then almost immediately you sweep back from 180 to 0. Don't you want some loop where you do repeated refresh()s without updating pos() once you have got to 180?

 

2) Servos require a 1..2ms pulse every 20ms to tell them where to position too. While you can go longer than 20ms between updates what you will find is that they only hold the position "weakly" and any force applied (such as the wind over an aileron) will easliy move them if they are not being updated regularly enough. Your description of "weakly" sound an awful lot like a servo that is not receiving a control pulse at least every 20ms.

 

I have to say that all those delay(15)s in there look kind of odd to me - I have no idea how this library works but are they the thing that's supposed to be doing the 15..20ms frame time?

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

I've now read the code and I see what it is doing. So I begin to wonder about your whole millis() and delay() timing. Could it be that on the t85 (compared to Uno) they are actually running much slower than you think?

 

Try using delay() to simply flash an LED once a second then time it and see if it really does flash at that rate. Run the same sketch on both Uno and t85. Do both perform the same?

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

godson.dabre7@gmail.com wrote:

I have mounted the Attiny85 on the breadboard and the connections are quite simple.

 

i have attached the diagram below

 

Beside the decoupling capacitors as Brian said "100nF", please have a look at:

 

http://ww1.microchip.com/downloa...

 

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

I missed the schematic - so there's no crystal? Arduino usually expect to be running at 16MHz. If the tiny 85 is not running at 16MHz is the Arduino library that is providing delay() and millis() aware of this? 

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

Im bit confused.!!!can anyone help me with the code to hold the position of servo continuously at one position e.g at 90degree for Attiny85 

Im running the Attiny at 8MHz

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

The library you are using is dependent on delay() and mills() working correctly. Is the code that is providing those functions for the tiny85 aware that it is running at just 8Mhz ? In fact how sure are you that it is even 8Mhz. By default the chip will actually run at 1MHz not 8MHz.

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

i have burnt the bootloader for 8Mhz using arduino ide 

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

Ah, so that cleared CKDIV8 did it?

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

Okay, try to think about what people said:

 

- Are yo really running at 20Mhz ? how can you prove this ?

 

For this check the answer from the guys above (Brian & Clawson).

 

- Your schematics shows some errors as you need a decoupling capacitors, placed as close as possible to the mcu. refer to Brian answer and to the datasheet that I posted to you.

 

- The delay_ms is depending on your frequency and not on the "#define F_CPU", so if you clock setting is wrong then you will get wrong delays

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

so what should i do next ...to resolve the issue?

1)decoupling cap.

2)??????????

 

Last Edited: Tue. Apr 2, 2019 - 09:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

godson.dabre7@gmail.com wrote:

so what should i do next ...to resolve the issue?

1)decoupling cap.

2)??????????

 

Read the datasheet.

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

If it were me and I had something that worked well on a 16MHz Uno that does not work so well on an 8MHz tiny85 I'd be looking to see what i could do to make the tiny85 behave more like the Uno - such as adding a 16Mhz cystal and configuring the chip to use that as a clock source.

 

PS a rather radical alternative is to forget the whole Arduino / Servo library thing all together. Just getting a standalone tiny85 (at any speed) to drive a single servo is actually quite trivial - about 10 lines of C.

 

PPS for example...  https://hackaday.com/2011/09/25/attiny-hacks-attiny4585-servo-library/

 

PPPS oh, I see - that is a "workalike" based on the same code!! Small world.

Last Edited: Tue. Apr 2, 2019 - 09:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bro clawson i have still not understood ....whats causing the problem ..pls help 

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

The code in your first post does not match the

description you gave.  The servo is told to first

sweep from 0 to 180, and then immediately

start heading back to zero.  There is no hold

for 2 seconds.  If this is the actual code, then

it's the Uno which is showing strange behavior.

 

--Mike

 

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

Did you actually scope your PWM waves ?--this is a requirement!  Why mess around when it is a quick & easy check?  That will tell the story very easily.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

godson.dabre7@gmail.com wrote:

bro clawson i have still not understood ....whats causing the problem ..pls help 

 

Is this your first project ? if yes, then there are some good tutorials here in this forum, i suggest you to take a look.

 

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

Hello,

 

What about the Servo8bit library?  see: http://www.cunningturtle.com/att...

 

If you've found the solution, please share with us.