Electronic – ATmega328 – two clock outputs

clock

I'm using an ATmega328P to provide a software-selectable 2, 4 or 8 MHz clock to my home made SBC. This works just fine. However, I am adding a programmable sound generator (PSG) to the board and it requires a 1-2MHz clock.

I want to keep the board simple and avoid flip-flop clock dividers and output selects due to the variable system clock speed, so I was hoping I could configure the ATmega328P to provide a second (non-variable) 2 MHz clock for the PSG.

Problem is, I'm not experienced with AVRs and their timer fuses and don't even know if this is possible with the ATmega328P? If it is, how can I set up another pin to and its timer to provide the 2 MHz clock signal?

Bonus (almost unrelated) question: Can a 20 MHz AVR provide an 8 MHz clock pulse, as it's not a factor of 20?

EDIT: Just to clarify a couple of points:

1) The ATmega328 is running at 16 MHz. I'm using one clock/timer output to produce the required 8 MHz clock I need for the main board.

2) I need a separate (but ideally in-step with the 8 MHz clock) 2 MHz clock for the PSG. I was hoping to be able to set up another clock output from the ATmega328?

Best Answer

I'm not deep enough into the atmega family, but you can probably do the 1MHz with a PWM unit. These are programmable, so you can adjust them to varying system clocks if necessary.

The 8 MHz will be harder, but if you can generate integer factors of 20 MHz:

  • generate 4 MHz square wave
  • convert square wave (which has a lot of odd order harmonics) to sine wave with very simple RC or LC low pass filter
  • rectify sine wave » signal with frequency content at twice the sine's frequency (amongst others)
  • filter rectified sine wave to only contain the desired 8MHz sine wave
  • use comparator or Schmitt trigger to convert sine wave to square wave, if latter is desired