PicBasic code for controlling a servo

General Robotics Forum - All aspects of robots and their applications. 

Bookmark this page:  YahooMyWeb Yahoo!  Google Google  Windows Live Favorites Windows Live  del.icio.us del.icio.us  digg digg  Add to Netscape Netscape
Subject Author Date
PicBasic code for controlling a servo Eriswerks 02-12-2006
If you were  Registered and logged in, you could reply and use other advanced thread options
Posted by Eriswerks on February 12, 2006, 10:31 am
I'm a PIC newcomer, and having succeeded in getting that LED flashing,
I've moved on to a servo. I'm having a little trouble with that - it
seems I can only make the servo move toward one of its extremes, and
not back the other way.

I'm using the 16f690 PIC, which is what comes with Microchip's PICKit
2, and programming in PicBasic Pro. I'm guessing that my troubles have
something to do with the special features of this chip, like the
internal oscillator. I've been hunting for some example code for this
chip to learn from, but 90% of what's out there is for the 16f84.

The code below is what I've been using. I would really appreciate
having any glaring errors pointed out to me.

position var byte
position = 150
TRISC=0
PORTC=0

sweep:
pulsout PORTC.5,position
position = position + 1
pause 18
if position > 110 then sweepback
goto sweep

sweepback:
pulsout PORTC.5,position
position = position - 1
pause 18
if position < 190 then sweep
goto sweepback



I've also tried adjusting the pulses to see if I can get a different
movement, but I get the same result every time.


Posted by Eriswerks on February 12, 2006, 7:46 pm
All right, I've been working on this today and have fixed the really
obvious mistake above - "sweep" now says if position > 190, and
"sweepback" says if position < 110. So it should now do something other
than bounce between the two loops - but no, it doesnt. I still get the
exact same result as before: the servo initially moves to one position,
and then just sits there stubbornly, not sweeping in the least. What am
I still missing?


Posted by Dennis on February 13, 2006, 9:07 am
RC Servos are pulse controlled. Usually 1 ms moves to one side and 2 ms
moves to the other extreme. If the servo rotates to one side and stays there
then either the pulses are to short or to long. Depending one which
direction it's moving to. Not familiar with PIC Basic. I usually program in
PIC Assembler. Try different initial values for your position and your max
and min positions.



Hope this helps,

Dennis

www.dseoutdoors.com



> All right, I've been working on this today and have fixed the really
> obvious mistake above - "sweep" now says if position > 190, and
> "sweepback" says if position < 110. So it should now do something other
> than bounce between the two loops - but no, it doesnt. I still get the
> exact same result as before: the servo initially moves to one position,
> and then just sits there stubbornly, not sweeping in the least. What am
> I still missing?
>



Posted by Dale T Stewart on February 16, 2006, 1:14 am
Hi

I don't use BASIC, but there is an online forum for PIC BASIC, just go to
mElabs' website and look for a link. There should be heaps of code
available- do a Google search.

Also, as far as I know there are some commands that are common or at least
similar between PBP and PBASIC used to program the BASIC Stamp. You will
find more PBASIC code around than you can poke a stick at: www.parallax.com,
and the Internet.

Download the free PDF tutorials from the link, there is one on robotics,
which should help Read the documentation that comes with PBP, in the section
that deals with common commands between PBP and PBASIC.

Cheers

|-]


Dale



> I'm a PIC newcomer, and having succeeded in getting that LED flashing,
> I've moved on to a servo. I'm having a little trouble with that - it
> seems I can only make the servo move toward one of its extremes, and
> not back the other way.
> I'm using the 16f690 PIC, which is what comes with Microchip's PICKit
> 2, and programming in PicBasic Pro. I'm guessing that my troubles have
> something to do with the special features of this chip, like the
> internal oscillator. I've been hunting for some example code for this
> chip to learn from, but 90% of what's out there is for the 16f84.
> The code below is what I've been using. I would really appreciate
> having any glaring errors pointed out to me.
> position var byte
> position = 150
> TRISC=0
> PORTC=0
> sweep:
> pulsout PORTC.5,position
> position = position + 1
> pause 18
> if position > 110 then sweepback
> goto sweep
> sweepback:
> pulsout PORTC.5,position
> position = position - 1
> pause 18
> if position < 190 then sweep
> goto sweepback
> I've also tried adjusting the pulses to see if I can get a different
> movement, but I get the same result every time.
>




The site map in XML format XML site map
other useful resources:
Official Robosapien Website
Lego Mindstorms Website

Contact Us | Privacy Policy