PIC10F322 Applications – Basic Astable Circuit

Continuing with using a PIC10F322 as a 555 replacement – Here is a basic Astable XC code.

The output pulses are on PORTA.0 and the run down of the code is as follows.

We do some basic setup, Set the speed of the cpu to 16Mhz, set PORTA.0 as output.

The code loop, toggles PORTA.0 on and off.

At 16Mhz and no delays, the output pulse is around 1.333Mhz or roughly a 750ns pulse – shown here.

The total time from rising edge to edge pulse is 666Khz.. Oh my. 


PIC10F322 Applications - Basic Astable

At 16Mhz, the instruction cycle is 4Mhz, or 250ns.

For now – is the basic astable code.  Notice I didn’t put the loop code (the code after while) in a separate function – that is because it will add an additional 2 instructions to call it.

#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  //16Mhz

void setup(void);

void main(void)
        LATAbits.LATA0 = 1;  //Put A.0 High
        /*We call an assembly insuctgion here NOP - no operation it burns 1 CPU cycle
         *and one more - because once the code hits the end, it will execute an ASM JUMP which takes two cpu cycles to complete
         *this gives us a nice square 50% dutycycle wave at 750ns high and low  */
        //Add Delay here if you need something different 
        LATAbits.LATA0 = 0;  //Put A.0 low   
        //AND Add the same Delay here if you need something different for 50%

void setup(void)
    //Disable analog for A.0, set as Output, Set to Low
    ANSELAbits.ANSA0 = 0;
    TRISAbits.TRISA0 = 0; //A.0 Output
    LATAbits.LATA0 = 0;  //Put A.0 low
    //Set the System Clock - You can change this to match the setting you are looking for
    OSCCONbits.IRCF = 0b111;  //Set System Clock to 16Mhz FOSC/4 = 4Mhz

Something You Might Be Intrested In


10F32X Rapid Prototype Board

Make The PIC10F322 and other PIC10F Processors Breadboard Friendly for Quick and Easy Prototyping.

{Click to learn more}

PIC10F322 Applications - Basic Astable