PIC _XT_OSC mode

Discussion in 'Embedded Systems and Microcontrollers' started by peter_morley, Aug 17, 2011.

  1. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    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?
    Code ( (Unknown Language)):
    1.  
    2. list      p=12f675            ; list directive to define processor
    3. #include <p12f675.inc>        ; processor specific variable definitions
    4.  
    5.     __CONFIG   _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
    6.  
    7. ;*************************** REGISTERS ********************************
    8.  
    9. cblock  0x20
    10.     PixelCounter                        ; file location PixelCounter will contain number of loops
    11.     HsyncCounter                        ; file location HsyncCounter will contain number of loops
    12.     VsyncCounter                        ; file location VsyncCounter will contain number of loops
    13. endc
    14.  
    15. ;*************************** CONSTANTS ********************************
    16.  
    17. #define Bank0       banksel 0x00        ; first registerr bank = Bank 0
    18. #define Bank1       banksel 0x80        ;second register bank = Bank 1
    19. #define Blank       B'00000000'         ; All LEDs off
    20. #define ConfigTRI   B'00111000'         ; Configure I/O
    21.  
    22.  
    23. ;******************** INITIALIZATION PROTOCOL **************************
    24.  
    25.     org     0x000               ; BIG BANG
    26.     goto    Initialize          ; Initialization call
    27.     org     0x005               ; Start of Programm Memory Vector
    28.  
    29. Initialize
    30.  
    31.     Bank0                       ; Bank 0 located at 0x00h
    32.     clrw                        ; clear w register
    33.     movlw   06h                 ; move integer 118 to w register making 118 pixels drawn per line
    34.     movwf   PixelCounter        ; move contents of w register to PixelCounter register location
    35.     movlw   30h                 ; move integer 118 to w register making 118 lines drawn per screen
    36.     movwf   HsyncCounter        ; move contents of w register to HsyncCounter register location
    37.     movlw   3Ch                 ; move integer 60 to w register making 60 screens per second
    38.     movwf   VsyncCounter        ; move contents of w register to VsyncCounter register location
    39.  
    40.     clrf    GPIO                ; clear GPIO
    41.     movlw   07h                 ; move 07h into w register
    42.     movwf   CMCON               ; move contents of w register to CMCON register location
    43.     movlw   B'00000011'         ; set GPIO 0,1 to make both waveforms start at the same time
    44.     movwf   GPIO                ; move value in w to register GPIO
    45.    
    46.     Bank1                       ; Bank 1 located at 0x20h
    47.     clrw                        ; clear w register     
    48.     clrf    ANSEL               ; clear ANSEL register which controls analog or digital configuration making DIGITAL   
    49.     movlw   ConfigTRI           ; loads constant ConfigTRI
    50.     movwf   TRISIO              ; loads w register into TRISIO register which assigns I/O for GPIO pins
    51.  
    52.     Bank0                       ; return to Bank0 address
    53.  
    54. Main
    55.     bcf     GPIO,0              ; clear GPIO 0 to increment pixel position
    56.     bsf     GPIO,0              ; set GPIO 0 to draw new pixel at next location
    57.     decfsz  PixelCounter        ; decrement counter and skip goto Main when pixelcounter reaches end of line
    58.     goto    Main                ; return loop
    59.     bcf     GPIO,1              ; clear GPIO 1 to increment line position
    60.     bsf     GPIO,1              ; set GPIO 1 to allow pixel drawings at that line
    61.     movlw   06h                 ; store value 118 into w register
    62.     movwf   PixelCounter        ; store w register into PixelCounter so we can draw 118 more pixels on a new line
    63.     decfsz  HsyncCounter        ; decrement counter and skip goto Main when HsyncCounter reaches end of line time
    64.     goto    Main                ; return loop
    65.     bcf     GPIO,2              ; clear GPIO 2 to start at the top of the screen
    66.     bsf     GPIO,2              ; set GPIO 2 to allow pixels to be drawn
    67.     movlw   30h                 ; store value 60 into w register
    68.     movwf   HsyncCounter        ; store w register into HsyncCounter so we can draw pixels on 118 new line
    69.     decfsz  VsyncCounter        ; decrement counter and skip goto Main when VsyncCounter reaches end of screen
    70.     goto    Main
    71.     movlw   3Ch                 ; store value 60 into w register
    72.     movwf   VsyncCounter        ; store w register into VsyncCounter so we can restart at the top of the screen
    73.     goto    Main
     
  2. Potato Pudding

    Well-Known Member

    Jun 11, 2010
    684
    92
    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.
     
  3. Potato Pudding

    Well-Known Member

    Jun 11, 2010
    684
    92
    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.
     
  4. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    You will need something like this with only two pins...
    [​IMG]
    or
    [​IMG]

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

    Good Luck
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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."
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  7. Potato Pudding

    Well-Known Member

    Jun 11, 2010
    684
    92
    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.
     
  8. Potato Pudding

    Well-Known Member

    Jun 11, 2010
    684
    92
    Just for interests sake - the stuff you notice when you look into something like this can be amazing.

    I had never heard of these PIC chips with RF features upto 800MHz or more.

    Not for internal processing but for use as a communication device. First time I had seen them.
     
  9. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    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.
    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?
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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?
     
  11. peter_morley

    Thread Starter Member

    Mar 12, 2011
    179
    0
    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?
     
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Because it is expecting a digital signal.
     
Loading...