## [TUT] ATMEGA328PB, 8-bit timer, servo, pwm, HXT900

5 posts / 0 new
Author
Message

This tutorial explains how to use the 8-bit timer on the ATMega328PB to drive a servo. The 328PB 8-bit timer has 2 control registers. OCR0A can be used to adjust the frequency while OCR0B is used to adjust the pulse width.

4 attachments, a description and 3 programs.  The 8bit.PDF is reposted in #4 below.  Fixed the Formulas.

## Attachment(s): 8bit.pdf M328PBservo8a.c M328PBservo8b.c M328PBservo8c.c
Last Edited: Mon. Feb 12, 2018 - 04:10 AM

Very nice & informative....Only issue might be a source of contention for the reader: A*B/C is A times B then divide by C  (so 3*10/5=6). Likewise, A/B*C  is A divided by B then mult by C (so 10/5*2=4  not 1)...you could write A/(B*C) or simply A/B/C to get there (10/(5*2)=1, 10/5/2=1)

So you'd need Freq=Fclk/N/cnt  or Fclk/(N*cnt).   The numerics in the tutorial were calculated using this, though not described as such.

It would be nice to see it also done with the 16 bit timer to compare how much better resolution can be had

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

working on the 16-bit timer

Here is the corrected write up.

Fixed the formulas as noted by avrcandies

## Attachment(s): 8bit.pdf