Timer 0 in DS_int_14 having a problem


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default Timer 0 in DS_int_14 having a problem

    Hi guys cant see what i am missing on this one , using DS_int_14 , to handle interupts call for timer 0 does not seem to activate

    the code compiles , no errors

    chip 16f1825

    i have setup intcon reg for 1:256 PSA ,
    its 8mhz clock
    timer 0 is using the internal clock

    the intent is timer 0 interupt every 25ms to go do subroutine _Timer0_Count

    which just counts the interupts till it reaches 1520 ( aprox 38sec) then call a subroutine to go and do stuff

    Note the other Int handler _getircode works

    any suggestions


    Cheers

    Sheldon

    Code:
    ' config for 16F1825             
    
    #CONFIG
    ;----- CONFIG1 Options --------------------------------------------------
      __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_ON
    
    ;----- CONFIG2 Options --------------------------------------------------
      __config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_HI & _LVP_OFF
    #ENDCONFIG
     
     ' ---------- Set up DT_INTS-14 Routine for Instant Interupt handling   -----------
    
    INCLUDE "DT_INTS-14.bas"
        
    INCLUDE "ReEnterPBP.bas"
    ASM
    INT_LIST macro	; IntSource  , Label        , Type, ResetFlag?
    
    		INT_Handler IOC_INT   , _GetIRcode   ,  PBP, yes      ; call GetIRcode subroutine on Interupt 
                    INT_Handler TMR0_INT , _Timer0_Count,  PBP, yes      ; call Timer0_Count subroutine
    	endm
    	INT_CREATE								; Creates the Interrupt Processor
    ENDASM
     
     
     '----------- 16F1825  - PIC chip settings --------------------                               
     
     OSCCON   = $70         ' Select 8Mhz , internal clock  
                            ' Bit 7 0 = 4xPLL disabled  1= 4xPLL enables ( overrided by conf word 2 setting -  PLLEN) 
                            ' bits6-3 -  1111 = 16Mhz , 1110 = 8MHz or 32Mhz ( depends on 4xPLL - conf word 2)  1101 = 4 MHz, 1100 = 2MHz 1011 = 1MHz 
                            ' bitS 0-1 - 00= Clock set by Conf word ,01 = Timer1 OSC , 1x = internal Osc Block 
     
     APFCON0 = %00000000	'All Default - No change when using SPI  use SDO1 = RC2 , bit6=0
     APFCON1 = %00000000	'All Default  APFCON1 = %00000000
     
     
     
     CM1CON0 = $00 	        ' Disable / Clear comparator 1
     CM1CON1 = $00 	        ' Used with CM1CON0
     CM2CON0 = $00 	        ' Disable / Clear comparator 2
     CM2CON1 = $00 	        ' Used with CM2CON0
     CMOUT   = $00          ' Disable Comparitors output register - used only if comparitor on
      
     ANSELA =  %00000000    ' Set Port A - Digital I/O  , 0 = Digital  1 = Analog
     ANSELC =  %00000000    ' Set Port C - Digital I/O  , 0 = Digital  1 = Analog
    
     INLVLA = %00000000	    ' Set Port A to TTL Levels 0 = TTL , 1 = SCHMITT TRIGGER - Used port reads and Interupt on Change 
     INLVLC = %00000000	    ' Set Port C to TTL Levels 0 = TTL , 1 = SCHMITT TRIGGER - Used port reads and Interupt on Change 
     SRCON0 = %00000000     ' Disable Latched Outputs 
     SRCON1 = %00000000     ' Used with SRCON0 register
    
     ADCON0 =  $00          ' Disable A/D 
     ADCON1 =  $00          ' Disable A/D  - used with ADCON0 settings
    
     WPUA   = %00001100	    '  Port A - Turn off week Pullups 1=ON , for each port ( globle enable set in option_reg.7)set wpu on PortA.3 as input only - ref spec 
     WPUC   = %00000000     '  Port C - Turn off week Pullups 1=ON   For each port 
    
     DACCON0 = $00          ' Disable D/A
     DACCON1 = $00          ' Disable D/A - used with DACCON0 
     FVRCON  = $00          ' Disable Fixed Voltage Ref
    
     INTCON = 0             ' Interupts Clear at start- GIE,PEIE,TMR0IE,INTE,IOCIE = on,TMR0IF,INTF,IOCIF
     IOCAN.4 = 1            ' Enable interupt on change on portA.4 for negative going edge  ( for getIR routine )
     IOCAF.4 = 0            ' Clear Interupt on Change flag on portA.4
     
     OPTION_REG.7 = 1       ' Weak Pullups disabled  1 = globel disable 0 = globel enable ( set by each port - WPUA & WPUC settings)
     OPTION_REG.6 = 0       ' Interupt on Falling Edge of INT pin  0= falling edge  1= rising edge 
     OPTION_REG.5 = 0       ' TMR0 clock source - 1=T0clk pin 0=internal clock
     OPTION_REG.4 = 0       ' TMR0 0=L/H of TOCKI pin  1=H/L of TOCKI pin 
     OPTION_REG.3 = 0       ' Use Prescaller for TMR0  0= Yes , 1 = No 
     OPTION_REG.2 = 1       ' Timer0 prescaler Rate Select bits 2-0(set to 1:256)
     OPTION_REG.1 = 1       ' 000 = 1:2  , 001= 1:4  , 010 = 1:8   , 011 = 1:16
     OPTION_REG.0 = 1       ' 100 = 1:32 , 101 = 1:64, 110 = 1:128 , 111 = 1:256 
     
     T1CON  = %01110100     ' Timer 1 ,bit7-6 = TMR1 CLK source 00 = Instuction Clk(Fosc/4),01 =sys clk,10=ext clk,11=cap sense osc
                            ' bit5-4 = TMR1 prescale 11= 1:8 ,bit3=0 LP off,bit2=1 no sync ext CLK ,bit1= 0 n/a,Bit0=0 Timer 1 on/off
     T1GCON = %00000000     ' Timer 1 Gate Control bit7 0= counts regardless of gate 1 = gates in use  , bit6 gate active when 1= High  ,0=low  
                            ' bit5 0= toggle mode diabled 1= enabled  bit4 single pulse mode 1- en 0= dis, bit 2 -status bit,1-0 - gate source sel 
                              
     T2CON  = %01110011     ' Timer 2 off + 1:15 postscale ,1:64 prescale ( bit 7 = x, bit6-3 1110 = 1:15 postscale, bit2=0 timer off ,bit1-0 = prescale 10 = 16 , 11= prescale 64   
     T4CON  = %00000000	    ' POSTSCALER 1/1,STOP,PRESCALER 1/1
     T6CON  = %00000000 	' POSTSCALER 1/1,STOP,PRESCALER 1/1
    
     TMR0 = 0               ' Clear TMR0 MODULE REGISTER
     
     TMR1H = 0              'CLEAR TMR1H MODULE REGISTER
     TMR1L = 0              'CLEAR TMR1L MODULE REGISTER
     
     TMR2 = 0		    	'CLEAR TMR2 MODULE REGISTER
     TMR4 = 0			    'CLEAR TMR4 MODULE REGISTER
     TMR6 = 0		     	'CLEAR TMR6 MODULE REGISTER
     
     'PR2 = 255              ' Timer 2 Preload value 
     'PR4 = 255              ' Timer 4 Preload value 
     'PR6 = 255              ' Timer 6 Preload value 
    
      
    
    DEFINE OSC 8             ' Timing referance for pause , pauseus commands 
    DEFINE PULSIN_MAX 21600  ' Maximum counts( clock ticks) allowed before pulsin times out( 21600 ^ 5ms =  108 ms)
                             ' Norm IR pulse length is 108ms   
    
    ' --------- PIC Timers & sync variables ------------
      T0Count  VAR WORD       ' varable in Timer 0 counter interupt handler
    
    @ INT_ENABLE IOC_INT	  ; Enable PortA Change on Interupt
    @ INT_ENABLE TMR0_INT     ; enable Timer 0 interupts 
    
    
    
    
    
    ' ============ Timer 0 Interupt handler ================ 
    
     Timer0_Count:
    
     T0Count = T0Count + 1                        ' inc counter on intrupt flag 
     TMR0 = 60                                         ' preload  256-196 = 60 to gen a 25ms timer using 1:256 prescale  
     if T0Count = 1520 then  Smooth_reset
    @ INT_RETURN

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: Timer 0 in DS_int_14 having a problem

    Hi,

    I just wonder if your TMR 0 interrupt flag is correctly reset ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Timer 0 in DS_int_14 having a problem

    tried adding INTCON.2 = 0
    in the called sub but it did not seem to make any dif , it seems the subroutine is never called ???

  4. #4
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Timer 0 in DS_int_14 having a problem

    mmm, the general routine seems to work on the 12F683 via a simulator , but not on the 16F1825 , i dont have a simulator for the 16f1825 atm

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Timer 0 in DS_int_14 having a problem

    Try not leaving the interrupt before it is finished.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Cool Re: Timer 0 in DS_int_14 having a problem

    found problem :

    " INTCON = 0 ' Interupts Clear at start- GIE,PEIE,TMR0IE,INTE,IOCIE = on,TMR0IF,INTF,IOCIF

    Was set after setting up the ASM calls for DT_int_14 started , which cleared its good work , not clear why it did not effect other routine that uses IOCIF , perhaps cos i clear and set the individual int flags for IOC on this chip ???

    also , the DT_int_14 does not clear the timer0 int flag and needs to be done in the service routine , adding stop and start timer 0 to the routine was required and should have been there to start with , dont think DT_int_14 would/ should do that as its just monitors the int flag


    so the commands for the int call routine are

    1. INTCON.5 = 0 ' stop timer 0

    2. go do what u want to do
    4. TMR0 = 60 ' reload timer 0 start point constant
    5. INTCON.5 = 1 ' start timer 0
    6. @ INT_RETURN

  7. #7
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Timer 0 in DS_int_14 having a problem

    one item i am noticing is that if the INT routine call has a another sub routine that is activated within it it does not seem to return back to the org int call , i am i missing something ?

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,523


    Did you find this post helpful? Yes | No

    Default Re: Timer 0 in DS_int_14 having a problem

    That's what Dave was trying to say. You have the following line in your ISR
    Code:
    if T0Count = 1520 then  Smooth_reset
    This is effectively a GOTO so the execution jumps to the Smooth_reset routine and doesn't return to the ISR from there.

    /Henrik.

  9. #9
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Wink Re: Timer 0 in DS_int_14 having a problem

    thanks Hendrick , i did not follow what he ment by the comment

    I eventually found that code
    Code:
     if (T0Count = Smoothfade) and Fade_flag = 2 then Smooth_reset
    was not returning , thought it was acted upon the same as

    Code:
     if (T0Count = Smoothfade) and Fade_flag = 2 then gosub Smooth_reset
    but it is not , as you say , the first is a goto and 2nd statement with the " gosub" returns and works fine


    Well something i did not know, i know now


    More fun learning ahead

    Cheers

    sheldon

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,523


    Did you find this post helpful? Yes | No

    Default Re: Timer 0 in DS_int_14 having a problem

    Yeah, a subroutine must always end with a RETURN and must always be jumped to with a GOSUB.
    If you GOTO a subroutine it will fail badly once it hits the RETURN statement because it will then "return" to the wrong place because the correct place hasn't been stored.

    * Never GOSUB anything not ending with RETURN.
    * Never GOTO anything which does end with RETURN.

    The manual is pretty clear on that specifying a label in an IF statement causes a GOTO when the expression is evaluated true.

    I'm glad you're moving forward!
    /Henrik.

  11. #11
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Timer 0 in DS_int_14 having a problem

    cheers Hendrick

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