PicBasic code for controlling a servo

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.

Reply to
Eriswerks
Loading thread data ...

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?

Reply to
Eriswerks

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

formatting link

Reply to
Dennis

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:

formatting link
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

Reply to
Dale T Stewart

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.