MCU crystal question - Page 1
Forum section: electronics / projects

author: c4757p
author_rank: Super Contributor
timestamp: March 23, 2013, 07:42:32 pm
content: I am designing a system which has two microcontrollers. The slave needs to have its own crystal, but sometimes, the master needs to be able to send it a clock signal instead. This will not be "forced" - the master will not transmit a clock when the slave oscillator is running.1) Is is possible to just do this directly, by having an pin on the master that is normally high impedance, connected to slave OSCI, and just switch it to an output and directly transmit the clock? Will the low-impedance drive be able to overpower the resonance of the crystal and avoid having massive ringing? (It's a slow clock - less then 1 MHz - so adding a series resistor to limit the edges would be possible)2) If that won't work, can an analog switch be put between the slave and its crystal without having too much of an effect on it?I'd breadboard it, but I'm afraid the parasitics of the breadboard system will make it behave differently than on the PCB.(Background: I am designing an AVR development board, mostly for myself, with a bunch of integrated functions, one of which is an HV parallel programmer - I have a stupid tendency to screw up the fuses on AVRs and I want an easy way to reset them in-system.)

author: hlavac
author_rank: Frequent Contributor
timestamp: March 23, 2013, 08:03:14 pm
content: You could do it by programming the slave to use external clock, use crystal oscillator instead of crystal, and simple logic gate multiplexor to select the clock source.You may want to be careful about the transitions if they don't include reset of the slave - you may get some nasty shortened clock cycles

author: c4757p
author_rank: Super Contributor
timestamp: March 23, 2013, 08:12:16 pm
content: I wish it were as easy as muxing it with an oscillator, but I want this board to be as general-purpose as possible. One of the main design goals is for the chip in the dev board to be able to be configured identically to how it would be in a finished system, and that includes clock settings. I want to be able to prototype something with this board, then take the entire firmware and configuration straight to the final version.Quote from: hlavac on March 23, 2013, 08:03:14 pmYep, they always will include a reset, since the only point of the external clock is parallel programming mode.Maybe I will "breadboard" this, but eliminate parasitics by doing it dead bug style.

author: hlavac
author_rank: Frequent Contributor
timestamp: March 23, 2013, 08:21:06 pm
content: Are you going to switch crystals, or are you just trying to emulate crystal for mcu configured for crystal oscillator?Latter shoud be relatively easy...

author: c4757p
author_rank: Super Contributor
timestamp: March 23, 2013, 08:33:43 pm
content: I want to have a real crystal - obviously, the frequency can be important, and I don't exactly want to get into frequency synthesis on what ought to be a simple dev board - but I want to be able to switch it out for an external clock when parallel programming mode is active.One thing that I did consider is to put the crystal socket at themasterand have it then output its clock to the slave, but some of the functions of the master are frequency dependent and I don't want the firmware complexity of a variable clock frequency.(Edit: The "obvious" solution is to just require that the crystal be removed from the socket before programming. If there is a decent electronic solution I'd rather use it - I'd like the entire process to be automated - but I can always resort to that if necessary)

author: c4757p
author_rank: Super Contributor
timestamp: March 24, 2013, 12:05:34 am
content: Follow-up: Putting the crystal behind an analog switch works perfectly fine. I used an HEF4051 because I had it on hand (the dev board will use 74HC4066), and paid practically no attention to "proper layout". The frequency dropped by 0.1%, probably just due to the added series inductance of the wires on the breadboard (though I kept them short), which is well within the realm of "who cares?" for this application.Also, the speed at which a basic 74HC00 crystal oscillator will run when there is no crystal attached is quite incredible.