PDA

View Full Version : Servo loosing my mind...



geckogrotto
- 25th June 2007, 03:03
Ok I'm loosing my mind here!

The code below works fine sorta.


@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
DEFINE OSCCAL_1K 1
INCLUDE "modedefs.bas"
TRISIO.0 = 0 'Set GPIO.0 to output.
ANSEL = 0 'disable ADCs
CMCON = 7 'disable comparator
T1CON = %00000110
ANSEL.1 = 0 'Set GPIO.1 to digital
Pulselen Var byte
ValidCode Var byte
I var byte
clear

goto main


Main:
validcode=200
If validcode=200 then
for I = 1 to 20
Pulsout GPIO.0, 200
next I
endif

validcode=0

goto main




Whats happening is I compiled it and have a hex file. I load it into flash kit starter, came with my pic kit V1

I burn a chip
12F675 and half the time it sends out a .005ms pulse instead of a 2 ms pulse.
If I take the same chip reburn it, it works maybe if not reburn it and it works...

What am I doing wrong here that sometimes works perfectly and others not? I'm using the same hex file...

Any ideas?

HenrikOlsson
- 25th June 2007, 07:35
Hi,
What is it you want the code to do?
You have a FOR-NEXT Loop with PULSOUT but you dont have any PAUSE in there so basicly there will be 20 2mS pulses right after each other with very little time between them. These 20 pulses will be present on the pin for roughly 40mS and then they will stop because you set Validcode to 0 after 20 pulses. So is it possible that you miss seeing the pulses all together?

HTH

/Henrik Olsson.

geckogrotto
- 25th June 2007, 07:44
Thanks for the reply. What I was acutally tying to accomplish is a servo pulse of 2mS that should repeat every 20mS.
This should basically be a full one way signal for a servo.

I realize now that I didn't have a delay but still when I hook this to my scope


for I = 1 to 20
Pulsout GPIO.0, 200
pause 18
next I

I don't get a nice clean 2mS square like I see from a known servo signal.

skimask
- 25th June 2007, 07:52
Why not just use a plain ol' pause statement for the testing part of your project? It'll at least eliminate the possibility of pulsin causing your problem.


main:
gpio.0 = 1
pause 2
gpio.0 = 0
pause 2 (then switch it over to 18 after you've verified a good square wave)
goto main

It's basically the same ol' blinky led program, but it'll get the ball rolling...

HenrikOlsson
- 25th June 2007, 09:46
Hi,
Yes but you will still only get 20 pulses because of the FOR-NEXT lopp. What if you try this:


GPIO.0 = 0
Main:
Pulsout GPIO.0, 200
pause 18
Goto Main


/H.O

George
- 26th June 2007, 03:27
are you scoping it with the servo connected? Servos can put out some pretty nasty noise when running - and need to be seperatly regulated and filtered

BrianT
- 26th June 2007, 06:57
Yes you need a pause to pace the servo pulses to approximately 50 per second. In addition, note that Pulsout is only a toggle. Unless you force the pin to a zero at the start of the loop, there is a good chance that sometimes the line will idle high instead of idling low. That drives a servo nuts.

Try
for i = 0 to 20
low servopin
pulseout servopin, 200
pause 18
next i

Note that 95+% of the time you may get away without forcing the servopin low but there WILL be times when the line idles high. It cost me a plane crash.

HTH
Brian

fazan83
- 27th June 2007, 05:57
Geckorotto do you connect the servo directly to batteries or you use a LM7805 regulator?

for I = 1 to 20
Pulsout GPIO.0, 200
pause 18
next I

This code should work fine. Sometime servo become nut because of the current is not enough.

That is base on my experience.