PIC _XT_OSC mode

Thread Starter

peter_morley

Joined Mar 12, 2011
179
I have a stand alone 4 pin 20 MHz oscillator (full circuit inside box) attached to the pin to the CLOCKIN (pin 2) of my PIC 12F675. I originally had my CONFIG word setup to _INTRC_OSC_NOCLKOUT and my program worked fine. I wanted to increase the internal clock speed to about 20 MHz so I took out the _INTRC_OSC_NOCLKOUT and replaced it with_XT_OSC and added the 20 MHz clock output to pin 2. Now I don't get any oscillations on my output pins after the simple change. Here is the code, what is wrong?
Rich (BB code):
list      p=12f675            ; list directive to define processor
#include <p12f675.inc>        ; processor specific variable definitions

	__CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC 
 
;*************************** REGISTERS ********************************

cblock	0x20
	PixelCounter						; file location PixelCounter will contain number of loops
	HsyncCounter						; file location HsyncCounter will contain number of loops
	VsyncCounter						; file location VsyncCounter will contain number of loops
endc

;*************************** CONSTANTS ********************************	

#define Bank0		banksel 0x00		; first registerr bank = Bank 0
#define Bank1		banksel 0x80		;second register bank = Bank 1
#define Blank		B'00000000' 		; All LEDs off
#define ConfigTRI	B'00111000'			; Configure I/O


;******************** INITIALIZATION PROTOCOL **************************

	org     0x000				; BIG BANG
	goto	Initialize			; Initialization call
	org		0x005				; Start of Programm Memory Vector

Initialize

	Bank0						; Bank 0 located at 0x00h
	clrw						; clear w register
	movlw 	06h					; move integer 118 to w register making 118 pixels drawn per line
	movwf	PixelCounter		; move contents of w register to PixelCounter register location
	movlw 	30h					; move integer 118 to w register making 118 lines drawn per screen
	movwf	HsyncCounter		; move contents of w register to HsyncCounter register location
	movlw 	3Ch					; move integer 60 to w register making 60 screens per second
	movwf	VsyncCounter		; move contents of w register to VsyncCounter register location

	clrf 	GPIO 				; clear GPIO
	movlw 	07h 				; move 07h into w register 
	movwf 	CMCON 				; move contents of w register to CMCON register location
	movlw	B'00000011'			; set GPIO 0,1 to make both waveforms start at the same time
	movwf	GPIO				; move value in w to register GPIO
	
	Bank1						; Bank 1 located at 0x20h
	clrw 						; clear w register		
	clrf 	ANSEL 				; clear ANSEL register which controls analog or digital configuration making DIGITAL	
	movlw 	ConfigTRI 			; loads constant ConfigTRI
	movwf 	TRISIO 				; loads w register into TRISIO register which assigns I/O for GPIO pins

	Bank0						; return to Bank0 address

Main
	bcf		GPIO,0				; clear GPIO 0 to increment pixel position 
	bsf		GPIO,0				; set GPIO 0 to draw new pixel at next location
	decfsz	PixelCounter		; decrement counter and skip goto Main when pixelcounter reaches end of line
	goto 	Main				; return loop
	bcf		GPIO,1				; clear GPIO 1 to increment line position
	bsf		GPIO,1				; set GPIO 1 to allow pixel drawings at that line
	movlw 	06h					; store value 118 into w register 
	movwf	PixelCounter		; store w register into PixelCounter so we can draw 118 more pixels on a new line
	decfsz	HsyncCounter		; decrement counter and skip goto Main when HsyncCounter reaches end of line time
	goto	Main				; return loop
	bcf		GPIO,2				; clear GPIO 2 to start at the top of the screen
	bsf		GPIO,2				; set GPIO 2 to allow pixels to be drawn
	movlw 	30h					; store value 60 into w register 
	movwf	HsyncCounter		; store w register into HsyncCounter so we can draw pixels on 118 new line
	decfsz	VsyncCounter		; decrement counter and skip goto Main when VsyncCounter reaches end of screen
	goto	Main
	movlw 	3Ch					; store value 60 into w register 
	movwf	VsyncCounter		; store w register into VsyncCounter so we can restart at the top of the screen
	goto	Main
 

Potato Pudding

Joined Jun 11, 2010
688
The XT OSC function is meant to drive a bare crystal.

It sounds like you have an external clock input instead, because your crystal oscillator box has drive circuitry included.
 

Potato Pudding

Joined Jun 11, 2010
688
My apologies. I still haven't cured myself of a bad post first check later habit.

You can use XT_OSC to set up the chip for an external clock.

From the Datasheet in section 9.2.3 the only thing they warn you about is to make certain that the clock signal meets timing specifications. They also show in Figure 9.2 that you must leave the clockout pin OPEN if you have an External clock.
 

debjit625

Joined Apr 17, 2010
790
You will need something like this with only two pins...

or


Or you may post a bit more about your oscillator like any datasheet or any part/model number.

Good Luck
 

ErnieM

Joined Apr 24, 2011
8,377
You are currently setting the oscilator type to external Crystal/resonator by using the _XT_OSC setting.

You shold change this to _EC_OSC which is described as:

EC: I/O function on GP4/OSC2/CLKOUT pin, CLKIN on GP5/OSC1/CLKIN

The CLKIN will allow your external clock to "get internal."
 

ErnieM

Joined Apr 24, 2011
8,377
Wow, 3 cross posts is a record for me.

Making the software match the hardware is usually the simplest way out. Here is is the mere substitution of two letters.
 

Potato Pudding

Joined Jun 11, 2010
688
Other things to check.
You need to have a higher voltage with increased frequency.
If you were running the chip at 4.5 Volts or less then the Frequency would probably need to be lower.
Have you tried configuring the chip for EC (External Clock) or HS (High Speed) Oscillator mode instead of XT?
External Clock frees the Clockout Pin for use as an I/O.

You may need to buffer your clock.
 

Thread Starter

peter_morley

Joined Mar 12, 2011
179
I changed my config word to _EC_OSC and i'm still not getting any good results. I tried other oscillators with different ranges and they were all cmos compatible but still no oscillations on the pins.
You may need to buffer your clock.
How would I go about buffering my clock? A capacitor?

One thing I possibly overlooked is setting the OSCCAL register?
Do I need to configure it to get _EC_OSC to work properly?
 

ErnieM

Joined Apr 24, 2011
8,377
OSCCAL is only used when using the internal oscillator, it has no effect for external clock sources.

Peter, does it still work (albeit slower) if you drop back and use the internal oscillator?

Do you have a scope to check that your external oscillator is really working?

The buffer Potato refers to is an amplifier, but any package oscillator should be able to drive one CMOS gate just fine as it is. Don't put a cap there.

This IS a digital output oscillator, right? Not a sine wave or such?
 

Thread Starter

peter_morley

Joined Mar 12, 2011
179
Well I can't confirm whether they are digital or analog because I don't have a scope hmmmm.

There is a letter coding on it that includes the letter D. I'm not sure if this D means it is digital or not.

Why can't the PIC take an analog clock?
 
Top