Home 9 The Art of Technology 9 Generating a Clock Reference Output with a PIC10F322 Using XC8

This guide demonstrates how to generate a clock reference output on PortA.2 of the PIC10F322 microcontroller using XC8. A clock reference output can be used to drive other devices that require a clock input, such as a Z80 microprocessor.

Overview

The clock reference output allows you to turn the PortA.2 pin into a clock output device. You can program different clock frequencies based on the system clock (internal oscillator), which is then divided by 4 to get the reference output frequency.

Internal Oscillator Frequencies

The internal oscillator of the PIC10F322 can be set to the following frequencies:

  • 16 MHz
  • 8 MHz (default power-on value)
  • 4 MHz
  • 2 MHz
  • 1 MHz
  • 500 kHz
  • 250 kHz
  • 31 kHz (LFINTOSC)

The clock reference output frequency will be the system clock frequency divided by 4. For example, if the internal oscillator is set to 16 MHz, the clock reference output will be 4 MHz.

ClockTiming

XC8 Code to Generate Clock Reference Output on PIC10F322

Here’s the complete XC8 code to configure PortA.2 as a clock reference output:





#include <xc.h>
#include <stdint.h>

//Device Configuration
#pragma config FOSC = INTOSC  // Oscillator Selection 
#pragma config BOREN = ON    // Brown-out Reset
#pragma config WDTE = OFF    // Watchdog Timer
#pragma config PWRTE = ON    // Power-up Timer
#pragma config MCLRE = OFF   // MCLR Pin Function Select bit->MCLR pin function is digital input, MCLR internally tied to VDD
#pragma config CP = OFF      // Code Protection 
#pragma config LVP = OFF     // Low-Voltage Programming 
#pragma config LPBOR = ON    // Brown-out Reset Selection bits
#pragma config BORV = LO    // Brown-out Reset Voltage Selection
#pragma config WRT = OFF    // Flash Memory Self-Write Protection

//Used to calculate the delay time - Change depending on processor Speed
#define _XTAL_FREQ 16000000  //16 MHz 

//Prototypes
void setup (void);



void main(void)
{
    setup();
    
    while(1)
    {
      
    }
}

void setup (void)
{
    OSCCONbits.IRCF = 0b111;  //Set System Clock to 16Mhz FOSC 4Mhz
    CLKRCONbits.CLKROE = 1; //Enable Clock Reference out on RA2
}

Have a Project or Idea!?

Seeking Bespoke Technology Solutions?

jamie@jamiestarling.com


Pin It on Pinterest

Share This