PDA

View Full Version : servo motor resets 16f877a



burak450
- 30th September 2008, 00:47
Hi.After a little time,Servo resets 16f877a when I make power on .I know i need to use opto-isolator and i have 4n35 but i dont know what connections are required.Somebody can tell me?Thanks everybody who answers my question...

Archangel
- 30th September 2008, 02:01
http://www.alldatasheet.com/datasheet-pdf/pdf/2848/MOTOROLA/4N35.html

burak450
- 30th September 2008, 11:54
thanks for your response but I mean what connections are required between 16f877a and 4n35 and servo motor?

aratti
- 30th September 2008, 12:56
Connect the output pin of the pic to pin 1 of 4n35 via a resistor of 330 ohms connect pin 2 to digital ground. you can also place a led diode in series (between pic and opto to detect the state)

Pin 4 and 5 (4nn35) will be used to drive your servo (max current 150mA) if you need more current you must use a power transistor or a mosfet. Connect to analog ground pin 4 and pin 5 to your servo ground side. Connect the positive analog voltage directly to the servo.

When your pic pin will go high the opto will conduct switching on your servo.

burak450
- 30th September 2008, 15:20
I am sorry but i dont get exactly.Can you send any proteus file to here?
my servo is this http://www.rcuniverse.com/market/item.cfm?itemId=230128
what kind of circuit should I use?

aratti
- 30th September 2008, 17:14
Find enclose the schematic. You should separate the supply of the pic from the supply of the servo to avoid the electrical noise generated by the servo will disturb the functionality of your pic. Remember that 4N35 can supply a maximum current of 50 mA so if you want to use the schematic as it is, you must check that your servo does not need higher current. Naturally you do not need to change the software, because the wiring will give you a direct interfacing.

Hope this will solve your problem.

burak450
- 30th September 2008, 17:29
Forgive me i asked too many questions but i am a rookie about pic.my servo motor has three cable.+5 volt,ground and i have another cable as signal cable.Where do I connect signal cable??? Thank for your patience...

Archangel
- 30th September 2008, 17:43
Forgive me i asked too many questions but i am a rookie about pic.my servo motor has three cable.+5 volt,ground and i have another cable as signal cable.Where do I connect signal cable??? Thank for your patience... . . . . . If using the opto . . then to that . . . otherwise to the pic . . . . Why use the optoisolator . . .are you using some dangerous voltage, somewhere ? Or just trying to keep servo isolated from pic?

burak450
- 30th September 2008, 18:03
I am just trying to keep servo isolated from pic.my question is that where should I connect orange cable?

http://img107.imagevenue.com/loc390/th_93956_DSC00308_122_390lo.JPG (http://img107.imagevenue.com/img.php?image=93956_DSC00308_122_390lo.JPG)

skimask
- 30th September 2008, 18:25
I am just trying to keep servo isolated from pic.
You really shouldn't NEED to isolate your servo from your PIC as long as you have a well designed circuit to drive it. I've used servos with my PICs, never had a need to isolate them, ran them off the same battery pack, same wires, etc.etc.etc.
If you're trying to run a PIC and a servo off a 9v battery (the little rectangular ones) connected to a single 7805 type regulator without any sort of cap's in the circuit anywhere, well, then, yes, you will most likely have a problem.

Maybe if we saw your schematic, we could help you figure out a way to avoid the isolator altogether...
Maybe you forgot to put a pullup on MCLR...maybe your oscillator setup is a bit goofy...maybe you got peanut butter in your chocolate...:D Who knows...

Acetronics2
- 30th September 2008, 19:14
Hi, Burak

THIS could be a geat help :

http://www.parallax.com/Portals/0/Downloads/docs/prod/sic/Signals.pdf

Alain

burak450
- 30th September 2008, 22:50
I am trying to design an object tracker (only left and right) and I am using phototransistors by using two analog inputs.I have to explain my problem more clear.When I turn power on servo tracks object but after a while sometimes pic resets itself or servo motor suddenly stops.I hope
I explained it clearly.What do you suggest? Here is my design.When you see the design there is a lcd.I use it for watching the values of analog input.When servo rotates,brightness of lcd changes (getting brighter or darker)...I think thats another weird thing...
http://img183.imagevenue.com/loc166/th_11142_servo_122_166lo.jpg (http://img183.imagevenue.com/img.php?image=11142_servo_122_166lo.jpg)

skimask
- 1st October 2008, 01:25
When servo rotates,brightness of lcd changes (getting brighter or darker)...I think thats another weird thing...
Doesn't that right there tell you something about the quality of your power supply?
Let's see...if I'm driving down the road, and my headlights change brightness, does that tell me anything about the electrical power in the car? If I'm sitting in my living room at night reading a book and the room's lights either dim or get brighter, would that tell me something about the local power grid?

I don't see ANY capacitors in there, either across Vdd and Vss or across your servo's power supply. I don't see what kind of power you are supplying this circuit with. I don't see a lot of anything.

Ya know, for that matter, we haven't seen your code yet... Who knows...maybe it is actually a firmware problem...

Archangel
- 1st October 2008, 09:04
I would agree with Skimask re: the capacitors and your power supply, I would add, disable Brown Out Reset in your config statement so PIC does not reset, I would further suggest you change your reference to God Blessed servo, just remembering something Moses said to Pharoe, "by your own words . . ." Cause if he Damns it, it's toast.

aratti
- 1st October 2008, 10:11
Hi, Burak from your schematic and your explanation I understand that is just a power supply problem! Add 10nF capacitor to the Vdd pic pin. Since surely you are using battery, my suggestion is that you use a two 9 volts batteries in parallel to a 7805 and use its output as power supply for your project. One way to check quickly that current failure is your problem, can be achieved simply removing (disconnect it) the backligth of your lcd, and very likely the problem will disappear as long as the present battery will be able to supply the required energy

burak450
- 1st October 2008, 10:28
i should repeat that=Lcd brightness doesnt change at normal work. when servo moves than it goes high or low...
my power supply is that.

switching adapter
input:ac 100-240V-50hz 0.36A
output:dc 5v--2.5A

and my program is that



DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE OSC 4
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 100
SYMBOL F=PORTA.0
SYMBOL G=PORTA.1
alta var byte
usta var byte
altb var byte
ustb var byte
ADCON1=2
TRISA=3
TRISB=0
PORTB=0
TRISC=0
LCDOUT $FE,1
pause 4000
adcin 0,ALTa
ADCin 1,usta

t var byte
i var byte
T=150

yap:




adcin 0,altb
ADCin 1,ustb






if ((((usta+10)*100)/(ustb+10)))>135 then
T=T+15
endif

if (((alta*100)/altb))>135 then
T=T-15
endif


gosub motor







LCDOUT $fe,2,#usta," ",#ustb," ",#altA," ",#altb

goto yap

motor:
for i=0 to 25
PULSOUT PORTC.2,T
PAUSEUS 20000-(T*10)
next
return

end

aratti
- 1st October 2008, 10:42
Check power supply wiring, especially the connector, install 1000 uF 16V electrolytic capacitor and 10 nF on your pic power pin

skimask
- 1st October 2008, 13:37
For grins, try changing your BYTE values to WORDs and see what happens.
Might be overflowing the byte values somewhere killing the program somehow someway.

Acetronics2
- 1st October 2008, 14:29
Hi, Burak

I'm curious to know which testboard you use ...

16F877A , LCD on PortB ... that sounds quite familiar.

So, the question is ... Where do you ( geographically ) take the servo 5v supply from ???

Alain

Bruce
- 1st October 2008, 14:29
Use a separate power supply for your servo.

burak450
- 1st October 2008, 14:39
Bruce thanks for advice,i tried million times but couldnt connect separate supply correctly.I think you mean opto-isolotor circuit.Do you suggest any opto-isolator circuit??
Some guys said i dont need this circuit.I am confused now.

Acetronics,I took 5v supply to servo from same source where I took power to pic.I mean servo and pic is feed same source...

sougata
- 1st October 2008, 14:50
Hi,

16F877a has got a Power Control Register (PCON). Section 14.10 page 151 in the datasheet.

In the top of your code just after you initialize the LCD. Read the PCON into some variable and display it on the LCD for say 5 seconds. Note it down just after a reset. This may help decide the cause of the reset---> Brown Out, WDT, MCLR etc.

Also make sure that your RB3 (Pin 37) is not floating. It is the LVP pin and noise on that can trigger the ICSP mode.

Just for information on the opto part you can use a TLP250 optocoupler (works upto a few khz) which has got a totem-pole output. So you drive the LED and get a 0-1 on the output. I use it mainly for my IGBT driver needs.

Bruce
- 1st October 2008, 15:01
You should not need an opto, but you may want to include the series resistor shown in the .PDF Alain linked to.

A separate power supply for the servo is a good idea, but you need a common ground connection between the two power supplies.

Most hobby type servos will work fine with a DC supply of ~4.8 to 6Vdc. I normally use a set of 4 x D cells. Just connect the ground leg from your batteries to the ground leg of your regulated supply for the controller.

If you use another regulated supply for the servo, make sure it can handle the servo load current. A servo can draw quite a load. Some up to 1A or more. Having this load on your primary supply can drop voltage and cause a device reset. With separate supplies you shouldn't have this problem.

Acetronics2
- 1st October 2008, 15:06
Ok, Folks

I've got it ...

Servo driving values on C.2 go out of the nominal 0.8 - 2.2 ms range OR Pause between pulses goes wrong.

Servo bumps on its mechanical stops ... or the amp doesnt like the pause !!!

That's all !

Alain

burak450
- 1st October 2008, 15:20
Acetronics,
Can you explain it more clear,i dont get what you mean.Is there any solution on your mind?

Acetronics2
- 1st October 2008, 15:28
Hi, Burak

The only solution is for you to verify you send correct signals to your servo ...

800 to 2200 µs @ 35 - 50 Hz ... only allowed.

Nothing more or less to say !

Alain

burak450
- 1st October 2008, 15:38
Hi Acetronics,
I think you are wrong because my signal is 50hz.I am using 20ms periodic pulses,if t=100 then 1ms high and 19ms low.if the period 20ms then frequency will be 50hz from the formula f=(1/T)
here is my signal code

PULSOUT PORTC.2,T
PAUSEUS 20000-(T*10)

where am I wrong?

skimask
- 1st October 2008, 15:43
Hi Acetronics,
I think you are wrong because my signal is 50hz.I am using 20ms periodic pulses,if t=100 then 1ms high and 19ms low.if the period 20ms then frequency will be 50hz from the formula f=(1/T)
here is my signal code

PULSOUT PORTC.2,T
PAUSEUS 20000-(T*10)

where am I wrong?

Look at the loop in your code.
Aboslutely no 'bounds' checking.
What if...T = 0? Then pauseus = 20000, ok no problem...
What if T=2000? Then pauseus = 0, ok not much of a problem...
What if T=2001? Then pauseus = 65526, ok, shouldn't happen because you've got T defined as a BYTE

But...what happens when you try to drive the servo out of it's physical limits?
What happens to the current draw if you hold a servo that's trying to move? Hook up an ammeter and find out real quick. And if you don't have an ammeter, hook up a voltmeter to your 'battery' and try it and see what happens to your voltage...

Acetronics2
- 1st October 2008, 16:39
Hi Acetronics,
I think you are wrong because my signal is 50hz.
?


Lol ...

It has been verifyed with a R/C Pulsemeter.

Checks pulse AND repeating frequency ...

Y've done the mods to have your program running ...

Runs awfully bad for a tracker, but runs ... on the USB supply from my PC. ( 500 mA ! )

YOU are wrong in your calculations ... that's it !!!

burak450
- 1st October 2008, 17:10
Hi Acetronics,
First of all,calm down :)

I just said my idea...

I havent got R/C Pulsemeter,I cant measure the pulses...

Probably your calculations are right.I am here because my project doesnt work correctly and want to have second opinion.

Can you give me the right code ?

will only changing variable type byte to word be enough????

skimask
- 1st October 2008, 17:16
Can you give me the right code ?
http://darreltaylor.com/files/ROFL.gif


will only changing variable type byte to word be enough????
Probably not...
Think about this...
How long does it take for ADCIN to execute?
How long does it take for LCDOUT to execute?
And fix your power supply...

burak450
- 1st October 2008, 17:33
And fix your power supply...


as you said that you mean same ground but another power supply...

did I understand right?

skimask
- 1st October 2008, 17:50
as you said that you mean same ground but another power supply...

did I understand right?

No I mean read back thru the thread! I don't see any mention of adding any capacitors anywhere in the circuit...except where somebody but you has mentioned them...
And, you say you are using a switching adapter, like a wall-wart rated at [email protected]?
How long is the cord feeding the PIC/servos? How much 'noise' is getting to your PIC? How much 'noise' does your servo generate under a load? Any capacitors in there anywhere?
http://en.wikipedia.org/wiki/Decoupling_capacitor

Acetronics2
- 1st October 2008, 18:18
Hi, Burak

Don't worry for me ... I always am calm.

I Exceptionnaly cook code for others ...


so,

- you'll fist check "T" calculations and do not allow it to go out of the 800 - 2200 µs range

- Check for a "decent" increment to the same "T" variable

- Understand that 50 Hz is not a MUST ... just be in the 35-50 Hz range; doesn't need to be a constant frequ. nor.


PS: "Give me THE code" or "Give me THE scheme" are the sentences that suddently re activate my Altzheimer ...

What Were we talking about ??? ...

Alain

burak450
- 1st October 2008, 21:45
Ok.I wont want you to give code because i know Altzheimer is very tough disease :)

I am gonna try what you said.If I fail I will disturb you again :)

Thanks for help up to now....

Macgman2000
- 2nd October 2008, 04:46
Why not just write simple code to sweep servo left to right and back right to left for testing? BTW, if you use a 5v regulator with 5v output power supply, it will cause a power drop when you try to draw current. A voltage reg will probably need 6.5v++ input voltage. Also, I have driven 4 large servos off of 2 paralleled voltage regs and a low current reg for the pic....no problems at all.

Acetronics2
- 2nd October 2008, 08:17
Hi, Burak

We haven't solved the power problem ...

so, I ask the question once more : Which is your testboard ???

Alain

burak450
- 2nd October 2008, 12:01
Macgman2000 wants my code...

I wrote a new code to protect values which makes out of range.



DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE OSC 4
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 100
SYMBOL F=PORTA.0
SYMBOL G=PORTA.1
alta var byte
usta var byte
altb var byte
ustb var byte
ADCON1=2
TRISA=3
TRISB=0
PORTB=0
TRISC=0
LCDOUT $FE,1
pause 4000
adcin 0,ALTa
ADCin 1,usta

t var byte
i var byte
T=150

yap:




adcin 0,altb
ADCin 1,ustb






if ((((usta+10)*100)/(ustb+10)))>130 and (not (t>194)) then
T=T+15
endif

if (((alta*100)/altb))>130 AND (not (t<51)) then
T=T-15
endif


gosub motor







LCDOUT $fe,2,#usta," ",#ustb," ",#altA," ",#altb
lcdOUT $fe,$C0,#T

goto yap

motor:
for i=0 to 25
PULSOUT PORTC.2,T
PAUSEUS 20000-(T*10)
next
return

end




I am using breadboards.A minute ago i tried to connect two parallel power supply.Servo didnt reset MCU.I was glad but sometimes when i turned power on ,servo turned full left sometimes didnt.I think my servos are crazy :) .BTW I connected a capacitor.

I have an idea.Can this error(full left error) occur because of my code that i wrote.too many PAUSEUS may make this error.Should I try DUTYCYLE or PWM codes???

Or Is there any power problem???

Macgman2000
- 2nd October 2008, 13:52
If you have an oscilloscope look at your control pulses from the PIC to the servo as it moves. If you see that the wave form (1~2ms pulse) is wiggling around or changing amplitude then you have a power supply issue. Do as I suggested above, get a 9v power supply (AC/DC) and use TWO 7805 regulators in parallel for the servo ONLY. At the servo use 470uF across power and ground. Look at the scope again and make sure you see a "cleaned" up signal while servo is in motion.

Nick

skimask
- 2nd October 2008, 13:54
I wrote a new code to protect values which makes out of range.
In the middle of that math mess? I don't think it's a good spot for it...but that's just me...



DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE OSC 4
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 100
f var porta.0 : g var porta.1 : alta var byte : usta var byte : altb var byte
ustb var byte : t var byte : i var byt e: adcon1=2 : trisa=3 : trisb=0
portb=0 : trisc=0 : pause 1000 : lcdout $fe,1 : pause 4000
adcin 0,ALTa : ADCin 1,usta : t=150
pulsout portc.2,t 'initial servo kick to center
yap: adcin 0,altb : adcin 1,ustb
if ((((usta+10)*100)/(ustb+10)))>130 and (not (t>194)) then T=T+15
if (((alta*100)/altb))>130 AND (not (t<51)) then T=T-15
'bounds checking...
if t < 100 then t=100
if t > 200 then t=200
'bounds checking
'if 100 isn't low enough, change it, if 200 isn't high enough, change it
gosub motor : lcdout $fe,2,#usta," ",#ustb," ",#altA," ",#altb, $fe,$C0,#T
goto yap
motor: for i=0 to 25 : PULSOUT PORTC.2,T : PAUSEUS 20000-(T*10) : next i
return
end

Acetronics2
- 2nd October 2008, 17:04
but sometimes when i turned power on ,servo turned full left sometimes didnt.I think my servos are crazy :) .BTW I connected a capacitor.

I have an idea.Can this error(full left error) occur because of my code that i wrote.too many PAUSEUS may make this error.Should I try DUTYCYLE or PWM codes???

Or Is there any power problem???


Always Place a:

LOW PORTx.y

just before the PULSIN command ...

That's all !

Alain

skimask
- 2nd October 2008, 17:26
Always Place a:
LOW PORTx.y
just before the PULSIN command ...
I've heard you say that a number of times...not bad advice by any stretch...but I'm wondering why I've never had to use it and others seem to have so much trouble with that particular 'gotcha'...

Acetronics2
- 2nd October 2008, 18:16
Hi, Ski

Because you connect thing properly !!! servo before mains ...

just try to plug and unplug your servo with power on the driving circuit ...

you'll get an inverted pulse !!! not every time ... but once is enough for the crash ...

I' ve been caught some years ago ... servos do not like that at all !!!

Alain

skimask
- 2nd October 2008, 20:45
Because you connect thing properly !!! servo before mains ...
just try to plug and unplug your servo with power on the driving circuit ...
you'll get an inverted pulse !!! not every time ... but once is enough for the crash ...
I' ve been caught some years ago ... servos do not like that at all !!!
Alain
Ok, that makes sense... Not the connect things properly, but the 'servo before mains' part. One time is all it takes...

burak450
- 3rd October 2008, 02:29
If you have an oscilloscope look at your control pulses from the PIC to the servo as it moves. If you see that the wave form (1~2ms pulse) is wiggling around or changing amplitude then you have a power supply issue. Do as I suggested above, get a 9v power supply (AC/DC) and use TWO 7805 regulators in parallel for the servo ONLY. At the servo use 470uF across power and ground. Look at the scope again and make sure you see a "cleaned" up signal while servo is in motion.

Nick

I tried everything which is suggested.I changed code and put PAUSEUS before pulsout.Something wrong ,I got same error I decided to change power supply.That can cause this problem.

I hope it will solve my problem...

I will use two servos...(one for left-right one for up-down).I wrote the code just for left-right.I will make servos TWO if I am successful left-right position...

Why did you say two parallel 7805? One for pic and one for servo?

How many 7805 regulators should I use?

skimask
- 3rd October 2008, 03:46
Wow...not reading very well these days...
Doubling up on servo's will only compound your power supply quality problem.
Why did he say 2 parallel 7805's? If you'd re-read post #39, you'll see why.
And while you're at it, you might want to actually READ all of the advice given to you up to this point. Lots of advice being given repeatedly...seems like not a lot of it taken.

Acetronics2
- 3rd October 2008, 07:17
Hi,


Just a little Typo ...

LOW Portx.y

has to be placed before

PULSOUT ... and not Pulsin.

Everyone had understood ... of course !

Alain


PS:



PAUSEUS before pulsout



are you sure ???

burak450
- 3rd October 2008, 10:38
I saw it now.He wrote for servo only....

burak450
- 3rd October 2008, 11:00
A voltage reg will probably need 6.5v++ input voltage. Also, I have driven 4 large servos off of 2 paralleled voltage regs and a low current reg for the pic....no problems at all.

A low current reg?

He said we used large servos and mine is not large but I have to ask it :( because after a hour i will go to buy (9v supply,7805..,)

Should I buy a current regulator?

mackrackit
- 3rd October 2008, 11:13
No current regulator.
What he means is say one 7805 will run the PIC (7805 at best 1 amp) = low current.

Power supply for motors are made from parallel 7805s or some other type to handle the amperage needed.

burak450
- 3rd October 2008, 11:45
No current regulator.
What he means is say one 7805 will run the PIC (7805 at best 1 amp) = low current.

Power supply for motors are made from parallel 7805s or some other type to handle the amperage needed.

thanks a lot i am gonna try it...

hi Acetronics ,

I am sure i changed code like that

motor:
for i=0 to 25
PAUSEUS 20000-(T*10)
PULSOUT PORTC.2,T

next
return

burak450
- 3rd October 2008, 17:42
God bless you guys!

1-I connected 9v 450ma(I hope 450ma is fine) power supply and connected two 7805 paralel and used a 470uf between vdd and vss.Mcu doesnt reset itself and works fine! But I think servo works a little bit slower than past.I dont know why? maybe changing power supply from 5.2 to 5 makes this difference...If its neccessary I can put here its video...

2-I think I finished left-right position and wrote a new code to complete my project.I wrote this
but That doesnt work and servo2(up-down) made some stupid moves (like vibration).Also left-right motion gets very very slower...I know I made too many mistakes.But I learned here this forum too many things that I dont know.Everybody wants to help here and I was a little suprised at the beginning of this Thread.I put my code here.

Can you help me again? t for left-right j for up-down.I bounded "j" between 135 and 115

My code is....





DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE OSC 4
DEFINE ADC_BITS 8 'A/D çevirim sonucu kaç bit olacak
DEFINE ADC_CLOCK 3 'Clock kaynağı (3=rc)
DEFINE ADC_SAMPLEUS 100
SYMBOL F=PORTA.0
SYMBOL G=PORTA.1
alta var byte
usta var byte
altb var byte
ustb var byte
sola var byte
solb var byte
saga var byte
sagb var byte
k var byte
t var byte
i var byte
j var byte
ADCON1=2
TRISA=%00001111
TRISB=0
PORTB=0
TRISC=0
LCDOUT $FE,1
pause 2000
adcin 0,ALTa
ADCin 1,usta
adcin 2,sola
adcin 3,saga

T=150
j=125
yap:




adcin 0,altb
ADCin 1,ustb
adcin 2,solb
adcin 3,sagb






if ((((usta+10)*100)/(ustb+10)))>130 and (not (t>194)) then
T=T+15
endif

if (((alta*100)/altb))>130 AND (not (t<51)) then
T=T-15
endif

if ((((sola+10)*100)/(solb+10)))>130 and (not (t>134)) then
j=j+10
endif

if (((saga*100)/sagb))>130 AND (not (j<116)) then
j=j-10
endif

gosub motor2
gosub motor1








LCDOUT $fe,2,#usta," ",#ustb," ",#altA," ",#altb
lcdOUT $fe,$C0,#T," ",#j

goto yap

motor1:
for i=0 to 25
PAUSEUS 20000-(T*10)
PULSOUT PORTC.2,T

next
return

motor2:
for k=0 to 25
PAUSEUS 20000-(j*10)
PULSOUT PORTC.3,j

next
return

end

mackrackit
- 3rd October 2008, 18:19
The lower the voltage the slower the motor.

Are the values displayed on the LCD what you expect, are they in range?

Macgman2000
- 3rd October 2008, 18:43
Most hobby servo's have a max voltage of 6v. The 450 mA should be OK for testing the servo unloaded.

If you have it turning a platform with large weight/mass then you can easily exceed 1A. A rule of thumb, the closer you get to maxing out the capabilities of your power supply the more noise you will see, especially true with motors, which could lead to glitches. I usually don't go over 50%, if I use a 2A supply for example, I only pull 1A.

Also, decoupling caps are a MUST! use inductors when feeding motors power with custom H-bridges. Use 0.1uf caps to filter out high frequency spikes at the motor and on your power supply to the PIC.

Do a search online for good engineering practice guides for dealing with inductive loads. There are tons of things that will go wrong working with inductive loads, you can solve most of them with well placed caps and careful layout.

Nick

burak450
- 3rd October 2008, 18:44
The lower the voltage the slower the motor.

Are the values displayed on the LCD what you expect, are they in range?


Yes,I think,they are....

I follow t and j values by using lcd...

skimask
- 3rd October 2008, 18:54
Try this...see if it's any faster


DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE OSC 4
DEFINE ADC_BITS 8 'A/D çevirim sonucu kaç bit olacak
DEFINE ADC_CLOCK 3 'Clock kaynağı (3=rc)
DEFINE ADC_SAMPLEUS 100
f var porta.0 : g var porta.0 : alta var byte : usta var byte : altb var byte
ustb var byte : sola var byte : solb var byte : saga var byte : sagb var byte
k var byte : t var byte : i var byte : j var byte : adcon1=2 : trisa=15
trisb=0 : portb=0 : trisc=0 : pause 1000 : lcdout $fe,1 : adcin 0,alta
adcin 1,usta : adcin 2,sola : adcin 3,saga : t=150 : j=125
yap: adcin 0,altb : adcin 1,ustb : adcin 2,solb : adcin 3,sagb
if ((((usta+10)*100)/(ustb+10)))>130 and (not (t>194)) then T=T+15
if (((alta*100)/altb))>130 AND (not (t<51)) then T=T-15
if ((((sola+10)*100)/(solb+10)))>130 and (not (t>134)) then j=j+10
if (((saga*100)/sagb))>130 AND (not (j<116)) then j=j-10
for i=0 to 25 : pauseus 20000-((t*10)+(j*10) : pulsout portc.2,t
pulsout portc.3,j : next i
lcdout $fe,2,#usta," ",#ustb," ",#altA," ",#altb, $fe,$C0,#T," ",#j
goto yap
end

skimask
- 3rd October 2008, 18:54
The lower the voltage the slower the motor.
Are the values displayed on the LCD what you expect, are they in range?

How many extra loops is he executing between servo updates? :D

burak450
- 3rd October 2008, 20:19
thanks for the code.I am sorry it doesnt work properly..

First I get a error and I fixed code in compiler--------pauseus 20000-((t*10)+(j*10) you forgot a parenthesis

Servo stiil slower than usual mode :(

When I worked with your code even j values got out of range...Once I saw j as 195...

I might have another power problem like Macgman2000 said :( or something about code???

You are right above.I have too many extra loops.I am stuck dont know what to do :(

skimask
- 3rd October 2008, 20:25
Servo stiil slower than usual mode :(
Does it speed up if you disconnect one at a time?
The PIC won't (i.e. shouldn't) care if there's 1, 2, or 3, or more servo's plugged in since it's not reading anything back from them.

burak450
- 3rd October 2008, 20:31
Does it speed up if you disconnect one at a time?
The PIC won't (i.e. shouldn't) care if there's 1, 2, or 3, or more servo's plugged in since it's not reading anything back from them.


When I used single servo and used this code.Everything was perfect.Object followed by servo perfecly.(left-right position)




DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 4
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 5
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE OSC 4
DEFINE ADC_BITS 8 'A/D çevirim sonucu kaç bit olacak
DEFINE ADC_CLOCK 3 'Clock kaynağı (3=rc)
DEFINE ADC_SAMPLEUS 100
SYMBOL F=PORTA.0
SYMBOL G=PORTA.1
alta var byte
usta var byte
altb var byte
ustb var byte
ADCON1=2
TRISA=3
TRISB=0
PORTB=0
TRISC=0
LCDOUT $FE,1
pause 2000
adcin 0,ALTa
ADCin 1,usta

t var byte
i var byte
T=150

yap:




adcin 0,altb
ADCin 1,ustb






if ((((usta+10)*100)/(ustb+10)))>130 and (not (t>194)) then
T=T+15
endif

if (((alta*100)/altb))>130 AND (not (t<51)) then
T=T-15
endif


gosub motor







LCDOUT $fe,2,#usta," ",#ustb," ",#altA," ",#altb
lcdOUT $fe,$C0,#T

goto yap

motor:
for i=0 to 25
PAUSEUS 20000-(T*10)
PULSOUT PORTC.2,T

next
return

end


second servo and new code =trouble
Now i unplugged a servo ,left-right position servo stiill slower and worked not properly..

Something wrong about codes you and me wrote....

mackrackit
- 3rd October 2008, 20:54
Swap servos? What happens?

skimask
- 3rd October 2008, 21:08
second servo and new code =trouble
Now i unplugged a servo ,left-right position servo stiill slower and worked not properly..


still slower and worked not properly.
That doesn't tell me much. Is your servo spitting out banana's again? Or is it making breakfast? both of which are not proper actions for a servo...

Macgman2000
- 3rd October 2008, 21:36
OK I have got to ask. What are you moving with your servo? As I said in my previous email, 450 mA is fine for testing UNLOADED servos. Possibly 2 servos. If you are using "standard" size servos then 450 mA is just adequate for turning 1 or 2 without a voltage compression under load. Again.....what are you moving with the servo?

Nick

burak450
- 3rd October 2008, 22:51
This video shows left-right perfect tracking...http://www.dailymotion.com/burak450/video/x6yg0s_one-servo-works-fine_tech

This video shows two servos crazy at the beginning..http://www.dailymotion.com/burak450/video/x6yg1f_sometimes-happens-to-servo_tech

This video shows (when up and down motion)(no vibration in left-right motion) servo vibrates weirdly...http://www.dailymotion.com/burak450/video/x6yfv9_vibration-of-servo_tech

Finally this video shows work of two servos up-down-left-right motion...http://www.dailymotion.com/burak450/video/x6yg05_work-of-two-servo_tech

something like grrrrrrr sound means vibration :)

Vibration when up-down motion and crazy servo at the beginning make problems...

Thats why I said it didnt work (properly! )or well or correctly
I hope I answered all questions with videos...

Macgman2000
- 3rd October 2008, 23:14
OK...just as I thought. Your power supply is not big enough. The other thing is you may need to get a larger servo to hold the turret vertically. The oscillation you see is the servo struggling to hold position and causing voltage dips because it is stalling. Get a 3A power supply from surplus, use several voltage regulators in parallel, filter with caps and get a metal gear servo to hold up the turret, they tend to be more heavy duty.

Nick

burak450
- 3rd October 2008, 23:27
The other thing is you may need to get a larger servo to hold the turret vertically.


I dont think so, it can hold upto 10 kilos....Turret isnt a heavy thing...

Did I understand right?I need to have 9v 3A power supply...

several 7805 ?how many?2 enough?What do you think?

skimask
- 3rd October 2008, 23:36
Did I understand right?I need to have 9v 3A power supply...
Apparently not because we've been telling you and giving you advice to fix your power supply issues for about 50 or 60 posts now...
You may very well have a 9v 3amp power supply right now...but that doesn't mean it's 9v @ 3 amps continuous, maybe a surge of 3 amps, maybe not...
How about a picture of your 'power supply'...

Macgman2000
- 4th October 2008, 00:09
It's not the weight necessarily its the mass. The servo was intended to pull on a throttle cable, or steering linkage etc.... it is not intended to hold up a mass with a lever arm that extends beyond the servo horn rigidly. The metal gear servo's are generally a bit slower and are heavier duty. If you stick to the current servos you will have to gear the turret with a worm gear to keep it from back driving the servo.

You have a few issues to work out in addition to the power supply it seems.

Nick

skimask
- 4th October 2008, 00:13
Good thoughts...
Maybe if that 'turret' was neutrally balanced, the whole thing might perform a lot better.
In the video, it almost looks like it's hanging off the end of a crane arm or something. Kinda like trying to hold onto a concrete block with your arms straight out.

burak450
- 4th October 2008, 00:19
Hi skimask,

Maybe I am always wrong...

Maybe my english isnt good enough...

But I think, it is not shame not knowing it is shame not learning ...

If you wont help me ,dont reply my words please...

When I read your words,I feel like humiliated

Thats all...

mackrackit
- 4th October 2008, 04:26
Hi skimask,

Maybe I am always wrong...

Maybe my english isnt good enough...

But I think, it is not shame not knowing it is shame not learning ...

If you wont help me ,dont reply my words please...

When I read your words,I feel like humiliated

Thats all...
No one is trying to humiliate you. In fact, it looks to me like skimask is giving you a lot of help. Complete code is not help.

Let me ask you to do something. Imagine how hard it is to help someone long distance like this? Sure the code can be posted and looked at easy enough, but what about the hardware that wee can not see or test.

Now think about the kind of person that will tale the time to work through the kind of problems that we see on this forum.

Now think about how you might make the person that is trying to help feel with your last post.

There are many many people here that could help, but only a few that take the time. No wonder there are so few willing to help.

That all said.

Try a battery pack on your servos. If it is noise from the power supply like Nick said, that will stop it.

And like skimask ask, show a picture of you power supply. As you are finding out, power supplies can be tricky.

skimask
- 4th October 2008, 04:28
Hi skimask,
Maybe I am always wrong...
Maybe my english isnt good enough...
But I think, it is not shame not knowing it is shame not learning ...
If you wont help me ,dont reply my words please...
When I read your words,I feel like humiliated
Thats all...

Whoa, hey, back up a bit here... Your English is a lot better than my __________ (insert any language other than English here) and completely understandable (if not a bit grammatically incorrect, but that's ok).
What I'm saying is that you aren't listening very well. We believe the core of the problem to be power issues and you keep talking everything but power issues (i.e. code problems, etc) thinking that your power is infallible, when judging from the problems described, it looks like a power issue...for the last 60-ish posts. How long did it take you to finally add a capacitor?
Think what you want, but in the end, I'd bet on a power supply problem...

burak450
- 4th October 2008, 12:45
Whoa, hey, back up a bit here... Your English is a lot better than my __________ (insert any language other than English here) and completely understandable (if not a bit grammatically incorrect, but that's ok).
What I'm saying is that you aren't listening very well. We believe the core of the problem to be power issues and you keep talking everything but power issues (i.e. code problems, etc) thinking that your power is infallible, when judging from the problems described, it looks like a power issue...for the last 60-ish posts. How long did it take you to finally add a capacitor?
Think what you want, but in the end, I'd bet on a power supply problem...


It's not about not listening,its about not understanding..

Sometimes i dont get what all people said because i dont know too much about power issue...

I appreciated what you did for me up to now..But say your word please more polite...

I swap the servos and tried first program(single servo program) which worked perfect...

But stiill remained vibration on up_down servo.I think thats interesting..

There is no vibration or oscillation whatever you called, on left-right servo...

Is this servo broken? :(

I have to tell you another things...

I connected 9v battery same problems remained...

I tried two parallel 7805 and it makes servo slow because when I tried a single 7805 ,it worked fast...

Thats gonna be a weird question but i want to ask:

Second servo wanna have more current? Or is it broken?

I cant explain why it vibrates...

Finally I tried to connect two servo and tried to work with program which skimask wrote..

Speed was ok but up-down servo vibrated again.Left-right worked well...

I think there is no error in program that you wrote skimask...

But i dont know where the problem is...

mackrackit
- 4th October 2008, 13:07
Try tipping your gizmo on its side, up and down becomes left and right. If that helps then counter balance.

We realy need to see your power supply! Two 7805s slower than one?

Swapping the servos had no change? The up and down servo worked correctly as the left and right servo? If so, the servo is not broken, yet.

burak450
- 4th October 2008, 13:29
I swapped the servos and up-down servo didnt work correctly.It goes up and down but it makes vibriation...maybe that means its broken...

thats my power supply...

http://img161.imagevenue.com/loc633/th_23972_abcedefgf_122_633lo.jpg (http://img161.imagevenue.com/img.php?image=23972_abcedefgf_122_633lo.jpg)


and thats 7805 circuit...

http://img197.imagevenue.com/loc524/th_23491_abcde_122_524lo.jpg (http://img197.imagevenue.com/img.php?image=23491_abcde_122_524lo.jpg)

and thats two servos..

http://img170.imagevenue.com/loc1029/th_23782_abderg_122_1029lo.jpg (http://img170.imagevenue.com/img.php?image=23782_abderg_122_1029lo.jpg)

I think there are two possibilities about my problem
power problem or broken servo...

mackrackit
- 4th October 2008, 16:28
When I say swap the servos, I was meaning physically. If the up/down is used for the left/right, does the left/right action still work.

I I was wanting to see the 7805s in parallel.

But... I still think the problem is power.
The one 9volt 450ma source does not provide enough power for tho whole setup, I think.

That is 450 ma total, yes at 9 volt, start adding two or more 7805s to drop to 5 volt and try to run motors... the amps are just not available.

Do you have another source?

skimask
- 4th October 2008, 16:42
thats my power supply...
I'd get rid of that...and I'd be willing to bet if you hooked up an o'scope to the output under a load, the output would drop off like a rock and just plain look ugly.
You'd be better off with an 8 cell AA NiMH pack of batteries. I would definitely support the load of 2 servos a lot better.
A single 9V battery (the little square ones) or even 2 connected in parallel... That just isn't going to support the load either.


and thats 7805 circuit...
And again, I see the one capacitor across what looks to be the output power and ground lines....ONE capacitor. Are there any more around there? A small cap across Vdd/Vss on the PIC? Another one across Vin/Gnd on the 7805, one across Vout/Gnd on the 7805, one on the main power input? Maybe even one across V+ and Gnd for the servo?
You need more than one capacitor in a circuit for good performance...One somewhere in the circuit isn't good enough.
http://en.wikipedia.org/wiki/Decoupling_capacitor
http://www.repairfaq.org/sam/aapsfaq.htm


I think there are two possibilities about my problem
power problem or broken servo...
Well, you can waste your time by swapping servo's, trying different code, and so on...or you can get a better power supply and start making progress on your project. Your choice...

Macgman2000
- 4th October 2008, 19:06
I hope my explanation is helpful, it may be more than you are looking for but it is good to know why things are as they are.

The servo's you are using is standard size, under light load they draw about 150 mA. If you hang a 6kg weight on a cable and attach it to the servo horn (about 1cm radius) then you are drawing about 500~800 mA. Since in your setup you don't quite have that much weight, what you have is an extended mass, because of inertia the mass will resist moving at the speed that the servo circuitry is setup for. So the servo struggles to draw more current to compensate. This slowing down and speeding up causes current surges and voltage drops. That is why you see the oscillation.

The hobby servos are rated for 4.8v to 6v (grandfathered since NiCd 1.2v/cell). At 6v it will move faster than at 4.8v (0.20s/60 deg compared to 0.16s/60deg). So seeing a slowing down compared to using higher voltage is to be expected.

What test equipment do you have? Oscilloscope? Multimeter? etc...? What country are you in? is it difficult to get 9v @ 3A for example? If it is difficult then Skimask is correct in using NiMh or NiCd, or maybe even sealed lead acid (alarm system battery usually 3~6A)

Nick

burak450
- 5th October 2008, 01:58
First of all I read everything you wrote.I will go to buy a new power supply (9V 3A or more) and will use more caps as soon as possible...I havent got Oscilloscope,i have only a multimeter...

But tonight I found out a new thing...

I wrote a code to test servo broken or not....




TRISC=0
i var byte
BASLA:

for i=0 to 25
PAUSEUS 19500
pulsout PORTC.2,50

next
pause 4000

for i=0 to 25
PAUSEUS 19000
pulsout PORTC.2,100

next
pause 4000

for i=0 to 25
PAUSEUS 18500
pulsout PORTC.2,150

next
pause 4000

for i=0 to 25
PAUSEUS 18650
pulsout PORTC.2,135

next
pause 4000

for i=0 to 25
PAUSEUS 18000
pulsout PORTC.2,200

next
pause 4000


GOTO BASLA
END


I connected first power supply 5.2V 2.5 A without 7805 and saw that...

Servo didnt vibrated at values pulsout 50 and 100 but at 150 and 135 made vibration and finally at 200 didnt make vibration...

Thats its video:http://www.dailymotion.com/burak450/video/x6yuwq_serov-motion-with-52-v-25a_tech

Secondly,I connected power supply 9v 450mA with 7805.Servo came at 50 position and couldnt move 100 and 150 position.I was very very suprised here.After that servo moved 135 position and made vibration!!!!
Finally moved 200 with no vibration!!!

That its video http://www.dailymotion.com/burak450/video/x6yuwk_servo-motion-with-5v-with-7805_tech

What do you think gentlemen?

Broken servo or only power problem???

skimask
- 5th October 2008, 02:09
Tough to hear the servo's in those videos...sure the video is low quality, but I think the audio is more important here...
As far as the servo's vibrating/not vibrating... I think when your servo hit there limits (which is where I hear the constant whining) you won't have any vibration because it can't vibrate.
I think what you really have to do is take those servo's off of that 'turret' and figure out where the limits of those servo's really are so you don't confuse a 'no vibration' condition with a servo that's hit it's mechanical (and/or electrical) limit. A pulse width of 1000-2000us for this servo, might not be good for that servo...or it might be just fine.

burak450
- 9th October 2008, 14:23
Hi guys,

I bought 9v 3.5 A power supply but Only problem that i have "vibration" is still same...

It is so weird,up-down motor vibrates only some values....

I dont know what to do but I think I gotta take off up-down motor...

Maybe these values are limits of servo as skimask said...

I will connect up-down motor to left-right motor with different way so I can use values which didnt make vibration for up-down motion....

Thats the only solution that I can find...

Any other ideas????

mackrackit
- 9th October 2008, 14:39
I bought 9v 3.5 A power supply but Only problem that i have "vibration" is still same...
Have you changed the regulators also? To handle the extra amps...


I will connect up-down motor to left-right motor with different way so I can use values which didnt make vibration for up-down motion....
Have you tried laying the apparatus on it side to see if the up/down servo works correctly?


Any other ideas????Have you tried counter balancing the up/down servo?

Macgman2000
- 9th October 2008, 20:47
Ok we are getting somewhere now. No reset.... Vibration is an indication that the servo is having trouble settling to a position. Mackrackit is pointing you in the right direction, you need to somehow balance the structure or unload it.

Think of a way to keep the weight of the turret from sitting directly on the servo shaft. The shaft of a servo is geared to a potentiometer which means anything that back drives the servo shaft will alter the potentiometer. That leads to vibration (or low level oscillation). The idea is only to use the servo to move, not bear the weight of the structure. Beyond that there is really no more that anyone can do for you, the structure mechanics is the issue now.

Nick

burak450
- 19th October 2008, 11:49
Hello everyone..

I solved the problem.Servo doesnt reset itself now...It was because of code...

Servo doesnt vibrate now..I changed the motor and bought an expensive one.the only problem was my cheap and broken servo...

Thanks everybody who helped me....

skimask
- 19th October 2008, 18:16
Hello everyone..
I solved the problem.Servo doesnt reset itself now...It was because of code...
Servo doesnt vibrate now..I changed the motor and bought an expensive one.the only problem was my cheap and broken servo...
What part of the code did you change to fix the problem?
Broken servo - well, ok, it happens, hasn't happened to me yet, sure, could happen. It's just that everything you suggested pointed right to a power issue.

burak450
- 19th October 2008, 22:25
I think this part what you said....


Look at the loop in your code.
Aboslutely no 'bounds' checking.
What if...T = 0? Then pauseus = 20000, ok no problem...
What if T=2000? Then pauseus = 0, ok not much of a problem...
What if T=2001? Then pauseus = 65526, ok, shouldn't happen because you've got T defined as a BYTE

But...what happens when you try to drive the servo out of it's physical limits?
What happens to the current draw if you hold a servo that's trying to move? Hook up an ammeter and find out real quick. And if you don't have an ammeter, hook up a voltmeter to your 'battery' and try it and see what happens to your voltage...