How to operate a PIC12F724 Timer 1

Discussion in 'Embedded Systems and Microcontrollers' started by lexdean, Jan 23, 2010.

  1. lexdean

    Thread Starter New Member

    Jan 22, 2010
    2
    0
    Hi all

    The literature is very misleading in its wording
    I get everything else ok

    I can handle the pre scaling and timing count of the timer as I want it to run as long as possible (about 3.8 times a second)

    I'm wanting a continuous synchronous timer running on the internal 8 MHZ clock
    I want it to trigger the interrupt at the end of its count.

    What register set were

    how
    best regards,
    Lex Dean
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    This is for 12F675 - check the banks of all the Special Function Registers as they tend to move around on different chips - hopefully the 724 isn't too different.
    I've deleted all but the important stuff for the timer interrupt - on a 675 at 4MHz this gives 2 interrupts per second.

    Code ( (Unknown Language)):
    1.  
    2.     list    p=12F675
    3.     radix    hex
    4.     title "sound"
    5.         #include <p12f675.inc>
    6.     __config _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
    7.  
    8.  
    9.     cblock 0x20
    10.     W_TEMP
    11.     STATUS_TEMP  
    12.     endc
    13.  
    14. ;    
    15. ;----------------------------------------------------------------------
    16.  
    17.     org    0x000
    18.     goto init
    19.     org 0x004    ;interrupt goes here
    20.     MOVWF W_TEMP ; Copy W to TEMP register,
    21.     SWAPF STATUS, W ; Swap status to be saved into W
    22.     MOVWF STATUS_TEMP ; Save status to STATUS_TEMP register
    23.     ;ISR : :
    24.          ; Interrupt Service Routine
    25.  
    26.    
    27. endint
    28.      ; should configure Bank as required
    29.      ;
    30.     SWAPF STATUS_TEMP,W     ; Swap nibbles in STATUS_TEMP register
    31.     ; and place result into W
    32.     MOVWF STATUS             ; Move W into STATUS register
    33.     ; (sets bank to original state)
    34.     SWAPF W_TEMP, F         ; Swap nibbles in W_TEMP and place result in W_TEMP
    35.     SWAPF W_TEMP, W         ; Swap nibbles in W_TEMP and place result into W
    36. ;    CLRF TMR1L                 ; Clear Low byte, Ensures no rollover into TMR1H
    37. ;    movlw 0xC0                ;set up timer1
    38. ;    movwf TMR1H
    39. ;    clrf TMR1L
    40.     clrf INTCON                ;clr interupts
    41.     bsf INTCON,PEIE            ;timer1 interrupt on
    42. ;    bsf INTCON, GPIE        ;gpio change interrupt on
    43.     bcf PIR1, 0            ;clr tmr1 interrupt flag
    44.     retfie
    45.    
    46. init    ;initialise stuff here
    47.    
    48.     movlw B'00110001'
    49.     movwf T1CON                ;enable timer1 internal 1:8 prescaler
    50.     BSF STATUS, RP0 ; Bank 1
    51.    
    52.     bsf PIE1, 0                ;timer1 int enabled
    53. ;    BSF STATUS, RP0 ; Bank 1    
    54.     clrf   OPTION_REG      ;
    55.     bcf     STATUS, RP0    ; bank 0    
    56.     movlw   B'01000000'     ; enable timer 1 interrupt (not GIE yet)
    57.     movwf   INTCON          ;  
    58.     CLRF TMR1L                 ; Clear Low byte, Ensures no rollover into TMR1H
    59.     clrf TMR1H
    60.    
    61.     bsf INTCON, GIE            ;enable interrupts, then sleep
    62.  
    63. main
    64.    
    65.  
    66.  
    67.     goto main
    68.  
    69.     end
    70.  
     
  3. lexdean

    Thread Starter New Member

    Jan 22, 2010
    2
    0
    Hay thanks
    I can follow that

    You made my day
     
Loading...