0
\$\begingroup\$

first of all this is for an assignment so I have certain limitations, mainly cost. The problem I'm having is I have run out of PWM inputs on my ATtiny45 but I still want to drive a servo. The two PWM outputs are taken up driving two motors. This servo would only have to sweep from left to right and back smoothly constantly to allow me to take reading at different angles off a sensor attached to the arm.

Is there a way I can use a 555 timer to sweep a PWM signal to control the servo? My idea would be then to smooth out this PWM signal to read it as Analogue signal on one of the inputs of the ATtiny45, thus reading the angle. In reality this servo is doing something quite 'dumb' so shouldn't really need a micro controller driving it.

As I said, this is for an assignment so don't give me too much detail, but any pointers on this scheme or suggestions to give me more PWM capability would be greatly appreciated. :)

\$\endgroup\$
  • 1
    \$\begingroup\$ A second ATtiny? \$\endgroup\$ – Scott Seidman Apr 16 '16 at 19:13
1
\$\begingroup\$

A 555 can generate servo pulses, but to 'sweep' the pulse width you would need a second 555 (or a 556, or some other circuit that produces a triangle wave). Then to smooth the 50Hz pulse frequency sufficiently for accurate A/D conversion you need to integrate it with a long time constant, so the response time will be slow.

If you still have a digital output available then it might be easier (and cheaper!) to just generate the servo pulse in software. Set up a 20ms timer interrupt and create the 1~2ms pulse using a software delay loop inside the ISR.

The servo pulse timing has to be accurate to within a few microseconds, but most servos can handle quite wide variation in repetition rate (at least 15~25ms) so the 20ms timer doesn't have have to be precise. If for some reason you can't use interrupts you might still be able produce pulses with the required repetition rate in the foreground, eg. by padding out your main loop execution time to ~20ms.

\$\endgroup\$
  • \$\begingroup\$ Yes, use a global variable that the ISR code can access for setting the pulse width. The main program then controls where the servo moves to. Actual deflection angle depends on the particular servo brand/model (typically 90~120º for 1~2ms), and may be clockwise or counterclockwise. \$\endgroup\$ – Bruce Abbott Apr 16 '16 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.