View previous topic :: View next topic |
Author |
Message |
pYr0
Joined: 10 Apr 2011 Posts: 9
|
Posted: Sun Apr 10, 2011 3:46 pm Post subject: Using BASCOM-AVR and Parallax continuous rotation servos |
|
|
Hello
I am trying to get started in bascom, and my first project involves rotating servos. I tried tweaking the sample code found in the help files in order to get the servo turning, but it doesn't seem to work correctly.
Some info about the servo: Parallax continuous rotation servo, requires an input pulse between 1.3 and 1.7ms, with 1.5 being complete stop. There also needs to be 20ms between pulses.
Info about the microcontroller: AT Mega 8, with an 8mHz internal clock.
Here's the code I'm using so far.
$regfile = "m8def.dat"
$crystal = 8000000
Ddrb = 1
Config Servos = 1 , Servo1 = Portb.0 , Reload = 20
Do
Portb.1 = 1 'test LED to make sure controller is working
Servo(1) = 150 ' THe help file said that this was in units of 10us. 10 * 150 = 1500, or
'what should give me the stop time.
'when run, the servo does nothing, but the light comes on.
Loop
help? |
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Sun Apr 10, 2011 5:23 pm Post subject: |
|
|
try add "Enable Interrupts" just before Do _________________ / Kim |
|
Back to top |
|
|
pYr0
Joined: 10 Apr 2011 Posts: 9
|
Posted: Sun Apr 10, 2011 5:30 pm Post subject: |
|
|
Ok, I put that line in, and the servo rotates. The problem is that it rotates in short spazzes, instead of a continuous turn. Decreasing the last argument in the config servo line decreases the gap time, but for it to be a continuous rotation, the number must go to zero. This gives us a compiler error.
Also, changing the servo() line does not change the speed of the servo at all, when tried with numbers from 75 to 255. |
|
Back to top |
|
|
pYr0
Joined: 10 Apr 2011 Posts: 9
|
Posted: Sun Apr 10, 2011 8:58 pm Post subject: |
|
|
OK, I got it working now. My goof was not noticing that the config servos command was meant for 180 degree servos and not for continuous rotation servos. Instead of using the config command, it's easier to control the servos manually through the waitms/waitus commands.
If anyone cares, here's some working code which can be used to test out these servos. The hardware is the same as described in the OP
$regfile = "m8def.dat"
$crystal = 8000000
Ddrb.0 = 1 'first output port for servo
Ddrb.1 = 1 'second output port for servo
Dim Count As Byte
Do
'**This loop will make both servos turn in opposite directions at full speed**
For Count = 1 To 100 Step 1
Portb.1 = 1
Portb.0 = 1
Waitus 130
Portb.1 = 0
Waitus 40
Portb.0 = 0
Waitms 2
Next
'**This loop will make them both turn in opposite directions at full speed the other way**
For Count = 100 To 1 Step -1
Portb.1 = 1
Portb.0 = 1
Waitus 130
Portb.0 = 0
Waitus 40
Portb.1 = 0
Waitms 2
Next
'This one will make one stop and the other keep going.
'the funny numbers in the wait commands were arrived at experimentally
'and represent the delay in creating the code.
For Count = 1 To 100 Step 1
Portb.1 = 1
Portb.0 = 1
Waitus 148
Portb.0 = 0
Waitus 22
Portb.1 = 0
Waitms 2
Next
Loop |
|
Back to top |
|
|
amidar
Joined: 13 Apr 2009 Posts: 6
|
Posted: Thu Apr 14, 2011 10:50 am Post subject: |
|
|
Of course that someone care.
Me for example !
Thank You so much for this useful tip. |
|
Back to top |
|
|
myblack60impala
Joined: 01 Aug 2006 Posts: 8
|
Posted: Wed May 25, 2011 4:18 am Post subject: RE |
|
|
I never could get the "config servos" code to work either.....
I use the same method to drive a servo on my robot |
|
Back to top |
|
|
pYr0
Joined: 10 Apr 2011 Posts: 9
|
Posted: Wed May 25, 2011 9:24 pm Post subject: |
|
|
Well, here's the thing: there are two types of servos.
The type of servo that the "config servos" command is meant for are the ones that only rotate 180 degrees. These work by sending them a command for turning to a certain angle (i.e. "go to 147 degrees").
This command is not really meant for the continuous rotation servos, which just receive commands telling them how fast to go. So, for the parallax continuous rotation servos, the "config servos" command doesn't work.
I've actually found that it works better to use the pulsout command to control the servos. It's a lot tighter and more percise than dealing with the waitms/waitus commands. I'll upload the code here later once I confirm it working with the robot. |
|
Back to top |
|
|
RobotGuy
Joined: 18 May 2011 Posts: 2
|
Posted: Thu May 26, 2011 3:20 am Post subject: RE |
|
|
I've never got config servos to work either
Not on any servo, continuous or unmodified.
I figured it was a bug in the program or something.
I wish Bascom had better explanations on its code examples, or someone would write a decent book on its use. |
|
Back to top |
|
|
myblack60impala
Joined: 01 Aug 2006 Posts: 8
|
Posted: Thu May 26, 2011 3:37 am Post subject: RE |
|
|
Yup me too, config servos never worked for me on any type of servo.
I also have to add that I've not tried config servos since that project, which was a long time ago. As such I'm a better programmer than I was then. So maybe if I messed with it now I'd have figured it out.
I too had the same complaint with their code examples, but I found these 2 resources that helped me learn the basics:
This page has several goodies:
http://www.qsl.net/pa3ckr/index.html
Here's a good Bascom book:
http://homepages.slingshot.co.nz/~bcollis/ |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu May 26, 2011 9:03 am Post subject: |
|
|
I added to the help that the config servos is intended for the 180 degrees rotation servos. It does not work for any other servo.
I only have these kind of servos. If one knows some info about the full rotation servo's (where to buy, how the protocol works) i can support them as well.
Not so long ago i rewrote the servo code, when you use interval option the new code is used. it works for me without jitter.
you also need to consider that servo support was made kong time ago when the avr did not had all the new timer modes. today you can as well use a timer which does not use software resources.
see it like the software uart : nice for the chips that do not have a uart, but not a good idea when you have a HW uart. _________________ Mark |
|
Back to top |
|
|
|