Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: offy on April 12, 2009, 08:36:58 AM

Title: Can I use a servo on a not PWM port
Post by: offy on April 12, 2009, 08:36:58 AM
I ran out of PWM ports and need to add 1 more servo, can I put it in a port without PWM, and if I do what could happen to my MCU and servo.
Title: Re: Can I use a servo on a not PWM port
Post by: SmAsH on April 12, 2009, 08:39:53 AM
nothing bad will happen to your mcu if you put a servo on a non-pwm port man! what mcu?
Title: Re: Can I use a servo on a not PWM port
Post by: offy on April 12, 2009, 08:40:20 AM
Roboduino is the MCU
Title: Re: Can I use a servo on a not PWM port
Post by: SmAsH on April 12, 2009, 08:46:52 AM
man, look at the $50 robot, it uses non-pwm ports and it hasn't screwed anyone yet.
Title: Re: Can I use a servo on a not PWM port
Post by: BEAMer on April 12, 2009, 09:01:45 AM
yea ofcourse... for one of my bots i used a PIC microcontroller to run 3 servo motors using general purpose I/O pins. i tried the PWM module of the PIC but it had noise in the output and the servo had lots of twitches in its movement. so i scraped the idea and used the GPIO.

All you have to do is, write a code to create a software delat to give a high on the pin for some time and switch it off for the rest of the time. this is PWM. The servo would happily consider this as the control signal and work!

BEAMer
Title: Re: Can I use a servo on a not PWM port
Post by: SmAsH on April 12, 2009, 09:08:16 AM
all pwm is is a PULSE WIDTH that is modulated eh? eg. you send a pulse and wait 1.5ms for center etc...
Title: Re: Can I use a servo on a not PWM port
Post by: Soeren on April 12, 2009, 10:52:07 AM
Hi,

all pwm is is a PULSE WIDTH that is modulated eh?
And exactly how do you modulate a width??  ;)

eg. you send a pulse and wait 1.5ms for center etc...
No, You send a pulse that IS 1.5 ms wide (for center position), then wait for around 17..18 ms before repeating the stunt.
Title: Re: Can I use a servo on a not PWM port
Post by: SmAsH on April 12, 2009, 03:37:00 PM
Hi,

all pwm is is a PULSE WIDTH that is modulated eh?
And exactly how do you modulate a width??  ;)
dammit! well i was close enough!
Title: Re: Can I use a servo on a not PWM port
Post by: Razor Concepts on April 12, 2009, 03:38:12 PM
SoftwareServo does not care about if the port is PWM or not. Heck, if you set the analog in pins to output you could use those too.
Title: Re: Can I use a servo on a not PWM port
Post by: Jdog on April 12, 2009, 08:44:39 PM
Hi,

all pwm is is a PULSE WIDTH that is modulated eh?
And exactly how do you modulate a width??  ;)

eg. you send a pulse and wait 1.5ms for center etc...
No, You send a pulse that IS 1.5 ms wide (for center position), then wait for around 17..18 ms before repeating the stunt.

Look in the $50 robot sor_utils.h
It says
Code: [Select]
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 0);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}

It's saying turn on portd wait for 1ms to 2ms turn portd off. Then wait around 9ms and do it again. You specify the 1-2ms delay to choose the position of the servo. Write a similair function to this and you'll be good.
Title: Re: Can I use a servo on a not PWM port
Post by: Soeren on April 12, 2009, 09:12:40 PM
Hi,

Look in the $50 robot sor_utils.h
It says
Code: [Select]
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 0);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}

It's saying turn on portd wait for 1ms to 2ms turn portd off. Then wait around 9ms and do it again. You specify the 1-2ms delay to choose the position of the servo. Write a similair function to this and you'll be good.

Thanks for the info, but I don't really need it (I played with micros, servos and lots of other stuff back when you were probably just a glimpse in your fathers eye, or even long before he had such thoughts ;)  and build a "personal" complete computer in the mid seventies when the Z80 was all the rage and the big liberator)

I was merely pointing out that you cannot modulate a "width", that expression doesn't make sense at all and in electronics, as well as in all other technical science, you have to be precise in your statements.

BTW. A cycle time of 10ms might easily be too short for some servos, the specified nominal cycle time of the R/C protocol is 50Hz/20ms (not 60Hz like you might read somewhere around the net).
Title: Re: Can I use a servo on a not PWM port
Post by: Jdog on April 12, 2009, 09:19:07 PM
Quote
Thanks for the info, but I don't really need it (I played with micros, servos and lots of other stuff back when you were probably just a glimpse in your fathers eye, or even long before he had such thoughts
Wow, a little rude.
Code: [Select]
was merely pointing out that you cannot modulate a "width", that expression doesn't make sense at all and in electronics, as well as in all other technical science, you have to be precise in your statements.I didn't use the word width in my reply at all, although that is the name of this technique, I don't know why, because as you said that expression doesn't make any sense.
Quote
BTW. A cycle time of 10ms might easily be too short for some servos, the specified nominal cycle time of the R/C protocol is 50Hz/20ms (not 60Hz like you might read somewhere around the net).
All I'm saying is that's what was used in the $50 robot.
Title: Re: Can I use a servo on a not PWM port
Post by: Soeren on April 12, 2009, 09:52:19 PM
Hi,

Wow, a little rude.
Never ment to, just gave you a backgrounder on why I don't really needed your (rude?) lecture on PWM.


I didn't use the word width in my reply at all, although that is the name of this technique, I don't know why, because as you said that expression doesn't make any sense.
You used a quote which did, which means that it was what your reply was founded in.

The reason for the name is not to modulate a width, but that the (variation of the) pulse width is the modulation.
Title: Re: Can I use a servo on a not PWM port
Post by: vialick on April 12, 2009, 10:13:58 PM
If you're really stuck, you can use audio to control a servo
Title: Re: Can I use a servo on a not PWM port
Post by: SmAsH on April 12, 2009, 10:24:27 PM
hes not really stuck, like 8 spare ports for him to use, and how the hell do you do that?
Title: Re: Can I use a servo on a not PWM port
Post by: vialick on April 13, 2009, 12:17:56 AM
hes not really stuck, like 8 spare ports for him to use, and how the hell do you do that?
Well I've been experimenting, and haven't exactly perfected it, but you generate a square wave at the required frequency. My physics is rusty (been years since I studied audio production) most signal generators create a symetrical waveform (eg a 100Hz wave will be positive for .0005 seconds and negative for the same time. If the pause between peaks is important (I know very little about servos) then you'll need to make an asymetrical waveform for precise control (due to lack of effort, I've only made the servo spin, I haven't tried to work out any precise controls yet)

I remember I had a graphical sequencing program where you could draw the waveform you wanted to use, you could probably also use C sound to generate the waveforms.

Essentially what you're doing both ways is exactly the same, if you want an interresting experiment, try hooking your servo outputs to an amplifier and speaker (make sure it's at a low level, square waves can do a lot of damage to speakers, and your ears) I think it would produce some interresting stereo experiences on the $50 robot,

But with the audio controlling method, you could plug into a DX7 and Rick Wakeman your heart out

----

come to think of it, you could go the other way round and use the normal outputs as a basic sound generator, if you can oscillate them off and on fast enough. Hook your 8 D outputs up to a speaker (well, probably to an amplifier first...I have no idea how much current would flow through them) and you could have your little chip making 3 bit sounds (expect pain), probably wouldn't be too hard to make it output a wave file...might try it as soon as I can get my programmer to work
Title: Re: Can I use a servo on a not PWM port
Post by: SmAsH on April 13, 2009, 03:59:13 AM
by dx7 do you mean jackson DX7? ive been wanting to get my hands on one of those sweet babies for ever now!
Title: Re: Can I use a servo on a not PWM port
Post by: vialick on April 13, 2009, 04:28:49 AM
by dx7 do you mean jackson DX7? ive been wanting to get my hands on one of those sweet babies for ever now!
That's a guitar right? I guess you could if you get guitar to MIDI device...hmm, could be good, would be good to watch at least

I was referring to the legendary Yamaha DX7 keyboard, though I'm not sure if Rick Wakeman's ever played one
Title: Re: Can I use a servo on a not PWM port
Post by: Soeren on April 13, 2009, 07:35:41 AM
Hahaha, I just get a mental picture of SmAsH trying control a 'bot by a hefty guitar solo.

The big question now is... Would a 12-string be able to control more servos than a regular model?  ;D
Title: Re: Can I use a servo on a not PWM port
Post by: SmAsH on April 13, 2009, 03:29:02 PM
its a 7 string! and maybe you could make one tune into a certain freq range? so like on only follows low g another e, a, d, g, b, e etc...