Hi, I am trying to get cunningturtles servo8bit library running on an attiny85. I have tried to tackle this problem years ago and given up with no answer and here i am again road blocked at the same problem - the servo jitter.
See video below - this much jitter won't work for this project.
See code below, not much to go wrong. 8Mhz or 1Mhz fuses doesn't seem to change behavior.
Consistent across 3 different servos
I actually still have a sketch I wrote years ago that bit banged a PWM signal using timer interrupts and it produces the exact same jitter on all of the servos. I must be missing something simple?
#include "Servo8Bit.h"
int main()
{
Servo8Bit myServo; //create a servo object.
//a maximum of five servo objects can be created
myServo.attach(1); //attach the servo to pin PB1
while (1) {
myServo.write(100);
}
}
A wiring diagram. Code works. does not work. I suspect the library. It has a copy/paste typo that causes me to not trust it.
If you are not using the IDE, why use a library?
Is this "cool?"
Try this uncool sketch...
int servoPin = PB1;
#define angle000 450 // this value is specific to this servo for 0 degrees
#define angle180 2450 // this value is specific to this servo for 180 degrees
void setup() {
pinMode(servoPin, OUTPUT);
}
void loop() {
goto000(servoPin);
goto180(servoPin);
}
void goto000(int servo) {
digitalWrite(servo, HIGH);
delayMicroseconds(angle000);
digitalWrite(servo, LOW);
delayMicroseconds(20000 - angle000);
delay(1000);
}
void goto180(int servo) {
digitalWrite(servo, HIGH);
delayMicroseconds(angle180);
digitalWrite(servo, LOW);
delayMicroseconds(20000 - angle180);
delay(1000);
}
Nothing cool about any of my code I can assure you..! Elegance of a bush pig.
I have tried your sketch, it swings the servo nicely, and if I comment out one of the swings it holds nicely in position. But I can't have delays in my sketch.
The circuit is below. For the sake of eliminating power issues I am powering the servo from 2 cells in a dewalt battery, grounds bonded 7vdc, but the original sketch produced same results with this setup.
I have also tried pulling the attiny85 after programming and putting into a second circuit identical, but without the Uno attached in programming configuration like this, no changes.
This was the original project below, for some context. I was fortunate enough that the servos only wanted two rounds of PWM and then they would chase that position and hold it without signal. The sketch was full of short functions with delays that just fired two pulses, but I soon wore the servos out swinging that heavy lid and all replacements I've found don't share this behavior. https://youtu.be/xDmV8Vz2OVU?si=Z_Y3sY2twR6MlSs4
This revisit was in hopes to learn the correct way to do it without delays, and understand it better for learnings sake.
I always saw a little jitter on Attiny85 when using servo's, due to the internal oscillator that is just not stable as a crystal oscillator would be. However I just tested this servo8bit library and I am surprised how well it works on my Attiny85. Even with a digital servo.
I am using a 2S lipo with a 5V 5A switching BEC as powersource.
With my servopulse analyzer I only see a jitter of one or two microseconds, which is the best I ever saw on a Attiny85. Normally I grab a modern series Attiny (eg Attiny412) when I drive servo's as they have a much better internal oscillator.
I'm still getting jitter with a load on the servos yes.
My test with your sketch @hmeijdam is still causing jitter. Do I just scratch this up to the limitations of the internal oscillator at this point?
I tried with a second micro servo in parallel, it is hard to see in the video but its jitters do mimic that of the larger digital servo, so for whatever reason it is they are being commanded to jitter.
Thanks for taking the time to set that up that is hugely helpful...!
While I have servo's that don't mind high voltage, I have some servo's (e.g. HXT900) that don't like more than 6 volts or they may start to jitter by themselves. Also the Attiny85 is rated up to 5.5V
If you are feeding 7V, I recommend to lover that to a stable 5V, with a few amps capacity to eliminate power problems.
That was just a test, I powered the servo off its own 7v source to eliminate voltage (Arduino still powered by USB, and it's a spektrum HV servo up to 9v rating from memory) but in that video it is running off the arduinos 5v rail.