Can Timer0 be used instead of Timer1 in DT Blinky?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597

    Default Can Timer0 be used instead of Timer1 in DT Blinky?

    Is it possible to use Timer0 instead of Timer1 on a 18F4550 using Darrel's blinky program?

    Code:
    @   __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @   __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
    @   __CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_1_2L & _VREGEN_ON_2L
    @   __CONFIG    _CONFIG2H, _WDT_OFF_2H
    @   __CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    @   __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
    
    DEFINE OSC 48
        ADCON1 = %00001111
        INTCON2 = %00000000
    
        T0CON = %10000000                   ; Prescaler = 2
    '    T0CON = %10000001                   ; Prescaler = 4
    '    T0CON = %10000010                   ; Prescaler = 8
    '    T0CON = %10000011                   ; Prescaler = 16
    '    T0CON = %10000100                   ; Prescaler = 32
    '    T0CON = %10000101                   ; Prescaler = 64
    '    T0CON = %10000110                   ; Prescaler = 128
    '    T0CON = %10000111                   ; Prescaler = 256
    '      bit 7 TMR0ON: Timer0 On/Off Control bit
    '              1 = Enables Timer0
    '              0 = Stops Timer0
    '      bit 6 T08BIT: Timer0 8-Bit/16-Bit Control bit
    '              1 = Timer0 is configured as an 8-bit timer/counter
    '              0 = Timer0 is configured as a 16-bit timer/counter
    '      bit 5 T0CS: Timer0 Clock Source Select bit
    '              1 = Transition on T0CKI pin
    '              0 = Internal instruction cycle clock (CLKO)
    '      bit 4 T0SE: Timer0 Source Edge Select bit
    '              1 = Increment on high-to-low transition on T0CKI pin
    '              0 = Increment on low-to-high transition on T0CKI pin
    '      bit 3 PSA: Timer0 Prescaler Assignment bit
    '              1 = TImer0 prescaler is NOT assigned. Timer0 clock input bypasses prescaler.
    '              0 = Timer0 prescaler is assigned. Timer0 clock input comes from prescaler output.
    '      bit 2-0 T0PS2:T0PS0: Timer0 Prescaler Select bits
    '              111 = 1:256 Prescale value
    '              110 = 1:128 Prescale value
    '              101 = 1:64 Prescale value
    '              100 = 1:32 Prescale value
    '              011 = 1:16 Prescale value
    '              010 = 1:8 Prescale value
    '              001 = 1:4 Prescale value
    '              000 = 1:2 Prescale value
    
    INCLUDE "DT_INTS-18.bas"            ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"         ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR0_INT,  _ToggleLED,   PBP,  yes
        endm
        INT_CREATE                      ; Creates the interrupt processor
    ENDASM
    
    DEFINE  LCD_DREG      PORTD
    DEFINE  LCD_DBIT      4
    DEFINE  LCD_RSREG     PORTE
    DEFINE  LCD_RSBIT     0
    DEFINE  LCD_EREG      PORTE
    DEFINE  LCD_EBIT      1
    DEFINE  LCD_BITS      4
    DEFINE  LCD_LINES     2
    DEFINE  LCD_COMMANDUS 1000
    DEFINE  LCD_DATAUS    50
    
        TRISA = %00000000
        TRISB = %00000000
        TRISC = %00000000
        TRISD = %00000000
        TRISE = %00000000
    
    LED1  VAR  PORTD.0
    LED2  VAR  PORTD.1
    
    @ INT_ENABLE  TMR0_INT              ; enable Timer 0 interrupts
    
        PAUSE 1500                      ' wait for PIC and LCD to stabilize
        LCDOUT  $FE,1,"Timer test Lab X1"
    
    Main:
        TOGGLE LED2
        PAUSE 500
    GOTO Main
    
    ToggleLED:
         TOGGLE LED1
    @ INT_RETURN
    END
    Darrel's blinky code works just fine at Prescaler 1 with Timer1 but I can't seem to get any variation in blink speed out of Timer0. I tried a gazillion combinations and I admit I'm not sure about the other settings in T0CON.

    I don't have access to a scope right now and this desktop doesn't have enough memory to run Saleae from 1MHz and up.

    LED2 was added to confirm I didn't screw up the PIC and it is blinking as expected. LED1 seems to be blinking very fast because it is just slightly paler than the other LEDs on the Lab X1 bargraph.

    Or are the blinking so fast at any prescaler that I won't be able to see a difference? I was able to detect "very fast" blinking in Timer1 at 1:1 though.

    Robert
    PBP v2.60c
    Last edited by Demon; - 15th April 2015 at 02:33.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Can Timer0 be used instead of Timer1 in DT Blinky?

    works for me pic18f45k20

    Code:
    ,****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 4/14/2015                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
     #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRT = OFF
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 18
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 512
      CONFIG  CCP2MX = PORTC
      CONFIG  PBADEN = OFF
      CONFIG  LPT1OSC = OFF
      CONFIG  HFOFST = ON
      CONFIG  MCLRE = ON
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
    
    
      define OSC 64
     osccon=$70   '64 mhz
     OSCTUNE.6=1
     
     
     
     pause 2000
     
    Serout2 PORTb.7,84,["ready",13,10] 
     
     
     '    T0CON = %10000000                   ; Prescaler = 2
    '    T0CON = %10000001                   ; Prescaler = 4
     '   T0CON = %10000010                   ; Prescaler = 8
     '   T0CON = %10000011                   ; Prescaler = 16
     '   T0CON = %10000100                   ; Prescaler = 32
      T0CON = %10000101                   ; Prescaler = 64
    '    T0CON = %10000110                   ; Prescaler = 128
    '    T0CON = %10000111                   ; Prescaler = 256
    '      bit 7 TMR0ON: Timer0 On/Off Control bit
    '              1 = Enables Timer0
    '              0 = Stops Timer0
    '      bit 6 T08BIT: Timer0 8-Bit/16-Bit Control bit
    '              1 = Timer0 is configured as an 8-bit timer/counter
    '              0 = Timer0 is configured as a 16-bit timer/counter
    '      bit 5 T0CS: Timer0 Clock Source Select bit
    '              1 = Transition on T0CKI pin
    '              0 = Internal instruction cycle clock (CLKO)
    '      bit 4 T0SE: Timer0 Source Edge Select bit
    '              1 = Increment on high-to-low transition on T0CKI pin
    '              0 = Increment on low-to-high transition on T0CKI pin
    '      bit 3 PSA: Timer0 Prescaler Assignment bit
    '              1 = TImer0 prescaler is NOT assigned. Timer0 clock input bypasses prescaler.
    '              0 = Timer0 prescaler is assigned. Timer0 clock input comes from prescaler output.
    '      bit 2-0 T0PS2:T0PS0: Timer0 Prescaler Select bits
    '              111 = 1:256 Prescale value
    '              110 = 1:128 Prescale value
    '              101 = 1:64 Prescale value
    '              100 = 1:32 Prescale value
    '              011 = 1:16 Prescale value
    '              010 = 1:8 Prescale value
    '              001 = 1:4 Prescale value
    '              000 = 1:2 Prescale value
    
    INCLUDE "DT_INTS-18.bas"            ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"         ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR0_INT,  _ToggleLED,   PBP,  yes
        endm
        INT_CREATE                      ; Creates the interrupt processor
    ENDASM
    
    
        TRISA = %00000000
        TRISB = %00000000
        TRISC = %00000000
        TRISD = %00000000
        TRISE = %00000000
    
    LED1  VAR  PORTD.0
    LED2  VAR  PORTD.1
    
    @ INT_ENABLE  TMR0_INT              ; enable Timer 0 interrupts
    
        PAUSE 1500                      ' wait for PIC and LCD to stabilize
        LCDOUT  $FE,1,"Timer test Lab X1"
    
    Main:
        TOGGLE LED2
        PAUSE 500
    GOTO Main
    
    ToggleLED:
         TOGGLE LED1
    @ INT_RETURN
    END

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Can Timer0 be used instead of Timer1 in DT Blinky?

    Thanks Richard, it works now?

    The only thing I've done is awaken the PC from sleep, but I don't see how that could have changed something.

    Sincerely,
    Confused in Montreal

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Can Timer0 be used instead of Timer1 in DT Blinky?

    I do most of my programing with a pickit2 , I reckon every now and then (when I'm not alert) the hex file does not refresh after compiling , and then I keep blowing the same old code into the chip. this causes paranoia to set in

Similar Threads

  1. Counting Timer0 and Timer1 overflows without any interrupt handler
    By dw_picbasic in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 16th March 2015, 21:33
  2. MIBAM blinky on 16f628
    By ShoKre in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th December 2013, 08:58
  3. Synchronising Timer0 and Timer1
    By manxman in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th April 2008, 23:12
  4. My first Blinky!
    By nomad in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 25th September 2007, 17:29
  5. 16F690 TIMER0 and TIMER1
    By nickdaprick in forum mel PIC BASIC
    Replies: 2
    Last Post: - 18th April 2007, 14:49

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