Author Topic: PWM not as expected  (Read 1551 times)

0 Members and 1 Guest are viewing this topic.

Offline WebbotTopic starter

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 109
PWM not as expected
« on: April 10, 2008, 07:14:13 PM »
Referring to the 'old' post
http://www.societyofrobots.com/robotforum/index.php?topic=1827.msg12082#msg12082
Then this all makes sense and seems like a sensible way to set servo motor speeds if you only have 2 motors.

However; if I use Admins 'hold_a_servo.hex' file then my servos (Hitec HS322HD) are all correctly centered but with the above link then I need to adjust the 'ZERO' position from 1500ms to around 1262ms Why is this - as it makes no sense?  I have other timer interrupts going on in the background but all they do is increment a global 'unsigned long int' so are quick and shouldn't effect the PWM which, presumably, is going on in the background.


Admin:- it would be great if you could release your 'hold-a-servo' code, be it ASM or C as it is a 'reference point' when it comes to mechanics


Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: PWM not as expected
« Reply #1 on: April 24, 2008, 06:51:35 PM »
All my code does it turn on a port, wait a specified amount of time, then turns off that port. Open up the photovore_V1.c code, and replace the while loop to look like this:

Code: [Select]
while(1)
{
servo_left(33); //modify this number to change center
delay_cycles(20000); //servos can only receive commands every ~10-20ms minimum
}

Compile and upload it, and you got yourself servo center code.

The exact time could be off a bit due to voltage differences, manufacturing differences, room temperature, etc. Also, I just guessed it when I did it - was too lazy to make it perfect ;D

Offline WebbotTopic starter

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,150
  • Helpful? 109
Re: PWM not as expected
« Reply #2 on: April 25, 2008, 05:36:41 AM »
Ok thanks.

The reason for my questions was I had (wrongly) made the assumption that your 'hold a servo' code was in assembler language since, that way, you can calculate the exact number of instructions and hence cycles. Whereas, in C, the generated code is different depending on the compiler optimisation setting you use. The most extreme case I've seen is that the compiler realises you are just decrementing a parameter value so no global variables are changed and no value is returned so it replaces the whole delay routine with a return statement !!

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: PWM not as expected
« Reply #3 on: April 25, 2008, 07:16:35 AM »
Yea, on the $50 Robot, for this exact reason optimization is turned off (specified in the make file).

I did this particular servo timing technique so that the timer is available for other tasks.

 


Get Your Ad Here