timer1 trouble


Closed Thread
Results 1 to 2 of 2

Thread: timer1 trouble

  1. #1
    beginner10's Avatar
    beginner10 Guest

    Default timer1 trouble

    Hello,

    i'm using a pic16f882 with a 20 Mhz oscillator connected to pin 9 and 10.
    i try to get a timer running with a tick every 0.1 second, but i cannot get it to work.

    What's the problem?

    Code:
    @ DEVICE PIC16F882,HS_OSC
    DEFINE	OSC 20
                                 
    ' Timer1 Registers: 
    ' Prescaler=1:8; TMR1 Preset=0; Freq=9,53674Hz; Period=0,1048576 s
    T1CON.5 = 0 ' T1CON.T1CKPS1 = 1 ' bits 5-4  Prescaler Rate Select bits
    T1CON.4 = 0 ' T1CON.T1CKPS0 = 1
    T1CON.3 = 1 ' T1CON.T1OSCEN = 1 ' Timer1 Osc Enable: bit 1=on
    pause 250  'delay for starting oscillator
    T1CON.2 = 1 ' T1CON.T1SYNC  = 1 ' Synchronization Control bit:
    T1CON.1 = 0 ' T1CON.TMR1CS  = 0 ' Source bit: 0=Internal clock (FOSC/4) / 1                                           ' External clock from pin T1CKI 
    T1CON.0 = 1 ' T1CON.TMR1ON  = 1 ' bit 0 enables timer
    TMR1H = $0        ' preset for timer1 MSB register
    TMR1L = $0        ' preset for timer1 LSB register
    when I try to read the TMR1H, it's counting like crazy, and keeps overflowing ( thus recounting to 255).

    Thanks in advance

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


    Did you find this post helpful? Yes | No

    Default

    Hello beginner1,
    T1 is a 16 bit timer so it should overflow at 65535 not 255. Using Mister_E's PICMultiCalc
    you should set your timer so: Preset at 34286, 1:16 prescale, will overflow @ 100.001 mSec
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Software PWM using Timer1
    By muqasim in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th December 2009, 11:49
  2. RPM With Timer1
    By mel4853 in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 29th June 2009, 21:50
  3. Help with TIMER1 + SLEEP
    By Yodoad in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd May 2009, 15:07
  4. Time Period of Timer1
    By arnol34 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th May 2007, 00:31
  5. Timer1 and Interupt wierdness
    By mind in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 23rd August 2005, 01:24

Members who have read this thread : 1

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