Help!newbie!trying to write code(basic)for servo controller

thanks for alla the time you have dedicated…could you please send me a link to download th manual you are talking about?

First menu item in the Help menu of the Basic Micro IDE is the syntax manual…

already have that!!!my dealine is approaching and despite your efforts i haven’t got near the solution.the problem is that i don’t have good knowledge of programming and i do not afford the time to learn it.i read in the manual v2_1 (page 162)that with the pulsout command you can change the polarity of the pulse.how can this be done?

Look at page 163…

This is school work George. You have to learn it. >.<

You have the code format down. You have the analog inputs working and you have the servos working. Have you tried to make changes to the math to see what would happen? It’s not likely you will break anything making changes to the program.

i don’t know what us is and how time affects the polarity of the pulse. i undrerstand that time affects the length of the pulse but nothing else…

i tried the following code and with the first pot it moves both servos [code]pot1 var word
pot2 var word
pot3 var word
buttona var bit

sound 9, [100\880, 100\988, 100\1046, 100\1175]
low 10
low 11
goto start
buttona = in4
if buttona = 1 then start
gosub makepulses
start:
adin 0, pot1
adin 1, pot2
serout S_OUT,i9600, [dec3 pot1\3," "]
pot1 = (pot1* 4)+1000
pot2 = (pot2* 4)+1000
pot3 = (pot3 *4)+1000
gosub makepulses
goto start

makepulses:
pulsout 10, pot1
pulsout 11, pot1
pulsout 12, pot3
return[/code] but i don’t know how to make pot2 have negative value and at the same time change the variables (ie.pot1)in the makepulses

Quick hints:
a) Don’t reuse the variables… that is maybe define pot1/pot2/pot3 to read in the pots… When calculating Pulse widths maybe define some new variables like PulseWidth1, PulseWidth2, PulseWidth3. So when you generate the pulses you are not overwriting the data you need to generate the next data…
Then you can do things like:
PulseWidth1 = (((pot1 + pot2)*2 + 1000) min PULSEWIDTHMIN) max PULSEWIDTHMAX
PulseWidth2 = ((pot1 - pot2)*2 + 1000) min … max…
Where the PULSEWIDTHMIN and PULSEWIDTHMAX are something you need to define that limit the range to something valid…

It goes without saying that you then should change the MakePulses to use the new variables.

b)goto start buttona = in4 if buttona = 1 then start gosub makepulses start:
What is that supposed to do??? A bunch of code that can never execute?

i am supposed to put a switch for on/off after finishing with programming the servos

This code makes 0 to 5vdc pulses…

[code]low 10;servo1
low 11;servo2
low 12;servo3

makepulses:
pulsout 10, switch0
pulsout 11, switch1
pulsout 12, switch2[/code]

This code makes 5vdc to 0 pulses…

[code]high 10;servo1
high 11;servo2
high 12;servo3

makepulses:
pulsout 10, switch0
pulsout 11, switch1
pulsout 12, switch2[/code]

The term uS is micro seconds. The pulse length = time in microseconds. Time has no effect on the polarity of the pulse.

must i debug the program i wrote before downloading it to the bap pro 28?if yes how do i do that?

You simply program the chip and test the results. You can do this over and over, very quickly. This is why it should be very easy to find the right code. It’s really very fast.

Hmmm… Maybe if you used real values…

PULSEWIDTHMIN con 2000 'limits the pulse to 1000uS PULSEWIDTHMAX con 4000 'limits the pulse to 2000uS

A servo responds to pulses from 1000uS to 2000uS where 1500uS is centered.