Question for Mr. Darrel Taylor and Mister-e Timer1 Reload


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,680


    Did you find this post helpful? Yes | No

    Default Re: Question for Mr. Darrel Taylor and Mister-e Timer1 Reload

    if using the appropriate reload and preload as calculated is not keeping good time then it means you xtal frequency is slightly off (as pedja089 suggested 1 to 5 % error is to be expected) , you might try trimming the capacitors on the crystal (might take a bit of experimenting if you haven't got a frequency counter) , changing the preload + or minus 1 will probably be too coarse an adjustment . you need to keep in mind that xtal ocillators aren't atomic clocks and that the osc frequency will be temperature dependant and will drift over time .
    another possibility is adding or subtracting the "error" say once per day, this was used in a slicon chip magazine project (pic toc )many years ago and was suprisingly good at time keeping .

  2. #2
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Re: Question for Mr. Darrel Taylor and Mister-e Timer1 Reload

    Ok, thank you Richard.
    I'll try to get a freq meter and see what exactly going to the oscillator.

    The chip I'm using is PIC 18F4685. What about to connect a 32768Hz watch quartz in order to feed the Timer1?
    I've had no experience yet with this approach so I don't know yet what exactly I'm talking about.
    All I need is to interrupt each exactly 100ms. It is possible to have that using the Timer1 feeded by an external source? And if so, using what setup?

    Thanks in advance.
    Regards,
    Mike.

  3. #3
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Question for Mr. Darrel Taylor and Mister-e Timer1 Reload

    10Hz interrupt is problem to derive from 32768Hz. 16Hz or 32Hz etc isn't problem. To get 1sec just count 16 interrupts, and that is all.
    I posted RTC code, with external crystal, 32 interrupts per second, and it consumes less than 10uA if you put pic in sleep mode.

  4. #4
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Re: Question for Mr. Darrel Taylor and Mister-e Timer1 Reload

    NICE!
    Where I can see that code?

    Thank you.

  5. #5
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Question for Mr. Darrel Taylor and Mister-e Timer1 Reload

    I can't find that topic...
    Here is cut/paste from my code for PIC18LF14K50
    Code:
            DEFINE  OSC 4         
            Define  INTHAND myint    ' Define interrupt handler
            DEFINE  NO_CLRWDT 1
    
            OSCCON=%01010110
            OSCCON2.2=0
            OSCTUNE.7=1
            OSCTUNE.6=1
            REFCON0=0
            REFCON1=0
            ADCON1=0
            ADCON2=0
            ANSEL =0           
            ANSELH=0
            CM1CON0=0
            CM2CON0=0
            SRCON0=0
            SRCON1=0
            WPUA=0
            WPUB=0
            WDTCON=0   
            SLRCON=0           
            RCON.7=0
            RCON.6=0   
            UCON=0  
            IOCA=0
            IOCB=0
            T0CON=0
            T1CON=%00001111  
            T2CON=0
            T3CON=%00000110
            INTCON=192  
            INTCON2=0  
            INTCON3=0 
            PIR1=0
            PIR2=0
            PIE1=1
            PIE2=0
            IPR1=0
            IPR2=0
            porta=0
            portb=0
            portc=0
            trisa=255
            trisb=255
            trisc=255
    
    
    
    
    'RTC_________________________
    Seconds        VAR BYTE bankA  
    Minutes        VAR Byte bankA       
    Hours          var byte bankA
       
    
    
    
     
     clear
    
    GoTo OverInt  ' jump over the interrupt handler and sub
    ASM                  
    myint 
     movlb .0
     ;If PIR1.0 =1 then
     BTFSS PIR1,0 
     GOTO End_RTC 
     MOVLW .252 ; TMR1H=252
     MOVWF TMR1H
     CLRF PIR1 ; Clear TMR1 int flag
     INCF _Ticks,F 
     ;if ticks>31 then
     MOVLW .31
     CPFSGT _Ticks  
     GOTO End_RTC   
        INCF _Seconds,F  
        CLRF _Ticks
        ; if seconds > 59 then
        MOVLW .59         
        CPFSGT _Seconds   
        GOTO End_RTC   
           CLRF _Seconds   
           INCF _Minutes,F
           ;if minutes > 59 then
           MOVLW .59         
           CPFSGT _Minutes   
           GOTO End_RTC      
              CLRF _Minutes
              INCF _Hours,F
              ;if hours > 23 then 
              MOVLW .23       
              CPFSGT _Hours   
              GOTO End_RTC    
                  CLRF _Hours
    End_RTC                                      
    ;Do your other stuff here
     retfie  FAST  
    ENDASM  
    OverInt:
    
    Main:
    @ Sleep
    'program starts here 32 times in sec
    goto Main
    This is example for PIC's that have fast return stack, and saves and restores WREG, STATUS and BSR registers...

  6. #6
    Join Date
    Aug 2006
    Location
    Italy
    Posts
    72


    Did you find this post helpful? Yes | No

    Default Re: Question for Mr. Darrel Taylor and Mister-e Timer1 Reload

    Thank you a lot.

  7. #7
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Question for Mr. Darrel Taylor and Mister-e Timer1 Reload

    Just one more thing that I had to deal with...
    Selection of crystal and capacitors from OSC pins to ground is critical to get accurate clock. I tried one by one from 10 to 47pF, and best results are with 47pF. But that will depend from board layout and used crystal.
    My suggestion is that you buy a lot of crystals, and select appropriate capacitor for it. And use that combination from now.

Similar Threads

  1. Darrel Taylor Interrupts and MultiCalc
    By AvionicsMaster1 in forum General
    Replies: 6
    Last Post: - 14th February 2012, 06:18
  2. Timer1 and Timer2 interrupts, Darrel Taylor
    By ronbowalker in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th December 2009, 18:38
  3. To Mr. Darrel Taylor once again
    By atwoz in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 10th December 2009, 19:10
  4. Darrel Taylor Elapsed Timer
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th March 2008, 01:22
  5. @Darrel Taylor Interrupt ;-)
    By Robson in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 31st August 2007, 00:59

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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