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

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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): 

Last Edited: Mon. Feb 12, 2018 - 04:10 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks for the comments.

 

working on the 16-bit timer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is the corrected write up. 

Fixed the formulas as noted by avrcandies

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is "ATMEGA3280B Xplained mini" a correct part number?

 

And "XHT900" isn't...

 

Ross McKenzie ValuSoft Melbourne Australia