go away spammer

Author Topic: A math problem in the USB-SERVO2 project  (Read 2223 times)

0 Members and 1 Guest are viewing this topic.

Offline nickTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
A math problem in the USB-SERVO2 project
« on: June 22, 2008, 02:28:54 AM »
Hi I am planning to implement the USB-SERVO2 (http://www.societyofrobots.com/member_tutorials/node/25),
but I found a little problem... do the math here:

1. the ATmega8 uses a 12MHz external oscillator;
2. and the Timer1 for PWM generation sets prescaler at 256 (from source code);
3. the PWM should be at 50Hz;
4. Then the ICR1 (aka topcount) is 486.75 = 12MHz/(2*256*50) -> Decimal?!
what goes wrong??


Offline bens

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 335
  • Helpful? 3
Re: A math problem in the USB-SERVO2 project
« Reply #1 on: June 22, 2008, 03:12:45 AM »
I don't understand what problem you're having.  Are you surprised that you can't acheive exactly 50 Hz when using a timer that's clocked at 46875 Hz?

If you want an exact 50 Hz signal, use Timer1 in phase-correct PWM mode with a prescaler of 8 and a top count of 15000 (or maybe 14999?).

- Ben

Offline nickTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: A math problem in the USB-SERVO2 project
« Reply #2 on: June 22, 2008, 06:47:13 AM »
Thanks Ben.
I am just wondering why it uses 12MHz and 256 prescaler to generate a not-so-accurate top count.
AVR-USB runs fine with 12,16..MHz.

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
    • dunk's robot
Re: A math problem in the USB-SERVO2 project
« Reply #3 on: June 22, 2008, 08:32:41 AM »
Quote
AVR-USB runs fine with 12,16..MHz.
hobby servos don't need to be at exactly 50Hz either. the actual pulse duration has far more effect than the exact frequency.

dunk.

Offline nickTopic starter

  • Beginner
  • *
  • Posts: 6
  • Helpful? 0
Re: A math problem in the USB-SERVO2 project
« Reply #4 on: June 22, 2008, 09:44:27 AM »
Thanks dunk.

 


Get Your Ad Here