Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
:
:
Don't worry -- youre-mail address is totally secure. I promise to use it only to send you MicroZine.

A (midrange) PIC Timer guide

Do you get stuck with PIC timer calculations juggling between datasheet, calculator and your design requirements?

If so then you need some tools to automate the process.

Calculations

Typically you will need to focus on the end result which is usually to make the timer generate a frequency or create a repeating interrupt time of the correct period.  This is fairly difficult when you first have to find the information in the datasheet and then account for prescalers and postscalers etc.

If you do this a lot you have quite a few calculations and decisions to make as the hardware in each timer is different and you'll also have to do battle with interrupts.

TCL Scripts for PIC Timer calculation

To make the process easy I have created three interactive script modules written in TCL (Tool Command Language).

Installing TCL

This is a very easy bush button process, and once done you can double click the .tcl file to run it.

It is at this location

Activestate.com

...Install the free runtime from ActiveState

From the page in the above link, click Languages, then select “Active TCL”. Then click the "Active TCL" link under the title:

“Download the Free Community Edition:”

Then finally, download the TCL environment for your machine - probably windows installer (x86).

After installation just double click the TCL file to run it (that you wil download below).

TCL Scripts

Each of these scripts is geared towards the most typical use of each timer and lets you change prescaler, postscaler or register value using slider controls.  This makes it easy to experiment with different values as the result is immediately displayed in the web page (frequency and period are displayed from each part of the timer e.g. after the prescaler, after the register, after the postscaler).

So you can do what-if type operations (all without a calculator in sight) e.g. I need a 15ms repeat rate.

From Timer 2 the closest I could get is 15.136 (took 1 minutes to test) - perhaps I'll try timer 1 - Ah that gives an exact 15ms (took 30 seconds to test). Just check with Timer 0 - this gives 15.040ms (took ~30 seconds to test).

Of course you can also set the main clock frequency (internal or external crystal) as well.

PIC Timer 0

This has an 8 bit prescaler and an 8 bit timer and can be driven from an external clock.

Prescaler : 8 bit
Timer register : 8 bit

Link to PIC-Timer 0 calculator.

PIC Timer 1

This has a 4 bit prescaler and an 16 bit timer and can be driven from an external clock. It can also be driven from a slow speed crystal e.g. 32kHz.

Prescaler : 4 bit
Timer register: 16 bit

Link to PIC-Timer 1 calculator.

PIC Timer 2

This has a 4 bit prescaler and an 8 bit timer and an 8 bit period register and is only driven from the internal clock (Fosc/4)

Note: the Period register lets you create an output frequency with no further processing i.e. you don't have to update the timer register value in an interrupt routine as you do with Timer 0 or Timer 1 - this makes it easy to use (although it's tricky to get right - unless you use the calculator scripts).

Prescaler : 2 bit (1:1, 1:4, 1:16)
Timer register: 8 bit
Period register : 8 bit
Postscaler : 4 bit (1:1 to 1:16 inclusive)

Link to PIC-Timer 2 calculator.



Jump from pic timer page to
Best-Microcontroller-Projects Home Page

New! Comments

Have your say about what you just read! Leave me a comment in the box below.



Privacy Policy | Contact | About Me

Site Map | Terms of Use





Visit our Facebook Page:

   Click Here

Recent Articles

  1. Easy Switch Debounce

    Switch debounce: Three different ways to debounce input push switches with one amazing method that you can't miss.

    Read more

  2. How to use a DS18B20 on the Arduino for easy temperature measurement

    How to Easily Use the DS18B20 Maxim One-Wire thermometer with Arduino example code showing external or parasitic power modes.

    Read more

  3. How to use the BMP280 Barometric Pressure chip with the Arduino

    How to use the BMP280 for weather pressure measurement or altitude change detection.

    Read more

  4. The TCS230 Color Sensing Chip: How it works and how to use it.

    How to use the TCS230 (/TCS3200) Color detector chip and easily add it to any of your projects.

    Read more

  5. All about the MC78M05BDTRKG Linear Voltage Regulator

    How to use MC78M05BDTRKG for maximum current without using too large a heatsink pad and how to select the optimum input voltage.

    Read more

  6. Fixed point: A fast and easy way to save tons of microcntroller flash memory

    How to use fixed point maths to save microcontroller memory by avoiding use of the floating point library.

    Read more

Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."

- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com<

"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


Learn Microcontrollers

"Interested in
Microcontrollers?"

Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon

Back to Top