Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Servo Library support for x61, x5, and other unloved 'tinies #85

Closed
AtomicCactus opened this issue Oct 12, 2016 · 9 comments
Closed

Servo Library support for x61, x5, and other unloved 'tinies #85

AtomicCactus opened this issue Oct 12, 2016 · 9 comments

Comments

@AtomicCactus
Copy link

I've put together a really basic interrupt driven servo library that works fairly okay on ATTinyx61 series. It uses Timer1 to control up to 8 servos. Perhaps this could be added to the AVR libraries since there currently is only a library for ATTiny1634? Or even better if it could be merged to create a more universal library. This may, with minor modifications, work on similar AVR 8-bit controllers.

https://github.com/AtomicCactus/Servo_x61

@AtomicCactus AtomicCactus changed the title ATTinyx61 interrupt driven servo library (8 bit) ATTiny x61 interrupt driven servo library (8 bit) Oct 12, 2016
@SpenceKonde
Copy link
Owner

SpenceKonde commented Oct 12, 2016

I think the commit comment is confusing you. Originally I didn't have a servo library included at all - "just use the normal one" - but that library lacked #ifdefs to know to use TIFR not TIFR1, so I added a check for that and put it in.

It's a good question which chips actually work and don't work with that version of Servo. I don't think anyone has even done a "sanity check" trying to compile an example with it.

What I do feel pretty confident in saying though, is that neither x5 nor x61 will work with it, which is a total fucking gloom cloud.

I love the idea of merging that library into the core. I suspect some of the same stuff that worked for x61 can be applied to x5 (they both have a similar wacky timer). Does it implement the same API as the normal one?

@SpenceKonde SpenceKonde changed the title ATTiny x61 interrupt driven servo library (8 bit) Servo Library support for x61, x5, and other unloved 'tinies Oct 12, 2016
@SpenceKonde SpenceKonde added this to the 1.1.3 release milestone Oct 12, 2016
@AtomicCactus
Copy link
Author

AtomicCactus commented Oct 12, 2016

You're right, the commit might have been a bit confusing. I did try just importing Servo.h at first but it did not compile. Mind you, this was before I spent ~2 weeks learning about timers and such things. I come from a Java server / iOS mobile dev background 😂

The "Servo_x61" library has a public interface in line with the standard Servo lib, except it lacks the writeMicroseconds() function. Which is funny because under the hood it uses microseconds. I'll update it. Would be interesting to see what other controllers this would work with. Thanks for giving it a chance! 🤓

PS: I played around with an oscilloscope and this could use some minor adjustments because the total frame length isn't exactly 20 ms (it moves with the pulse width, but it's very close) and other things are a bit wacky. It does keep the servo pointed in the right direction and doesn't produce any jitter so I'm using it for my project because there's no love for the x61 out there 😭

@SpenceKonde
Copy link
Owner

SpenceKonde commented Oct 12, 2016

Not producing jitter is probably the important part.

The work you did is by no means for naught, as the Servo.h I have only has any code for 16-bit timers, of which the x61 (and x5) have none.

I wonder why the x61 isn't more popular. It's even available in through-hole!
I don't think I've sold a single assembled x61 board.

@SpenceKonde SpenceKonde modified the milestones: 1.1.4 Release, 1.1.3 release May 13, 2017
@SpenceKonde SpenceKonde modified the milestones: 1.1.5 Release, 1.1.6 Release Jan 26, 2018
@SpenceKonde
Copy link
Owner

Last deferral, I swear - 1.2.1 will come fairly soon, since we're sure to end up with bugs relating to the new bootloader stuff too.

@SpenceKonde
Copy link
Owner

I've gotten a tiny85 servo implementation that seems to work, will be checked in shortly. Remember that you can't use software serial (including the builtin software serial "Serial" this core provides on chips without a hardware one) while controlling a servo. Anything that disables interrupts for any length of time will produce terrible jitter.

Will still need to do it for the tinyx61 and tiny43 (which each have slightly different timers available).

SpenceKonde added a commit that referenced this issue Nov 27, 2018
@AtomicCactus
Copy link
Author

I have an implementation now that allows for software serial use, but need to package it appropriately. It's not checked in anywhere, but I'm using it in my product here (felik.net). Traveling this week, but will try to submit a pull request once I'm back. My only concerns are:

  • requires use of special pins on x61 chips
  • doesn't play well with metal-gear servos, only the SG90 kind, despite emitting the correct pulse when measured with an oscilloscope

The code I presented a while back works fine, but like you said we must allow software serial use or else it's not very usable..

@SpenceKonde
Copy link
Owner

SpenceKonde commented Nov 27, 2018

I consider the "no software serial" limitation to be more acceptable than requiring the servos to be on specific pins. As I understand this limitation exists on the official Arduino core as well, doesn't it? (Edit: Quick search of the forums seems to confirm this). As this is how it works on the official core, we'll stick to that behavior here; If one needs a library that uses output compare to directly generate a servo signal on the PWM pins, a third party library can always be used.

I'm about to check in code that works on the tinyx61.

SpenceKonde added a commit that referenced this issue Nov 27, 2018
Servo support for x61 works too now! Wasn't terribly hard either.
@AtomicCactus
Copy link
Author

Up to you! Thank you for supporting the ATTinies 👍

@SpenceKonde
Copy link
Owner

That said, if the library is in a packagable state, it might be good to put it up on your github so I can add a note pointing to it to the docs for the applicable parts, next to where I remind people not to use software serial with servo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants