Article sections

    PIC10F322 – MCU Overview – What you really Need to Know


    If you want the detailed nitty gritty.. Refer to the microchip datasheet… This is just the high level of the chip to get you going.

    The major difference (and only) between the PIC10F320 and PIC10F322
    PIC10F320 has 256 words of program memory
    PIC10F322 has 512 words of program memory

    The PIC10F322 has double the program storage space.

    Both have
    -Max Clock speed of 16Mhz – internal clock – software selectable frequency
    -Operates from 2.3V to 5.5V – I am only talking about the PIC10(F) devices not the PIC10(LF) Devices
    -64 Bytes of Data Memory
    -128 Bytes of nonvolatile data storage

    4 I/O Pins: Labeled RA0 – RA3
    -RA3 (shared MCLR Pin) is input only.
    -I/O Pins can sink/source current up to 50mA
    -Individually selectable weak pull-ups
    -Interrupt on change

    Two Timers: TMR0 and TMR2
    -Timer0: 8 bit Timer/Counter with Programmable Prescaler
    -Timer2: 8 bit Timer/Counter with 8-Bit Period Register, Prescaler and Postscaler

    (Don’t ask – why did it jump from Timer0 to Timer2.. What happened to 1?)

    Two PWM modules:
    -10bit PWM – Max Frequency of 16kHz

    A/D (Analog Digital) Converter:
    -8 bits – three channels (pins RA0, RA1, RA2)

    Configurable Logic Cell (CLC): 
    -Software selectable logic functions including:
    -AND/OR/XOR/D Flop/D Latch/SR/JK

    Numerically Controlled Oscillator (NCO):
    – 20-bit accumulator
    – 16-bit increment
    – Linear frequency control
    – High-speed clock input
    – Selectable Output modes
    – Fixed Duty Cycle (FDC)
    – Pulse Frequency (PF) mode

    Complementary Waveform Generator (CWG):
    – Selectable falling and rising edge dead-band control
    – Polarity control
    – Two auto-shutdown sources
    – Multiple input sources: PWM, CLC, NCO


    PIC10F322 Pinout Diagram

    PIC10F322 Details

    What is the difference between the PIC10F320 versus the PIC10F322?

    With all the above the two PIC microcontrollers are the same. except for one thing.

    The PIC10F322 has 512 Words of Flash Program Memory.
    The PIC10F320 has 256 Words of Flash Program Memory.

    So, the PIC10F322 has double the Program Space. And costs roughly 3 cents more than the PIC10F320, depending on the quantity you buy.


    How to Power the PIC10F322


    For the majority of the work I do with 8bit Microcontrollers – the PIC10F322 is an 8bit controller – I run a +5 power supply. Just call me old fashion.

    To power up the 322, and depending on how you are going to use it – you need some sort of power regulation circuit, that takes some input voltage and drops it to your desired voltage to drive the PIC10F322.

    The easiest way (unless you want to build something yourself) is to get one of these breadboard power regulators. You can find them on eBay and Amazon. It takes up to a 12V input and outputs, 5V or 3.3V depending on jumpers. You can even run one rail at 5V and the other at 3.3V. Another plus is it has an off and on switch.

    So, just run the 5+ to pin – VDD {pin – 2 of the PDIP package} the ground {0V negative} to VSS {pin – 7 of the PDIP package}

    Not so fast, it is a good idea to put in a decoupling capacitor, also referred to as a bypass capacitor. You’ll find these commonly placed as close as possible to an integrated circuit (IC) on a PCB layout. Once fully charged, their job is to simply oppose any unexpected change in your input voltages from a power supply.

    Some components like integrated circuits rely on their input voltage being as steady as possible, so when you place a decoupling capacitor next to an IC, you’ll be able to protect those sensitive chips by filtering out any excess noise and creating a nice, steady source of power.

    What happens if you don’t use decoupling capacitors next to your IC? Well, you’ll likely wind up with a processor that starts skipping instructions and behaving abnormally.

    While it seems like this might create a short from power to ground, only high-frequency signals can run through the capacitor to ground. The DC signal will go to the IC, just as desired. Another reason these are called bypass capacitors is because the high frequencies (in the kHz-MHz range) bypass the IC, instead running through the capacitor to get to ground.

    When physically placing decoupling capacitors, they should always be located as close as possible to an IC. The further away they are, they less effective they’ll be.

    For most of our work, a .1uf cap is enough to take of this. Here is a recommended power diagram.

    PIC10F322 Details



    PIC10F322 Reset MCLR Line

    The PIC 10F322 has a reset pin named – MCLR – This is PIN RA3 or physical pin 8 on a PDIP device.

    This is an optional external input that can reset the device. The pin is active low – meaning bring the pin to ground will hold the device in reset mode.

    You also have the option of disabling the MCLR though a configuration word – MCLRE and LVP. Setting both MCLRE and LVP to 0, will disable the MCLR pin and RA3 will function as a normal input pin.

    Notice above, I said RA3 will function as a normal input pin. RA3 is not bi-directional like the other pins, it can only be set for input.

    What can you do with MCLR.. If you have it enabled.

    Depending on your circuit, it can be held low until other devices power up.
    Put a push button on it and use it as a reset.

    Although the datasheet does say that RA3 is connected to VDD (+ voltage) though an internal weak pull-up. I always found it a good idea to supply my own external 10k pull-up resistor.

    If you wanted to use a push button reset – tie the 10K pull-up to the pin, and the button to ground. This would be a normally open switch. When you press the button it will complete the circuit to ground, overriding the 10K pull-up and bring MCLR low.

    For me – I rather have the RA3 pin functional – so I disable MCLR though the configuration word. If you are using XC8 you can include the following config settings.

    #pragma config MCLRE = OFF // MCLR Pin Function Select bit->MCLR pin function is digital input, MCLR internally tied to VDD
    #pragma config LVP = OFF // Low-Voltage Programming

    Overview of the Configuration Bits


    What Are the Configuration Bits? They are a collection of special bits that can only be modified at program time. Configuration bits are “read” during reset and enable or disable hardware features in the microcontroller. The features controlled by the configuration bits include, but not limited to, the clock source, WatchDog timer, brownout detect and Memory Read protection. Configuration bits are not executable code they are essentially fuses located in the program memory space.

    Each PIC MCU has it’s own set of configuration bits. The Special Features section of the individual datasheets contains the definition for each of the bits.

    The settings for the configuration bits is determined by directives written in the application software.

    Here is a breakdown of the Configuration Bits for the PIC10F320 and PIC10F322 – Also below is a snip of code to insert into your program using XC8 to make setting them a little easier.

    FOSC — Oscillator Selection bits
    FOSC = INTOSC : (uses internal oscillator) INTOSC oscillator: CLKIN function disabled – I/O function available on CLKIN pin
    FOSC = EC : Uses external oscillator – A clock source needs to present on the CLKIN pin
    {My recommendation – use the internal oscillator – FOSC = INTOSC.}

    BOREN — Brown-out Reset Enable (Resets the chip in the event of a brown out)
    BOREN = OFF : Brown-out Reset disabled.
    BOREN = SBODEN : Brown-out Reset controlled by the SBOREN bit in the BORCON register.
    BOREN = NSLEEP : Brown-out Reset enabled while running and disabled in Sleep.
    BOREN = ON : Brown-out Reset enabled.
    {My recommendation – Set the Brown-out to ON so that the device will reset if voltage levels fall}

    WDTE — Watchdog Timer Enable (Resets the device if the program does not issue a CLRWDT instruction within the time-out period.)
    WDTE = OFF : Watchdog Timer is disabled
    WDTE = SWDTEN : Watchdog Timer controlled by the SWDTEN bit in the WDTCON register.
    WDTE = NSLEEP : Watchdog Timer enabled while running and disabled in Sleep.
    WDTE = ON : Watchdog Timer is enabled
    {My recommendation – for what we are doing – disable it – WDTE = OFF, unless you are writing some mission critical program}

    PWRTE — Power-up Timer Enable (Holds the device in reset for ~64 ms after reset for power up. This allows the voltage of the device to rise to an acceptable level before operating)
    PWRTE = ON : Power up Timer Enabled
    PWRTE = OFF : Power up Timer Disabled
    {My recommendation – enable it – PWRTE = ON}

    MCLRE — MCLR Pin Function Select (Enables the MCLR Reset Pin or Disables it so the pin can be used for I/O)
    MCLRE = OFF : MCLR pin function is digital input, MCLR internally tied to VDD
    MCLRE = ON : MCLR pin function is MCLR you will need to provide an external pullup on MCLR
    {My recommendation – Disable it so you can use the MCLR as an I/O pin – MCLRE = OFF}

    CP — Code Protection (Protects the code in the MCU so it cannot be copied out)
    CP = ON : Program memory code protection is enabled.
    CP = OFF : Program memory code protection is disabled.
    {My recommendation – Depends – if you are producing a commercial product perhaps enable it for debugging, building – disable it}

    LVP — Low-Voltage Programming
    LVP = OFF : High-voltage on MCLR/VPP must be used for programming.
    LVP = ON : Low-voltage programming enabled.
    {My recommendation – If you are using the PICKit or other ICD – this needs to be off – LVP = OFF}

    LPBOR — Brown-out Reset Selection (enables use of the BORV config)
    LPBOR = OFF : BOR disabled.
    LPBOR = ON : BOR enabled.
    {My recommendation – LPBOR = ON : BOR enabled}

    BORV — Brown-out Reset Voltage Selection (The level of voltage that will trigger a brown out reset)
    BORV = HI : Brown-out Reset Voltage (Vbor), high trip point selected. ~2.70v
    BORV = LO : Brown-out Reset Voltage (Vbor), low trip point selected. ~1.90v
    {My recommendation – BORV = LO}

    WRT — Flash Memory Self-Write Protection (With the 10F320 and 10F322 you can write to flash memory though program code)
    WRT = ALL : 000h to 1FFh write protected, no addresses may be modified by PMCON control.
    WRT = HALF : 000h to 0FFh write protected, 100h to 1FFh may be modified by PMCON control.
    WRT = BOOT : FF000h to 07Fh write protected, 080h to 1FFh may be modified by PMCON control.
    WRT = OFF : Write protection off.
    {My recommendation – WRT = OFF unless you really need it}


    If you are looking for a configuration bits header file – I have one for XC8 – below.

    PIC10F322 XC8 My Recommended Configuration Bits



    PIC10F322 TRISA Register (Control Direction of a Pin) XC8


    The PIC10F322 has 4 general purpose I/O Pins. RA0, RA1, RA2, RA3 – That is assuming you are not using any other peripherals connected to the device and MCLR is disabled.

    All 4 I/O pins are on the same port – A

    The registers we need to modify to get a pin into output mode are, ANSELA and TRISA

    The ANSELA register controls the analog function of a pin – The ANSELA bits default to the Analog mode after Reset. To use any pins as digital general purpose or peripheral inputs, the corresponding ANSEL bits must be initialized to ‘0’ by user software.

    TRISA register controls the direction of a pin. Think of it this way, setting a bit in the register as a 0 – think output. Setting a bit as a 1 – think input.

    After a power on reset – the Pins are set to Input mode. To make pin RA0, an output we would..

    ANSELAbits.ANSA0 = 0; //Disable Analog
    TRISAbits.TRISA0 = 0; //Set Pin 0 PortA.0 as output

    If we wanted to do the same for RA2..

    ANSELAbits.ANSA2 = 0; //Disable Analog
    TRISAbits.TRISA2 = 0; //Set Pin 0 PortA.0 as output

    Or if we wanted all the pins*(see note below) to output..
    ANSELA = 0;
    TRISA2 = 0;

    (Note**) Pin RA3 can only be an input pin you can not set it as an output..

    Once the pin you want is set as an output – you can set it high or low, by writing to the associated data latch register.

    To make RA0, which we set as output high, we would

    LATAbits.LATA0 = 1;

    To turn it off, or make it low..

    LATAbits.LATA0 = 0;

    The same for RA2

    LATAbits.LATA2 = 1; //high
    LATAbits.LATA2 = 0; //low



    PIC10F322 System Clock Speed is 8Mhz After Reset


    Here is a little know fact (not really) – On the PIC10F322 – If you are using the internal oscillator for the system clock – following any Reset, the IRCF<2:0> bits of the OSCCON register are set to ‘110’ and the frequency selection is set to 8 MHz.

    That means, until you change the OSCCON Register INTOSC (FOSC) Frequency Select bits in software – the device is running at 8Mhz.


    bit 6-4 IRCF<2:0>: INTOSC (FOSC) Frequency Select bits
    111 = 16 MHz
    110 = 8 MHz (default value)
    101 = 4 MHz
    100 = 2 MHz
    011 = 1 MHz
    010 = 500 kHz
    001 = 250 kHz
    000 = 31 kHz (LFINTOSC)



    10F322 Pin RA3 is input only

    Pin RA3 can only be an input pin you can not set it as an output..

    in PIC10F322

    Related Articles