Controlling Timers in PIC


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Location
    Hendersonville NC
    Posts
    14

    Question Controlling Timers in PIC

    How does one use PIC Basic Pro Commands to control the timer1 module, or can it even be done?

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Yes

    Yes it can, get the data sheet for the chip you intend to use and let us know which chip it is and then we will teach you how to implement this as Sayzer taught me.
    http://www.microchip.com/stellent/id...GE&nodeId=1434
    Last edited by Archangel; - 13th January 2007 at 21:58. Reason: add link

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default instructions

    1. From the Data sheet you see pin ?, the clock input
    pin for timer 1 (varies by pic number). A 16F628A it is RB6
    a 16F877 it is RC0 et. al . . . . Check your data sheet for
    your particular PIC.

    2. Look at the T1CON register in the datasheet. It is a byte
    variable, 8 (bits). Bit 7 and Bit 6 are not used, just ignore
    them.

    3. Now look at bits 5 and 4. These are the bits you select based
    upon your application. This is where you set the prescaler.


    4. Now on to bit 3. This is the T1OSCEN bit. usually this is
    turned off so make this a zero too.
    1 = T1OSCEN on, 0= T1OSCEN off

    5. We are at bit 2 now. To use timer 1 in counter mode, we choose
    not to synchronize external clockinput, because we want to
    count the incomming ticks, so set this bit as 1.

    6. Now we are at bit 1. "This is our guy", this selects timer or
    counter mode. Set this to 1 to count external pulses.

    7. Bit zero at last. set bit zero to 1 and timer is enabled, set
    to 0 and it is turned off. Use it this way in your code:


    T1CON = %00110111 ' Sets up timer and prescaler
    (zero bit 3-4 to alter prescaler)

    the following code is put into your code where you want to start
    and stop the counter/timer:
    T1CON.1 'turn on timer
    T1CON.0 'turn off timer

    8. Now we come to the point where we see the number of ticks The
    ticks are stored in a word variable, set up like this:
    CounterTotal var word 'initialize variables needed for program.

    9. The counts are stored in TMR1L and TMR1H and you set up the
    variable like this: CounterTotal.LowByte=TMR1L
    CounterTotal.HighByte=TMR1H
    Prior to beginning to count at the start of program, zero
    these as follows:
    TMR1L=0
    TMR1H=0
    you may zero these for your own purposes anywhere in your
    program or you may preload these with a value greater than zero.

    10. Now look at the datasheet re: T1CON register and set
    up the T1CON register for your program. The example below
    is set up as follows:

    Prescaler = 1:8 ' 8 counts in = 1 count out
    T1OSCEN = off
    T1SYNC = 1 ' do not synchronize external clock input
    TMR1CS = 1 ' External clock from clock input pin
    TMR1ON = 1 ' Timer is enabled and running


    T1CON = %00110111 ' Sets up timer and prescaler(zero bit 5-4 to
    alter prescaler)

    That was easy, and yes I do keep these instructions available
    to reference when I need them.

  4. #4
    Join Date
    Dec 2005
    Location
    Hendersonville NC
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Control tmr1 using PIC Basic Pro

    Thanks Joe!! That is terrific info.
    The end task I had in mind is to clk tmr1 from a noise clocking source (random clock pulses), then sample the timer count every 5 seconds or so and display the number on an LCD....i.e. a random number generator between 0 and 65535. Why? Someone challenged me to do it! Your info could easily be used with other applications....thanks again!

  5. #5
    Join Date
    Dec 2005
    Location
    Hendersonville NC
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Control tmr1 using PIC Basic Pro

    I forgot to mention I am using the 16F870 PIC

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Cool Hail Sayzer!

    Your Welcome, the credit goes to Sayzer, this is what he taught me !
    JS

Similar Threads

  1. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  2. Controlling stepper motor with PIC
    By The Master in forum Off Topic
    Replies: 3
    Last Post: - 1st July 2008, 10:21
  3. Availability of PIC timers from PBP
    By coda64 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th February 2006, 07:18
  4. Controlling power to a PIC with another PIC
    By jswayze in forum Off Topic
    Replies: 3
    Last Post: - 28th May 2005, 19:44
  5. Battery Backup with PIC controlling switch
    By Dwayne in forum Schematics
    Replies: 1
    Last Post: - 27th December 2003, 13:16

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts