Starting Point System : Forum

You are not logged in.

#1 2010-04-11 11:49:45

brainbooster
Member

Driving rc servo and dc motors

Hi, i was looking for some schematics explaining how to interface rc servos for testing purpose and how to drive big dc motors...
Any clue?

Offline

 

#2 2010-04-12 10:51:08

gremlinc5
Member

Re: Driving rc servo and dc motors

http://www.epanorama.net/documents/motor/rcservos.html

if this is right... you need to use some kind of logic... You cannot use PWM signals DIRECTLY, they are to fast as frequency.

So we could use PWM indirectly with BACKGROUND EVENT.

use:
1 DIGITAL PIN as output to drive the servo
1 PWM PORT as timer for background event
1 ADC as your input to select the servo position
DIM to create variables
LET to manipulate variables
IF to create the needed logic to automate data manipulation

You will need to put high digital output for 1 ms and then low for 19 ms to achieve "initial position of servo".

Or you will need to put high digital output for 2 ms and then low for 18 ms to achieve "final position of servo".

If this doesn't work try other timer times... I used 20 ms to explain (1+19ms or 2+18 ms), try out 18 to 25 ms total time.

Next step is to use "1.17.4 Background event clock source" as explained in the user manual.

Put a frequency in PWM9 and set BACKCLK9.

OnEvent Background CODE will enable code usage periodically wrote:

dim counter as int
dim output as int

create 2 values in memory

let counter=0
let output=0

initialize variables to zero value

pin 10 output

pin 10 will be used to drive the servo

onevent background

the code after the "onevent" is periodical

if counter<2000 then increment counter

if counter is less then limit (2000 for 20ms) increase it

if counter = 2000 then adc 1

if counter limit is reached (2000 for 20 ms) take ADC value (ADC function put it automatically in "?")

if counter = 2000 then let counter = 0

if counter limit is reached (2000 for 20 ms) reset counter

let output = ?

put "?" value (the ADC value) in output variable

if counter = 0 then pin 10 high

if counter was reseted put pin 10 high

if counter = 0 then let output = output * 100
if counter = 0 then let output = output / 255

only if counter was reseted take output and NORMALIZE it at 100 (100 mean 1 ms, 200 mean 2 ms)

if counter = 0 then let output = output + 100

if ADC is at maximum value output is 100 (1 ms) but we need 2 ms, so add 100

if counter > output then pin 10 low

if counter is between output ms and 20 ms pu it low

endevent

This code init the production of BACKGROUND events every 0,00001 ms as the PWM frequency is 10MHz divided for your PWM value: 100 -> 100KHz  wrote:

pwm 9 per 100
pwm 9 on

background clock 9
background on

ADC DATA NORMALIZATION MEAN wrote:

if ADC value is 0 (min value) you need counter = 100
if ADC value is 255 (max value) you need counter = 200

max-min=200-100=100=ADCnormalized

ADCnormalized/ADCmax=100/255=1/2,55

you cannot divide ADC values taken from pin 1 for 2,55 so you need to mult per 100 and divide per 255

100 mean only 1 ms so you add another 100 to reach 2 ms, that is the value for servo to put it to its max.

("counter" is a 16 bit value so the max value is 65535.)

examples:

ADC=0
ADC*100=0
0/255=0
0+100=100 (1 millisec) servo at 0% MIN

ADC=100
ADC*100=10000
10000/255=39
39+100=139 (1,39 millisec) servo at 39%

ADC=255
255*100=25500
25500/255=100
100+100=200 (2 millisec) servo at 100% MAX

you need a potentiometer with 3 pins connected to 5 volt and ground, so put potentiometer central pin to ADC 1 to drive your system.

If you find errors tell it to me.

This code isn't checked or granted, it's an initial idea.

Ciao, by Michele.

Last edited by gremlinc5 (2010-04-13 14:28:18)


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#3 2010-04-12 16:24:41

brainbooster
Member

Re: Driving rc servo and dc motors

Ok, you've been very clear! i can't wait! just purchased a digital servo on ebay, it sould arrive this week! i've to experiment a lot of thinks, 1st servos , 2nd brushed and brushless motors, 3rd ultrasonic sensors 4th make some mess with visual basic and comm programming!
Thank you Michele (ITA?) i'll do some tests as soon as i get the parts and i'll let you know the results.
What about dc motors? can i drive a good mosfet directly with ucam. PWM? or do i need a "logic" to drive  it?

Offline

 

#4 2010-04-13 10:29:41

gremlinc5
Member

Re: Driving rc servo and dc motors

Yes I'm italian smile

If you want drive big DC Motors, you could use switching power supplies or simple big reles connected to the battery.

With a switching power supply you will change Motor speed changing the value of a potentiometer with big precision. With reles you will need to use digital outputs and some resistor.

The switching power supply eat some battery power (about 10%) during its work, the reles pass all the power at DC Motor.

When you will have some news on servos we will discuss this. wink

Last edited by gremlinc5 (2010-04-13 10:32:46)


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#5 2010-04-13 19:33:26

brainbooster
Member

Re: Driving rc servo and dc motors

per i motori in continua pensavo di generare un pwm (abbiamo un range abbastanza ampio da 2Hz a 5 Mhz) e darlo in pasto ad un mosfet avendo in questo modo una regolazione di velocitÓ e la possibilitÓ di alimentare il motore a tensione diversa da 5v, che ne dici?
For non italians:
about the dc motors, i was wandering to generate a PWM (we have a very wide range 2Hz to 5Mhz) and drive a power mosfet the way to have a kind of speed control and the possibility to drive the motor with a different voltage than 5v, what do you think about it?

Last edited by brainbooster (2010-04-13 19:42:10)

Offline

 

#6 2010-04-15 10:19:07

gremlinc5
Member

Re: Driving rc servo and dc motors

brainbooster wrote:

per i motori in continua pensavo di generare un pwm (abbiamo un range abbastanza ampio da 2Hz a 5 Mhz) e darlo in pasto ad un mosfet avendo in questo modo una regolazione di velocitÓ e la possibilitÓ di alimentare il motore a tensione diversa da 5v, che ne dici?
For non italians:
about the dc motors, i was wandering to generate a PWM (we have a very wide range 2Hz to 5Mhz) and drive a power mosfet the way to have a kind of speed control and the possibility to drive the motor with a different voltage than 5v, what do you think about it?

look at circuits 8 9 10 here:

http://www.picotech.com/applications/pwm_drivers/

i circuiti a fine pagina sembrano buoni potremmo provarli wink

there is some circuits that we could try out wink


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#7 2010-04-15 18:11:08

brainbooster
Member

Re: Driving rc servo and dc motors

The circuit 8 is precisely what I was talking about...
Today i got the servo, but now i'm blasted, so i will try tomorrow.
il circuito 8 Ŕ esattamente quello di cui parlavo...
Oggi mi Ŕ arrivato il servo, ma adesso sono distrutto e quindi prover˛ domani.

Last edited by brainbooster (2010-04-15 18:44:53)

Offline

 

#8 2010-04-16 22:09:02

brainbooster
Member

Re: Driving rc servo and dc motors

Ciao, ho fatto un p˛ di prove ma molto deludenti :-( (il servo risponde strano gira solo a destra)
Help
Michele, non Ŕ che potresti postare un batch del tuo primo esempio (pilotaggio servo)?

hi, i did some tests, but very disappointing :-(    (servo moves in a strange way,it only goes right)
Help
Michele, can you post a batch with the code of your 1st example (servo driving)?

Last edited by brainbooster (2010-04-18 19:28:07)

Offline

 

#9 2010-04-18 19:43:46

gremlinc5
Member

Re: Driving rc servo and dc motors

brainbooster wrote:

Ciao, ho fatto un p˛ di prove ma molto deludenti :-( (il servo risponde strano gira solo a destra)
Help
Michele, non Ŕ che potresti postare un batch del tuo primo esempio (pilotaggio servo)?

hi, i did some tests, but very disappointing :-(    (servo moves in a strange way,it only goes right)
Help
Michele, can you post a batch with the code of your 1st example (servo driving)?

XD

quel codice l'ho inventato per te... io non l'ho mai provato... XD

ummm non gira a sinistra dici?

booo se vuoi ci provo anch'io dovrei avere dei servo in casa di una macchina elettrica vecchia. Ci provo e poi posto il codice per intero wink

Hi, I didnt have already used the code so I will prove that with some old servo to find out the problem.


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#10 2010-04-19 07:03:01

brainbooster
Member

Re: Driving rc servo and dc motors

Ok, non vedo l'ra di capire cosa c'Ŕ di sbagliato...
Ho fatto anche un p˛ di prove con il demo bench, ma niente
Ho anche scritto un programmino da 0 in vb6 con tre tasti (destra centro sinistra) e temporizzazioni fisse, ho giocato con la funzione di prescaling ma senza successo :-(
Penso che dipenda dal fatto che non riesco a calcolare la frequenza generata, sul manuale utente dice che abbiamo 10 MHz e 65535 passi quindi dovremmo avere 153Hz per ogni passo, ma nell'esempio successivo un valore 1000 sta per 10kHz perchŔ?!


OK, i can't wait to understand what's wrong...
I've made some tests with the demo bench, but no way...
I also wrote from scratch a little vb6 app with 3 buttons (for right center left) and fixed timings , played with prescaler functions but without success :-(
i think is because i can't calculate the generated frequency, on the user manual we have 10MHz and 65535 steps so we shuld have 153Hz for every step, but in the subsequent example a value of 1000 stands for 10kHz why?!

Offline

 

#11 2010-04-19 15:27:17

gremlinc5
Member

Re: Driving rc servo and dc motors

brainbooster wrote:

Ok, non vedo l'ra di capire cosa c'Ŕ di sbagliato...
Ho fatto anche un p˛ di prove con il demo bench, ma niente
Ho anche scritto un programmino da 0 in vb6 con tre tasti (destra centro sinistra) e temporizzazioni fisse, ho giocato con la funzione di prescaling ma senza successo :-(
Penso che dipenda dal fatto che non riesco a calcolare la frequenza generata, sul manuale utente dice che abbiamo 10 MHz e 65535 passi quindi dovremmo avere 153Hz per ogni passo, ma nell'esempio successivo un valore 1000 sta per 10kHz perchŔ?!


OK, i can't wait to understand what's wrong...
I've made some tests with the demo bench, but no way...
I also wrote from scratch a little vb6 app with 3 buttons (for right center left) and fixed timings , played with prescaler functions but without success :-(
i think is because i can't calculate the generated frequency, on the user manual we have 10MHz and 65535 steps so we shuld have 153Hz for every step, but in the subsequent example a value of 1000 stands for 10kHz why?!

E' il contrario se inserisci "pwm 9 pre 65535" ottieni una freq di 153 Hz.
Se inserisci "pwm 9 pre 1" ottieni una freq di 10 MHz.

ITALIANO wrote:

Il PWM PERIOD Ŕ il numero di volte che conti il clock.

pwm 9 period 100
significa: conta 100 volte il clock

dato che il clock Ŕ 10MHz che nel tempo significa 0,0000001 second

la frequenza PWM Ŕ lenta rispetto al CLOCK ed il valore per "pwm 9 period 100" Ŕ
10'000'000/100 = 10KHz come da manuale

se vuoi calcolare "period", e lo vuoi calcolare per 35 KHz cioŔ 35000 Hz:
10'000'000/35000= 285
per ottenerlo ti serve
pwm 9 period 285

pwm [pin] period [value]
significa: nel timer del pin numero [pin] conta [value] volte il clock, ottenendo un segnale periodico.

ENGLISH wrote:

The PWM PERIOD is the number of CLOCK counted.

pwm 9 period 100
mean: count 100 times the clock

if clock is 10MHz = 0,0000001 second

PWM frequency is slow respect to CLOCK and the value is
10'000'000/100 = 10KHz as the manual example

if you want to calculate it, you want to calculate it for 35KHz do:
10'000'000/35000= 285

mean: to obtain 35000 Hz count 285 times the clock time

Last edited by gremlinc5 (2010-04-19 16:07:03)


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#12 2010-04-19 17:51:54

brainbooster
Member

Re: Driving rc servo and dc motors

OK, capito, anche se nel tuo esempio usi 100 ed il manuale utente dice 1000 per avere 10kHz.
E quindi?! non capisco perchŔ il servo non funziona...
Ma tu ci sei riuscito a farlo muovere?
Ho riportato tutti i comandi dell'esempio (tranne i commenti) ma non succede nulla...
Forse ho sbagliato la sequenza?

Ok, got it, even if in your example you use 100 and the user manual use a value of 1000 to have 10kHz.
So what?! i don't understand why the servo doesn't work...
Did you managed to moving it?
I wrote all the commands of your example (but the comments) but nothing happens....
maybe i messed up the sequence?

Help this is the code:

dim counter as int
dim output as int
let counter=0
let output=0
pin 10 output
onevent background
if counter<2000 then increment counter
if counter = 2000 then adc 1
if counter = 2000 then let counter = 0
let output = ?
if counter = 0 then pin 10 high
if counter = 0 then let output = output * 100
if counter = 0 then let output = output / 255
if counter = 0 then let output = output + 100
if counter > output then pin 10 low
endevent
pwm 9 per 100
pwm 9 on
background clock 9
background on

dov'Ŕ l'errore?
where is the error?

Last edited by brainbooster (2010-04-19 19:44:00)

Offline

 

#13 2010-04-20 10:09:39

gremlinc5
Member

Re: Driving rc servo and dc motors

brainbooster wrote:

OK, capito, anche se nel tuo esempio usi 100 ed il manuale utente dice 1000 per avere 10kHz.
E quindi?! non capisco perchŔ il servo non funziona...
Ma tu ci sei riuscito a farlo muovere?
Ho riportato tutti i comandi dell'esempio (tranne i commenti) ma non succede nulla...
Forse ho sbagliato la sequenza?

Ok, got it, even if in your example you use 100 and the user manual use a value of 1000 to have 10kHz.
So what?! i don't understand why the servo doesn't work...
Did you managed to moving it?
I wrote all the commands of your example (but the comments) but nothing happens....
maybe i messed up the sequence?

Help this is the code:

dim counter as int
dim output as int
let counter=0
let output=0
pin 10 output
onevent background
if counter<2000 then increment counter
if counter = 2000 then adc 1
if counter = 2000 then let counter = 0
let output = ?
if counter = 0 then pin 10 high
if counter = 0 then let output = output * 100
if counter = 0 then let output = output / 255
if counter = 0 then let output = output + 100
if counter > output then pin 10 low
endevent
pwm 9 per 100
pwm 9 on
background clock 9
background on

dov'Ŕ l'errore?
where is the error?

In ingresso al pin 1 cosa gli dai?

pwm 9 per 100 ti da una frequenza di 10000 Hz e la variabile counter conta 2000
10000/2000 = 50 Hz -> cioŔ 0,02 secondi = 20 ms
che Ŕ giusto

comincio a pensare che un evento in background cosý veloce non possa essere utilizzato... dobbiamo arrabattarci un sistema che sfrutti l'evento in background standard da 20 Hz per aggiornare il valore ADC1. Ma di base usare le istruzioni WaitTime per creare i segnali.

Stasera porto a casa il uChameleon che uso al lavoro e provo wink

We must use WaitInstructions and not a background event with 10KHz refresh time. It is too fast, the uChameleon doesnt execute all the Background Event instructions.


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#14 2010-04-20 12:41:26

brainbooster
Member

Re: Driving rc servo and dc motors

on the channel 1 there is the central pin of a 2k2 pot (other pins to gnd and 5v)
we could use the timer object in vb6, it should have a 1ms resolution...
i don't know if background event is too fast, i wrote to sps to have some extra examples, but they don't reply...


sul canale 1 c'Ŕ il piedino centrale di un potenzionetro da 2200k ( gli altri due vanno a massa e 5v)
potremmo usare il controllo timer di vb6 dovrebbe avere una risoluzione di 1ms...
non s˛ se l'evento backgroung e troppo veloce, ho scritto a sps per avere qualche esempio in pi¨ ma non rispondono....

Last edited by brainbooster (2010-04-20 15:17:00)

Offline

 

#15 2010-04-21 08:56:51

brainbooster
Member

Re: Driving rc servo and dc motors

novita? io sono bloccato :-(

any news? i'm stuck :-(

Offline

 

#16 2010-04-22 00:27:45

gremlinc5
Member

Re: Driving rc servo and dc motors

brainbooster wrote:

novita? io sono bloccato :-(

any news? i'm stuck :-(

no non ce l'ho fatta neanche io
domani con l'oscilloscopio prover˛ a vedere i segnali in uscita dalla centralina della macchina RC
potrebbe anche essere un problema di corrente dall'esterno, se richiedesse parecchi milliamp

no i havent done it at yet
tomorrow I will study the RC car output signals to find out a way to do it
it could be also a current drain problem, uChamy could not give too milliamp

Last edited by gremlinc5 (2010-04-22 12:15:38)


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#17 2010-04-22 19:20:44

brainbooster
Member

Re: Driving rc servo and dc motors

In my opinion it's not a current matter, because with the wrong tinings the servo turns right until the end of the coarse and still want to go ... (i've almost burned the servo).
Maybe i should open another thread:"How to generate a 50Hz pwm with 1.5ms duty cycle.
P.S.
Hey SPS support team, are you there? clean up the forum from spam/spammers at least...

Penso che non sia un problema di corrente, perchŔ con i tempi sbagliati il servo gira vigorosamente a destra fino a fine corsa e vorrebbe anche andare oltre (ho quasi squagliato un servo).
Forse doveri aprire un altro thread:"come generare un pwm a 50Hz con duty cycle di 1,5ms).
P.S.
Hei amministratori del forum ci siete? pulite il forum dallo spam almeno...

Last edited by brainbooster (2010-04-22 19:27:08)

Offline

 

#18 2010-04-22 19:58:32

SPS Support Team
Moderator

Re: Driving rc servo and dc motors

Hello brainbooster,

Here is a simple sequence of commands that will program a pwm output to 50Hz / 1ms pulse:

pwm 9 prescaler 4
pwm 9 period 50000
pwm 9 width 2500
pwm 9 on

A 1.5ms pulse will be obtained by sending:
pwm 9 width 3750

A 2ms pulse will be obtained by sending:
pwm 9 width 5000

You can try that by pasting these line into the "ÁChameleon Control" text editor and sending the code with crtl-D.

Of course, it is still possible to read an analog input driven by a potentiometer, and modify the pwm value in a background event for real-time interaction with no PC connected !

Cheers,

Offline

 

#19 2010-04-22 20:56:00

brainbooster
Member

Re: Driving rc servo and dc motors

Alleluia! funziona!  Grazie SPS


Alleluia It works! thanks SPS

Last edited by brainbooster (2010-04-23 09:42:20)

Offline

 

#20 2010-04-23 16:15:09

gremlinc5
Member

Re: Driving rc servo and dc motors

All this for the prescaler... XD

We need a "200 Hz" PWM signal prescaled to "50Hz" with "prescaler 4"... thanks I have got it wink


ST7FLite39 daughter board
REva 2.10
RLink 3.4
"uChameleon" as: SPI Master for debug, Analog output for sensing emulation

Offline

 

#21 2010-04-23 20:37:41

brainbooster
Member

Re: Driving rc servo and dc motors

E adesso.... parte 2: pilotare i motori in continua..
primo problema.... che frequenza dovrei generare per pilotare un mosfet tipo irfz48n? (tipo 20kHz?)
secondo problema... posso inviare il segnale del pwm direttamente al mosfet o serve altro?

And now... stage 2: driving dc motors
first question.... wich frequency should i generate to drive a irfz48n mosfet? (guess 20kHz?)
second question... can i send the pwm signal directly to the mosfet or do i need something else?

Offline

 

#22 2010-04-25 10:34:08

brainbooster
Member

Re: Driving rc servo and dc motors

Autorisposta alle domende precedenti...
Il mosfet pu˛ essere pilotato direttamente senza altri componenti aggiuntivi
il codice per generare il giusto (per mŔ ha funzionato) segnale pwm Ŕ il seguente:
pwm 11 prescaler 2
pwm 11 period 2000
pwm 11 width  (potete mettere da 1300 a 1900)
adesso ho il controllo manuale potenziometrico sul movimento del servo e della velocitÓ del motore in continua!

Autoanswer to my previous questions...
You can directly drive the mosfet without any other component
The code to generate the right (has worked for me) pwm signal is the following:
pwm 11 prescaler 2
pwm 11 period 2000
pwm 11 width  (you can put values between 1300 and 1900)
now i have potentiometric manual control over the servo and the dc motor speed!

Offline

 

#23 2010-04-26 12:05:02

brainbooster
Member

Re: Driving rc servo and dc motors

Now stage 3 ... interfacing ultrasonic range finder to have a sonar like function.
i'm gonna buy/use this module http://droboticsonline.com/ebaydownload … Manual.pdf
it also have a channel to control a servo for the tipical radar moves.
what do you think about that module?

E adesso livello 3 interfacciamento di modulo ad ultrasuoni per avere una fonzionalitÓ tipo sonar.
comprer˛/user˛ questo modulo http://droboticsonline.com/ebaydownload … Manual.pdf
ha anche un canale che pilota il servo per il movimento tipico del radar.
Che ne pensate? fattibile?

Offline

 

Board footer

Powered by FluxBB

Home