Adsby Google
PIC Microcontroller programmer
PIC Microcontroller ADC
PicProgramming
PIC16F877A
TimerClock
Search this web site:
Contact us
Blog
Register
PIC16F877TimerModulestutorialsTimer1
Search
Adsby Google
Register
UsedHorologyTools
Pic18F
HorologySupplies
VintageHourglasses
AntiqueEnglishClocks
PrintableClockFaces
PIC Microcontroller
Development tools
Home
PIC microcontroller kits
USB PIC microcontroller kits
PIC programming books
Programming PIC in C
PIC Microcontroller
Tutorials
Adsby Google
ClockModule
PicSoftware
Many times, we plan and build systems that perform various processes that depend on time.
Simple example of this process is the digital wristwatch. The role of this electronic system is to
minute (for minutes) and so on.
To perform the steps we've listed, the system must use a timer, which needs to be very accurate in
In this PIC timer module tutorial we will study the existing PIC timer modules. The microcontroller
PIC16F877 has 3 different timers:
PIC Memory Organization
PIC Timer1
Microcontroller Board
PIC USB Programmer
PIC Debuger
PIC Timer Modules
PIC Timer0 tutorial
PIC Timer1 tutorial
PIC Timer2 tutorial
Serial communication /
USART
Horology
Supplies
PrintableClock
Faces
InteractiveClock
Games
MilitaryTime
TimeClock
Converter
program could be continued. "Delay procedure" had two disadvantages:
we could not say exactly how long the Delay procedure was in progress
we could not perform any further steps while the program executes the "delay procedure"
Now, using Timers we can build a very precise time delays which will be based on the system clock
EDUPIC microcontroller board
and allow us to achieve our desired time delay well-known in advance.
In order for us to know how to work with these timers, we need to learn some things about each
one of them. We will study each one separately.
PIC Timer1 tutorial
The Timer1 module, timer/counter, has the following features:
readable and writable
PIC Fire Detector project
AntiqueEnglish
Clocks
implement some delay in the program, that was counting up to a specific value, before the
16-bit timer/counter consisting of two 8-bit registers (TMR1H and TMR1L)
Creating new project
We can use these timers for various important purposes. So far we used delay procedure to
PIC A/D converter
Projects
Vintage
Hourglasses
PIC Timer2
PIC Interrupts
PIC Microcontroller
order to take necessary actions.The clock is actually a core of any electronic system.
PIC Timer0
HI-TECH compiler
UsedHorology
Tools
display time in a very precise manner and change the display every second (for seconds), every
PIC Introduction to PIC
Microchip MPLAB IDE
8-bit software programmable prescaler
Internal (4 Mhz) or external clock select
Interrupt on overflow from FFFFh to 0000h
ICP2 USB programmer
General
Liquid Crystal Display - LCD
Contact Us
Lets explain the features of PIC Timer1 we have listed above:
Timer1 has a register called TMR1 register, which is 16 bits of size.
Actually, the TMR1 consists of two 8-bits registers:
TMR1H
TMR1L
It increments from 0000h to the maximum value of 0xFFFFh (or 0 b1111 1111 1111 1111 or
65,535 decimal). The TMR1 interrupt, if enabled, is generated on overflow which is latched in
interrupt flag bit, TMR1IF (PIR1<0>). This interrupt can be enabled/disabled by setting/clearing
TMR1 interrupt enable bit, TMR1IE (PIE1<0>). You can initialize the value of this register to what
ever you want (not necessarily "0").
TMR1IF TMR1 overflow Interrupt Flag bit.
This flag marks the end of ONE cycle count. The flag need to be reset in the software if you want to
do another cycle count. We can read the value of the register TMR1 and write into. We can reset its
value at any given moment (write) or we can check if there is a certain numeric value that we need
(read).
Prescaler Frequency divider.
We can use Prescaler for further division of the
system clock. The size of the register is 2-bit only,
so you can make four different division. The
options are:
1:1
1:2
1:4
1:8
You can choose whether to use an internal system
clock (crystal) or external oscillator that can be
connected to a pin RC0.
The structure of the T1CON register
We perform all the necessary settings with T1CON register. As we can see, the size of the register
is 8 bits. Lets explore the relevant bits:
Initializing the T1CON register
The following is an example how we can initialize the T1CON register:
1. TMR1ON=1; // the timer is enable
2. TMR1CS=0; // internal clock source
3. T1CKPS0=0; // Prescaler value set to 00
4. T1CKPS1=0; // which means 1:1 (no division)
Or you can set all the T1CON register at once as follows:
T1CON=0b00000001;
CLICK here for more information about PIC TIMER 1 Module
Block diagram of the PIC Timer1
PIC TIMER1 block diagram
Calculating Count, Fout, and Timer1 values
If using INTERNAL crystal as clock, the division is performed as follow:
PIC TIMER1 formula for internal clock
Fout The output frequency after the division.
Tout The Cycle Time after the division.
4 - The division of the original clock (4 MHz) by 4, when using internal crystal as clock (and not
external oscillator).
Count - A numeric value to be placed to obtain the desired output frequency - Fout.
(256 - TMR1) - The number of times in the timer will count based on the register TMR0.
If using EXTERNAL clock source (oscillator), the division is performed as follow:
PIC TIMER1 formula for external clock
Simple example and calculation of how to use TIMER1:
Suppose we want to create a delay of 2 second in the our program using Timer1. What is the value
of Count?
Calculation:
First, lets assume that the frequency division by the Prescaler will be 1:1. Second, lets set
TMR1=0, which means the TMR1 will count 65,536 times. Thus:
Formula to calculate Cout for Timer1
Delay of 1 sec using Timer1
The following simple program creates a delay of 1 sec using TIMER1:
#include<pic.h>
intCount=0;
voidmain(void)
{
T1CON=0b00000001;
while(1)
{
while(!TMR1IF);
TMR1IF=0;
Count++;
if(Count==15)
{
Count=0;
}
}
}
1 sec delay using Timer1
PIC Timer0 tutorial
PIC Timer2 tutorial
Microcontroller Board Blog
Microcontroller Board Store
Contact Page
Copyright 2008- 2016 MicrocontrollerBoard.com. All rights reserved.