Recently bought teensy 3.0 how many servo's can she drive?

Status
Not open for further replies.

Xeon

Well-known member
HEX WALKER -Recently bought teensy 3.0 how many servo's can she drive?

I Recently bought teensy 3.0 how many servo's can she drive?
"not wondering about power consumed"


Edit-: logs so far......

-Bought servo's and extra teensy 3.0
-Servo's are TTL compatible with teensy 3.0
Rethink.jpg
Img_0114.jpg
Img_0105.jpg
orderplaced.png
Order placed.jpg
Base completed.jpg

+objectives
-=So need to edit servo lib. (FIXED) Thanks PaulStoffregen
-=Test bot in 3d.
-=Build bot base.

+Decide on brains "R-pi & x10 MP "u20i"
+Then interface Teensy with "insert brains here"
 
Last edited:
Try editing Servo.h and increase it to 16.

Just like on Arduino, the pulses are sent in round-robin fashion to each one, so adding 4 more will lengthen the time between pulses by 33%. That's going a bit beyond the specs, but odds are good your servos will work with it.
 
If that does not work, you could connect one of these to the 3.3V I2C bus side of the Teensy3 to the VCCL side and one of these to the VCCH side and you can control up to 16 servos effortlessly. or you just add another one for up to 32 or you add another one ...... ;-)
 
They say 12 servo's.
Those tests were done with the teensy at 48MHz correct?
So what if i clock to 96MHz and add 4 more servo's.
I'm speculating she should handle the job.

Should i fear overclocking?
 
Not sure who you are referring to with " they", but if you are referring to Adafruit's Servo driver then that's 16 channels at 12 bit resolution. 16 channels means 16 Servos.

Perhaps you should explain what you are trying to do before anyone can even make an educated guess if there is enough processing power to do it.
 
Sorry for my speculation.
Going to use the teensy over serial or usb to control 16 servo's.
 
Last edited:
And I seem to have made some errors in my math :(

Amount of servo's per appendage

Legs =
(Legs) x (leg segments)
6 x 2
=12 servo's


Arms
2 x 3
= 6 servo's


Hands
2 x 1
=2 servo's

Chest (from base to head) segments

(amount of segments) = (chest + head)
= 1 + 2
= 3 servo's


---------------------
Totals = 23 servo's!!!
possible?
 
Last edited:
Aha, now were getting closer to having an explanation of what you're trying to achieve. Looks like a humanoid robot. Ambitious! I like it.

Controlling that large a number of servo's from a hardware standpoint is possible with a Teensy3 by using the Adafruit Servo controller. This is an I2C bus controlled device and you can connect more than one of these to the I2C bus. the theoretical limit is 128 but there are a number of reserved addresses in the I2C bus spec so lets say 100. You would only need two of these to control 32 Servos.

If you can really control these with a Teensy3 at 48Mhz or 96MHz depends on what else the Teensy3 has to process. Most (industrial) robots rely on inverse kinematics using quite complex math. You define the path you want your end effector (Hand, finger tip, foot iin this case) to take and the software calculates in real-time what the joint angles need to be, which in essence is what your servos are doing.
If you do the calculation on a computer and just use the Teensy3 for secondary calculations and for I2C communication to the Servo's I'd say that this is possible. If you want all inverse kinematics math calculations to be performed by the Teensy3 I suspect that is not possible.

Industrial robot controllers are usually quite beefy in terms of their processing power!
 
Last edited:
Well i'm planing on only having the teensy drive the 23 servo's.
The teensy will be plugged into a raspberryPI running Raspian wheezy @1Ghz that is networked into a cluster with a few more pi computers.

Pi1 = Main program
Runs all primary automation

Pi2 = Sensors
(2x small IR camera's)
Handles encoding of video

Pi3 = Control
Feeding all the servo's
(Small Ultra Sound Radar Cluster made up of 4 ultra sound transmitters)
And the 6 motors for drive mode.
"1 to 2 more teensy3 boards for this perhaps.

It for a small 6 legged bot with a torso and a head.
It has 2 simple arms with clamp like hands but has nearly full human arm motion.
It tracks it's environment using a set of camera's to negotiate depth and it's focused apon world.
She goes further by having 360* radar for building a visual map and tracking changes around her.

Kinda reminds me of a Tachicoma robots from ghost in the shell.

I hope this is how this project will work out.
 
Currently the Servo library is limited to 12 signals. I have some ideas about greatly expanding that number, which I'll get to in a moment. You need to understand more about how the Servo library and servo control signals work first.

Please keep us updated as you get into this project, especially with photos. The honest reality is I'm not going to touch the Servo library based only on an ambitious plan.... but when you're actually building this project, if you really do connect 20-some servo motors and post good photos, code, measurement and other info, I'll work on the Servo library for you.

Before I get into details, the main point is interrupt latency and the number of hardware timers are what matters, not raw CPU speed. Doubling the CPU speed only helps slightly, in that a faster CPU will have slightly less interrupt latency with the same software. The software design and its use of hardware timer resources is what makes a dramatic difference. Overclocking the CPU isn't very risky, but for this application, the benefit is small.

Normally you don't need to know how servo signals and the Servo library works. You just connect the 1 control signal to a digital pin and use the library to set the angle. Then your main challenge is coding to make all those angles at the right times... and also a big enough power supply so all those motors can work. But if you're going to start thinking and talking about the Servo library design, then you really must understand how servo control signals work.

The signal is a pulse that repeats approximately 44 to 50 times per second. The width of the pulse tells the servo motor what angle you want. A 1.5 ms pulse indicates the middle of the range (90 degrees). The range is 0.544 ms to 2.4 ms.

The Servo library uses a hardware timer. Suppose you've written an angle that corresponds to a 0.9 ms pulse. When it's time to output the pulse, it sets you motor's pin high, then configures the timer to create an interrupt in 0.9 ms. This takes very little CPU time. For the next 0.9 ms, the library does nothing. Your program gets to run with all the CPU time. Then at 0.9 ms, the interrupt occurs and the Servo library drives that pin low. It then moves on to the next servo, setting its pin high and setting the timer to create another interrupt when that next motor's signal needs to end.

This process is repeated for all the motors you're currently using. After the last motor, it compares the total time spent creating all the signals. If you have just 1 motor and it's at 0 degrees, the time will be only 0.544 ms. If less than 20 ms has been spent, it then configures the timer to create an interrupt after 20 ms less the time spent creating the signals. That's important, because many servos can not accept more than 50 pulses per second.

If you have a lot of servos in use and they all had higher angles, the total time spent might already be more than 20 ms. For example, 12 servos all at 2.4 ms will be 28.8 ms. In that case, the Servo library skips the wait time, since it's already spent more than 20 ms. It just begins the pulse to the first servo again. But 12 servos all at their center position is only 18 ms, so the Servo library would wait another 2 ms before beginning the pulse to the first motor.

One simple thing you can do, which I suggested above, is just increase the number from 12 to, well, at that time 16. Now you're using 23? That's quite a few more than 12, but you could give it a try anyway. Now that you understand how this work, you'll know that to really test if 23 will work, you would need to write a little program that creates 23 Servo library objects and sets them all to their maximum 180 degree angle. Even if you only physically connect 1 motor, the library will be creating 23 signals. You could use an oscilloscope or a multimeter in frequency mode to check how often the signals are updating. But it's pretty easy math... 23 signals at 2.4 ms each is a total of 55.2 ms, which is 18.1 Hz.

The big question, which you can answer (and I really hope you will) is whether your servo motors work with an 18.1 Hz update rate? Just edit Servo.h to increase to 23 instead of 12. Then write a little test program, or modify the Servo library sweep example, so it creates 23 instances and sets all the unused ones to the max angle. If your motor works and is responsive, then you're good to go!

I mentioned some ideas earlier. Now I want to be clear, I am indeed willing to rewrite the Servo library on Teensy3. I wrote the version that currently works on Teensy3, patterned after Michael Margolis's design. But other than this long-winded message, I'm really going to be looking for you to get involved before I put in a lot of work. I really hope you do. This first simple test with 23 signals, 1 motor connected, and maybe a multimeter to check the frequency, and most definitely a photo, would be a very good first step.

So if I rewrite Servo, inspired by your project (and your effort to test and post real results here), I would try to use multiple timers. Servo already has this on AVR chips with more than one 16 bit timer. Each 16 bit timer generates 12 outputs. When you use 13, 14, 15, etc, it begins using another timer, effectively creating 2 sets of outputs. The downside to this, on AVR, is each 16 bit timer also creates PWM signals and might be needed for other libraries, so you lose some other functionality for each timer consumed.

On Teensy3, I wanted to avoid this loss of PWM and use of many other libraries. So instead of using the main timers, I used a special programmable delay timer. Currently no other library uses that timer, so on Teensy3 you can use Servo without messing up anything else. I ported Servo and designed it to use that timer early-on, only weeks after Teensy3's release last year. At the time, the IntervalTimer stuff didn't exist, so there was no easy way to share the pool of 4 programmable interval timers. Now, many months later, we do have IntervalTimer and several libraries and projects are using it. The nice thing about IntervalTimer is the 4 hardware timers (none of which are needed for PWM) are in a shared pool.

One idea I've had is redesigning Servo so it could draw upon any unused IntervalTimer capability when you go beyond 12 motors (without slowing the update rates by adding more motors per timer). Since there are 4 of those timers, in theory this could expand to 60 motors using the 4 interval timers and 1 delay block timer. Of course, there's only 34 I/O pins, so you can't possibly have more than 34 motors connected.

Even though this message is already long, one other issue to mention is interrupt latency. Since Servo is setting the pins high and low based on elapsed time when an interrupt occurs, anything that delays response to the interrupt will lengthen the signal (and shorten the next motor's signal). The millis() time update, USB activity, serial port use and other libraries all use interrupts. Software can also disable interrupts, which is critically important while accessing shared data. But other interrupts or disabling interrupts temporarily can cause jitter on your servo outputs. On Arduino, the SoftwareSerial library is the worse. Teensy3 has relatively few libraries that disable interrupts for lengthy times, partly because it's so much faster than AVR, partly because there are more on-chip peripherals and some of the worst libraries on Arduino either don't exist or use alternate ways on Teensy3.

Another feature Teensy3 has, which currently isn't being used, is nested interrupt priority. I've considered having Teensyduino initialize all the interrupts for a default "medium" priority level. Then some libraries like Servo could set higher priority. This hasn't been done yet, mainly because it simply hasn't been much of an issue for anyone. So again, if you're really going to be connecting 20-some motors, please keep in contact and please post good info (eg, photos, code schematics, etc) as you go.

Teensy3 has a tremendous amount of potential to make huge animatronic servo motor projects possible. But it's not the raw CPU speed that truly matters. Careful use of timers and interrupts are the key.... stuff the Servo library does for you. If the current library isn't capable of really supporting a large number of motors, I really would like to work to improve it. But that can only happen if you participate with good updates and info. How much I work on Servo, for the sake of your project, will really depend on how well you post updates and share good info. If you post photos, code, and measurements as you go (without lots of back and forth trying to get the info posted), that will help immensely.
 
Fascinating read and I appreciate you taking the time to reply.
Well I will be ordering my servo's soon and will be keeping info and pic's and vids on my blog that do often update.

If you want to check it out www.recall.co.nr
I have not got much to show yet.
But I will finish the base and torso keeping you informed as it's going.

Edit:

Also I see what you mean it's all a matter of timing not processing.

Unfortunately I also do not own a oscilloscope or any sort of signal generator for that matter.
Always wanted to try build a oscilloscope for myself. i'm wondering if anyone knows some cheap or simple builds.
Been hitting google but not getting many hits.
My little fluke multimeter can only show minimum, maximum and average frequencies being read.
no graph so it's really not suitable for the task.

I'm really very excited to learn and could probably fine tune the servo lib myself if i learn more about the inner workings of the teensy.
 
Last edited:
orderplaced.pngOrder placed.jpg

Today I ordered more parts.
Now I have three R-pi's.
And the servo's.

Gona begin constructing the base soon.
 
Last edited:
Hold on wait.
do i need to change the TTL levels ?
I only see now the teensy3.0 uses 3.3V
 
Most servo motors take "TTL level" signals, where low is less than 0.8 volts and high is greater than 2.0 volts.

Before you go to a lot of unnecessary trouble to convert 0-3.3V to 0-5V (perhaps using 74HCT125 or 74HCT245 buffer chips), you should probably check your motor's specs (if such detailed specs are published) or just connect one and see if it works. Odds are very good it will "just work", because anything over 2.0 volts is recognized as logic high.

Of course, most servo motors need considerable power at 5 volts while moving and delivering substantial torque, so you probably can't power more than 1 or 2 motors from VUSB.
 
Most servo motors take "TTL level" signals, where low is less than 0.8 volts and high is greater than 2.0 volts.

Before you go to a lot of unnecessary trouble to convert 0-3.3V to 0-5V (perhaps using 74HCT125 or 74HCT245 buffer chips), you should probably check your motor's specs (if such detailed specs are published) or just connect one and see if it works. Odds are very good it will "just work", because anything over 2.0 volts is recognized as logic high.

Of course, most servo motors need considerable power at 5 volts while moving and delivering substantial torque, so you probably can't power more than 1 or 2 motors from VUSB.

Ahh thanks i'll definitely look into that
 
The Servo library on Teensy3 supposed up to 12 servo motors.

Hi,
Again congratulation about the board (Teensy 3.0). I use it since 2 days and I confess it is really perfect and very impressive. I will buy more of them in the next.
Just one question. Since I m using Teensarduino and all the sfotware is copied into the arduino folder, if I use the servo library like:
#define <Servo.h>
, the library for arduino (AVR) will be picked up.
Where cna I find the servo library for Teensy 3.0? Eben in the website is the library for Teensy 2.0 (ServoPWM I mean).
Regards
 
It's in libraries/Servo within your Arduino. On a Mac, control-click and use "show package contents" to look inside. On Windows and Linux, it's ordinary directories.

Teensyduino replaces the normal Servo.cpp with a modified copy that uses alternate code when compiling for Teensy3. To see what changed, just compare Servo.cpp to an original copy. I pretty much had to re-implement the whole library based around the PDB timer. The good news is the PDB doesn't conflict with PWM or (so far) any other libraries, so using Servo on Teensy3 doesn't take away features like it does on all other boards.
 
Hi,
Again congratulation about the board (Teensy 3.0). I use it since 2 days and I confess it is really perfect and very impressive. I will buy more of them in the next.
Just one question. Since I m using Teensarduino and all the sfotware is copied into the arduino folder, if I use the servo library like: , the library for arduino (AVR) will be picked up.
Where cna I find the servo library for Teensy 3.0? Eben in the website is the library for Teensy 2.0 (ServoPWM I mean).
Regards

Just like any cpu it has it's own set of code.
 
Great news.
My package arrived.

Now.. let me build the base of the bot first. "IE the legs"
 
Before you built lots of stuff, I'd highly recommend doing just a few simple tests. If this is your first time using Teensy, at least make sure the board works and you can upload code. Also connect at least 1 servo and make sure the Teensy3 signal is compatible.

These things are much easier to troubleshoot before you have lots of motors and parts mounted in awkward positions and lots of wires soldered.
 
Status
Not open for further replies.
Back
Top