0
\$\begingroup\$

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?

\$\endgroup\$
  • 2
    \$\begingroup\$ In what shape exactly do you need your 1 MHz clock, and your 8MHz clock? I'm not deep enough into the atmega family, but you can probably do the 1MHz with a PWM unit. \$\endgroup\$ – Marcus Müller Dec 19 '17 at 11:33
  • 2
    \$\begingroup\$ Completely a non-answer, but you might want to consider a clock generator chip with I2C interface. \$\endgroup\$ – Spehro Pefhany Dec 19 '17 at 12:51
0
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ PWM? I think you mean PLL. \$\endgroup\$ – Curd Dec 19 '17 at 11:49
  • \$\begingroup\$ no, actually not, @Curd. OP's (as far as I can tell) running with a system clock of 20 MHz, so 1MHz would simply be a PWM unit that counts from 20 down to 0 and inverts an output halfway through that. \$\endgroup\$ – Marcus Müller Dec 19 '17 at 11:55
  • \$\begingroup\$ Why not just use then counter/timer to generate a clock divided by 2? \$\endgroup\$ – Curd Dec 19 '17 at 14:52
  • \$\begingroup\$ a counter / timer module == PWM unit, usually. \$\endgroup\$ – Marcus Müller Dec 19 '17 at 14:59
  • 2
    \$\begingroup\$ call it what you will – the datasheet calls it "8-bit Timer/Counter with PWM", so I think none of us is especially right or wrong - I'd call any timer with a counter and a compare unit a PWM unit anytime, because it has all the features of a PWM unit. \$\endgroup\$ – Marcus Müller Dec 19 '17 at 15:09
0
\$\begingroup\$

You might also consider this chip

https://www.renesas.com/us/en/www/doc/datasheet/82c54.pdf https://www.digikey.com/products/en?keywords=CP82C54

Feed it with 8, 10, 12 MHZ clock, program it to output desired frequency.

\$\endgroup\$
  • \$\begingroup\$ Now that's a blast from the past. \$\endgroup\$ – Richard the Spacecat Feb 14 at 14:57
  • \$\begingroup\$ Still available - I just designed a board with 16 of them for 48 clock outputs. \$\endgroup\$ – CrossRoads Feb 14 at 15:00
  • \$\begingroup\$ Okay, interesting chip - thanks for the suggestion (shame it's so expensive!) I sorted this issue well over a year ago, btw, as I got to grips with the ATmega and used two PWM outputs with 50% duty cycle in the end. \$\endgroup\$ – nockieboy Feb 14 at 18:38

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.