pic18f4431 timer1 problem

Discussion in 'Embedded Systems and Microcontrollers' started by dmta, Jun 25, 2013.

  1. dmta

    Thread Starter Member

    Mar 24, 2013
    32
    1
    Hi all,

    I want to use the timer1 of the PIC18f4431 to increment every instruction cycle. I wrote a function to do this and simulated using pic18 simulator IDE but I am not seeing the TMRL register increment. Please take a look at my code and correct me.

    Code ( (Unknown Language)):
    1. void timer1_init(){
    2.  
    3.      T1CON.RD16    = 0;          // enable register read/write of TIMER1 in two 8-bit operations
    4.      T1CON.T1RUN   = 0;          // system clock is derived from another source
    5.      T1CON.T1CKPS1 = 0;          // ##increments with 1:1 prescale value
    6.      T1CON.T1CKPS0 = 0;          // ##
    7.      T1CON.T1OSCEN = 0;          // TIMER1 oscillator is shut-off
    8.      T1CON.TMR1CS  = 0;          // enable TIMER1
    9.      T1CON.TMR1ON  = 1;          // TIMER1 uses internal clock (FOSC/4)
    10.      TMR1L         = 0;          // clear TIMER1 lower register
    11. }
    12.  
     
    Last edited: Jun 25, 2013
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,028
    What you show should start the timer as far as it goes assuming you only call the routine once during setup (it clears TMR1L) and not in some loop.

    You'll have to do and show the config bits/processor/simulator setup and show the whole code to go further. What's the simulated frequency and OSC type?

    Be sure to turn off the FAIL-SAFE clock function for now.

    Check the instructions and release notes for MPSIM to see any additional info that applies to timer 1.
     
Loading...