Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

EE Design > In Technical
| Home | Contact |

Title: Timer in PIC Microcontrollers
Author: Vincent Wong
Date: 29th March 2005


Below shows how to setup Timer 0, Timer 1 and Timer 2 to overflow every 1ms or 1KHz running at 4MHz. The 16F series MCU has 3 timers like in the PIC16F627, which is very usefull. I have used up all three timers to implement a PWM output controlling the brightness of a Red, Green and Blue high-power LEDs and also a White LED to set the huse of the ligthing system. The white color brightness is also control using PWM, but it is implemented using software because there are only 3 timers available in the PIC16F627 microcontroller.


Setting up Timer 0 :

    set prescale to 1:4
    1 machine cycle = 1us
    1us x 4 = 4us/tick
    If we load 0x00 into TMR0 register,
    Then -> 256 x 4us = 1024us = 1.024ms


Setting up Timer 1 :

    set prescale to 1:4
    1 machine cycle = 1us
    1us x 4 = 4us/tick
    Timer 1 is 16 bits.
    We only require lower 8 bits (lower byte), therefore we need to mask the upper byte.
    So we always load TMR1H with 0xFF when we reload TMR1L value.
    If we load 0x00 into TMR1L register,
    Then -> 256 x 4us = 1024us = 1.024ms


Setting up Timer 2 :

    set prescale to 1:4
    set postscale to 1:1
    If we load 0x00 into TMR2 register,
    Then -> 256 x 4us = 1024us = 1.024ms



| Home | Top Page | Contact |


Copyright Notice: This article, including all text, documents and schematic diagrams, are the intellectual property of Vincent Wong, and is Copyright (c) 2005. Reproduction or re-publication by any means whatsoever, whether it is electrical & electronic, mechanical or electro-mechanical, is strictly prohibited under International Copyright laws. The author (Vincent Wong) grants the reader the right to use this information for personal use only. Commercial use is prohibited without express written authorisation from Vincent Wong.

Copyright of Vincent Wong. All Rights Reserved.