Weekend project: using the event system of the tiny1614 to create a full swing crystal oscillator

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

This is something I've been thinking about for a while, since the new xtinies only support a 32kHz crystal.

However, they do have the event system and the custom logic peripherals, so I though, can I make a crystal driving circuit from these?

The answer is yes, and in fact only the event system is neededsmiley

Using another feature, the inverter present on each I/O pin, I just connected an inverted input to the event system output. I attenuated the event system output with a 33 ohm resistor to drive the crystal, and also the external clock input.

Source code:

 

#include <avr/io.h>
#define F_CPU 20000000UL/6
#include <util/delay.h>

int main(void)
{
	// Use the Event System to create an asynchronous hardware inverter
	// Propagation delay of the inverter is about 10-15 ns
	// Input:	PA1 (in inverted configuration)
	// Output:	PA2 (Event System output 0)
	EVSYS.ASYNCCH0 = EVSYS_ASYNCCH0_PORTA_PIN1_gc;
	EVSYS.ASYNCUSER8 = EVSYS_ASYNCUSER8_ASYNCCH0_gc;
	PORTA.DIRSET = 1 << 2;
	PORTA.PIN1CTRL = PORT_INVEN_bm;
	PORTMUX.CTRLA = PORTMUX_EVOUT0_bm;
	
	// Wait a few ms and switch to external clock
	_delay_ms(64);
	CCP = CCP_IOREG_gc;		// Load protection key to access clock registers
	CLKCTRL.MCLKCTRLA = CLKCTRL_CLKSEL_EXTCLK_gc;

#	define RESCALE 18.432/20

	// Blink LED on PB2 for testing
	PORTB.DIRSET = 1 << 2;
	while(1) {
		_delay_ms(500 * RESCALE);
		PORTB.OUTTGL = 1 << 2;
	}
}

This is the circuit I used to drive a 18.432MHz crystal:

After all is set, the tiny can change the clock input to the external clock signal originating from the crystal circuit, and yes, all is working fine and the LED blinks at 1 Hz.

 

note: the capacitors were not carefully selected, just what I had available on the junk bin...

 

edit: there was a bug in the code, setting F_CPU to a new value has no effect. Now it's ok.

Last Edited: Sun. Aug 19, 2018 - 10:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Interesting, but a little risky... as that likely still clocks when you unplug the crystal, and might not snap-back when you re-insert the crystal.

For commercial use, it's safer to use an Oscillator module, (sub 50c these days in modest volumes) or a 1GU04 unbuffered gate ?

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

I would have looked at the programmable logic block as you want as little additional "delay" (other than the intentional inversion), as possible. Provided, of course, that you can source the system clock from there. 

 

As who-me points out, it would be important to check whether or not your design "oscillates" without the crystal and whether or not it locks back to the crystal frequency when the crystal is reconnected. You want it stable when there is no resonant feedback, and unstable (oscillates) at the feedback frequency when feedback it connected. You should not need the 33 ohm resistor. High frequency crystals will tolerate much higher drive levels than tuning-fork low frequency ones.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Just tested unplugging the crystal, yes, it oscillates (at a much lower frequency). It recovers when the crystal is inserted back.

Anyway, this was just an experiment, it's not meant to be used in actual production, unless, maybe Microchip tests it thoroughly and writes an app note wink

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

Not surprised at low frequency oscillation without crystal. Would be much more concerned if it was within, lets say, 25% of the expected crystal frequency. I don't take that as a big deal. 

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net