1Hz clock using Timer3, 32.768kHz crystal and runs badly on 18F26k22


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1

    Default 1Hz clock using Timer3, 32.768kHz crystal and runs badly on 18F26k22

    I have been building clocks for a while and have sometried and tested code which works great on an 18F25k22. I need to add some more features to the device which uses this so I am stepping up to the 18f26k22 just for the larger memory.

    When i run the code which worked on the 18f25k22 on the 18f26k22, the clock increments randomly by 2 seconds when it should only increment by 1.

    I have a 32.768kHz on the secondary oscillator input pins (with suitable caps)
    Using timer 3, no prescaler and prelaod of 128 in TMR3H each epoch.

    An interrupt is generated every 1 second when timer 3 rolls over and my code simply increments the 'Seconds' register...when that reaches 60 it is reset and minutes is incremented and so on.

    The code has been perfectly behaved on the 25k22, but now, compiled for the 26k22 the seconds counter is sometimes incremented by 2 when it should only increment by 1

    I have tried adding new variable for seconds called Seconds2 ( in case it was a memory location issue. I have tried stopping the timer3 from running, T3CON.0 = 0, before writing to it. I have tried everything I can think of, but I can't seem to get it to behave with the 26k22.

    I have several boards of identical circuits, whichever has the 26k22 chip has the problem and the fault moves with the chips. I have had this with a batch of SDIP 26k22's and a couple of SOIC 26k22's

    I've looked at the .inc files (Pbasic and Mchip's own) and can't see any reason for a difference between these devices, so now I am stuck, is it a Pbasic issue or a MPASM issue ? The only difference between these two chips is that the 26k22 gains 32k more memory over the 25k22, otherwise they seem to be identical.

    Has anyone got any experience with something as odd as this ? For comparisons I've used CPFSEQ and CPFSGT instead of the longhand XORLW too, but nothing makes an difference. It is almost as if with the 26k22 version the TMR3 overflow isn't interrupt isn't being cleared and the code is run through twice, but I am clearing the interrupt and reloading the TMR3 registers manually.


    Chris

    Code:
            
    btfss   PIR2,1   ; timer 3 rollover interrupt ? (1 second epoch)
            bra     INT_OUT
            bsf     _power
            btfss   PORTA,0
            bcf     _power
            bcf     T3CON,0  ; stop TMR3 prior to writing to it
            movlw   128
            movwf   TMR3H
            movf    _timer3l_buffer,w  ; compensation value for low voltage
            btfss   STATUS,Z
            movwf   TMR3L
            bsf     T3CON,0   ; re enable TMR3 after writing     
            bsf     _control,6 ; set 1 sec flag
            bcf     PIR2,1  ;clear interrupt
            incf    _seconds2,f
            movlw   60
            xorwf  _seconds2,w
            btfss   STATUS,Z
            bra     INT_OUT
            clrf    _seconds2
            incf    _Minutes,f
            movlw   60
            xorwf  _Minutes,w
            btfss   STATUS,Z
            bra     INT_OUT
            clrf    _Minutes
            incf    _Hours,f
            movlw   24
            xorwf  _Hours ,w
            btfss   STATUS,Z
            BRA     INT_OUT
            clrf    _Hours
            bsf     _control,2 ; set 'NEW DAY' flag

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: 1Hz clock using Timer3, 32.768kHz crystal and runs badly on 18F26k22

    I have an update on this issue.
    In my ISR I have interrupts created by timer 1 and timer 3. Timer 1 is used as a one-shot timer and timer 3 is used as the low frequency 1Hz generator.

    Timer 1 and timer 3 are identical peripherals, so I have simply renamed timer 1 registers to timer 3 registers and vice versa, and now the code works well on 26k22 as well as 25k22, with timer 1 running the 1 second epoch code.

    The only difference between timer 1 and timer 3 is that they use different peripheral interrupt enable registers, maybe there is an issue with that ?

    Chris

  3. #3
    Join Date
    Nov 2008
    Posts
    26


    Did you find this post helpful? Yes | No

    Default Re: 1Hz clock using Timer3, 32.768kHz crystal and runs badly on 18F26k22

    Hi Chris

    I had this problem on a 24k22, turned out to be the TxRD16 bit of TxCON being set for 16bit mode. Changing this to 8 bit mode solved it for me.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: 1Hz clock using Timer3, 32.768kHz crystal and runs badly on 18F26k22

    Quote Originally Posted by BH_epuk View Post
    Hi Chris

    I had this problem on a 24k22, turned out to be the TxRD16 bit of TxCON being set for 16bit mode. Changing this to 8 bit mode solved it for me.
    Hi, thanks for that.
    I did get around to suspecting that and tried changing between 16-bit and 8-bit modes but there was no difference - and I couldn't explain how it would make a difference because the 25k22 and 26k22, which use identical registers.

    The only difference between the two timers seems to be that they use different interrupt registers, not between devices though, so I still can't quite explain how the fault occurs

  5. #5
    Join Date
    Jan 2009
    Location
    Alabama,USA
    Posts
    232


    Did you find this post helpful? Yes | No

    Default Re: 1Hz clock using Timer3, 32.768kHz crystal and runs badly on 18F26k22

    Chris,
    I am trying to make the leap from 16F’ to 18F’s. I want to start with the 18F25k22. Would you mind sharing some 25k22 code? I would be interested in what your config’s look like for your 25k22 clock project?
    Thanks!
    Wayne

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: 1Hz clock using Timer3, 32.768kHz crystal and runs badly on 18F26k22

    Hello Wayne,
    there is probably little point in using my configs, unless yoiu plan to set up your pic to mimic mine.
    Your best way top approach it is to decide which peripherals you would like to use first of all, and then look in the MPASM directory for the 18F25k22.inc file. At the end of that file all of the correct mnemonics for the configs are listed.
    I generally copy the ones I want to use from the Microchip include file and put them in the Picbasic 18f25k22.inc include file to enable them.

    Chris

Members who have read this thread : 0

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