osc frequency and out put frequncy??

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

What is the relationship between osc frequency and frequency out put on avr pins?

ex:

for generate 500Hz,Which crystal is appropriate?(ATmega8A).

thanks.

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

It all depends on how you intend to generate the output freq - , bit banging or timer output

 

bit banging depends on the number of CPU clock cycles your code uses & the period of those CPU clock cycles

 

Timer output depends on the timer clock frequency & how the timer is configured.

 

full details can be found in the datasheet

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

mostafa147 wrote:

...for generate 500Hz,Which crystal is appropriate?(ATmega8A).

 

To generate EXACTLY 500Hz you need a crystal whose frequency is an EXACT multiple of 500Hz.

 

HOWEVER, it's very rare in the real world to need an exact frequency unless you are making high precision test equipment. In the real world you will have tolerances. What tolerance does your 500Hz frequency have?

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Brian Fairchild wrote:
To generate EXACTLY 500Hz you need a crystal whose frequency is an EXACT multiple of 500Hz.

Preferably, a power-of-two multiple.

 

HOWEVER, it's very rare in the real world to need an exact frequency unless you are making high precision test equipment.

In which case, you'd probably use a dedicated oscillator ... ?

 

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

Well, as mentioned above, if your micro's Xtal is a multiple of 500 Hz then it is easier to get a pretty accurate output signal.

 

If you can tolerate < 1 uSec jitter for the loop, and the micro doesn't have to do anything else, (LCD display, user push button switches, etc.,), then the code is only a few lines:

 

...
$clock = 10000000 '10MHz, for example
...
Config I/O pin here
...

Main:
 do

  Set SignalPin
  waitus 1000 '1/2 Period High
  
  Reset SignalPin
  wait1000 '1/2 Period Low
 
loop   'Forever

 

Otherwise, have a look at the Timer/Counter and setting it up in CTC mode to generate an interrupt every 1/2 Period.

Inside the Interrupt Service Routine you toggle the I/O pin to generate your signal.

 

There is a Tutorial or two on Interrupts in another sub-Forum on this site.

 

JC

 

Edit:Typo