Troubled with Instant Ints and TMR2


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1

    Default Troubled with Instant Ints and TMR2

    Hello....
    I have been looking at this code all the day and cant find my mistake

    i am using a 420Hz frequency as input to the Comparator in 16f628, the signal is correctly biased to 2.5v and Vref is set to Vcc/2.

    So now... i am trying to sample this signal into a Bits array and then sending through serial port.

    Code:
    <font color="#000080"><i>;----[ Change these to match your LCD ]---------------------------------------
    </i></font>LCD_DB4         <b>VAR </b>PORTA.6
    LCD_DB5         <b>VAR </b>PORTB.6
    LCD_DB6         <b>VAR </b>PORTB.5
    LCD_DB7         <b>VAR </b>PORTB.4
    LCD_RS          <b>VAR </b>PORTA.0
    LCD_E           <b>VAR </b>PORTA.7
    LCD_Lines       <b>CON </b>2    <font color="#000080"><i>' # of Lines on LCD,  1 or 2 (Note: use 2 for 4 lines)
    </i></font>LCD_DATAUS      <b>CON </b>50   <font color="#000080"><i>' Data delay time in us 
    </i></font>LCD_COMMANDUS   <b>CON </b>2000 <font color="#000080"><i>' Command delay time in us 
    
    
    </i></font><b>INCLUDE </b><font color="#FF0000">&quot;LCD_AnyPin.pbp&quot;  </font><font color="#000080"><i>; *** Include MUST be AFTER LCD Pin assignments ****
    </i></font><b>INCLUDE </b><font color="#FF0000">&quot;DT_INTS-14628.bas&quot;
    </font><b>INCLUDE </b><font color="#FF0000">&quot;ReEnterPBP.bas&quot;
    </font><b>INCLUDE </b><font color="#FF0000">&quot;modedefs.bas&quot;
    </font><b>INCLUDE </b><font color="#FF0000">&quot;Elapsed_INT628b2.bas&quot;
     
    </font><b>DEFINE </b>OSC 4
    <b>DEFINE </b>HSER_RCSTA 90h <font color="#000080"><i>' Set transmit register to transmitter enabled
    </i></font><b>DEFINE </b>HSER_TXSTA 24h <font color="#000080"><i>' Set baud rate
    </i></font><b>DEFINE </b>HSER_BAUD 9600
    <b>DEFINE </b>HSER_CLROERR 1
    
    PinActivar      <b>VAR </b>portb.0
    PinDescuelgue   <b>VAR </b>porta.5
    PinPolaridad    <b>VAR </b>porta.4
    InZCD           <b>VAR </b>porta.2
    PinDTMF         <b>VAR </b>portb.7
    PinOffHook      <b>VAR </b>portb.3
    TMR2_clock      <b>VAR WORD
    </b>FlagSample      <b>VAR BIT
    </b>NumSamples      <b>VAR BYTE
    </b>Samples         <b>VAR BIT </b>[124]
    x               <b>VAR BYTE
    
    ASM
    </b><font color="#008000">INT_LIST  macro    </font><font color="#000080"><i>; IntSource,        Label,  Type, ResetFlag?
            </i></font><font color="#008000">INT_Handler   TMR2_INT,  _Sample,   PBP,  yes
        endm
        INT_CREATE               </font><font color="#000080"><i>; Creates the interrupt processor
    </i></font><b>ENDASM
    </b><font color="#008000">@    INT_ENABLE  TMR2_INT     </font><font color="#000080"><i>; Enable Timer 1 Interrupts  
    
    ;----[ Your Main program starts here ]----------------------------------------
    </i></font>LoopCount  <b>VAR WORD
    
    </b>Config:
             trisb.0=0
             trisa.5=1
             trisa.4=1
             trisa.2=1
             trisb.7=0
             trisb.3=0
             CMCON = 5
             VRCON = %11101100
             OPTION_REG = %00000000 
             T2CON = %00000000 <font color="#000080"><i>' TMR2 prescale 1:1     
             </i></font><b>PAUSE </b>500 : <b>LCDOUT </b>$FE,1 : <b>PAUSE </b>250
             PR2 = 125 <font color="#000080"><i>' load tmr2 PR2 to reset every 1ms
    
    </i></font>MAIN:
        <b>HIGH </b>PINACTIVAR
        <b>GOSUB </b>GETSAMPLE
        <b>PAUSE </b>1000
    <b>GOTO </b>MAIN
    
    GetSample:
        T2CON.2 = 1
        NumSamples = 0
        FlagSample = 0
        <b>WHILE </b>FlagSample = 0
        <b>WEND
        HSEROUT </b>[<font color="#FF0000">&quot;:&quot;</font>,10,13]
        <b>FOR </b>x = 0 <b>TO </b>119   
              <b>HSEROUT </b>[<b>DEC </b>Samples [x],10,13]
        <b>NEXT </b>x
        <b>RETURN
       
    </b>Sample:
        Samples [NumSamples] = CMCON.7
        NumSamples = NumSamples + 1
        <b>IF </b>NumSamples = 120 <b>THEN
                </b>FlagSample = 1
                T2CON.2 = 0
        <b>ENDIF
    </b><font color="#008000">@ INT_RETURN
    
    </font></code></pre><!--EndFragment--></body>

    My problem is that the frequency sample doesnt match, it seems like the interrupt period is not consecuent with my need..


    I am using PR= 125, and with internal clock 4Mhz this should interrupt 0.000125s or 8000Hz.

    This doesnt seemd to be the case. Please any advice on how to interrupt with this TMR2 each 125uS.

    How can i confirm that my program is interrupting every 0.000125 Seconds?, maybe i am wrong somewhere else.

    Thanks for any help

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Code:
    INCLUDE "LCD_AnyPin.pbp"  ; *** Include MUST be AFTER LCD Pin assignments ****
    INCLUDE "DT_INTS-14628.bas" ' * * * * * this one * * * *
    INCLUDE "ReEnterPBP.bas"
    INCLUDE "modedefs.bas"
    INCLUDE "Elapsed_INT628b2.bas" ' * * * * and this one * * * *
    Are the files marked ' * * * * this one * * * * altered from Darrels originals ?

    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System

    INCLUDE "Elapsed_INT.bas" ' Elapsed Timer Routines

    Or did I miss one of Darrel's Masterpiece releases ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    is it me or you should use TMR2 instead of PR2?

    Try TMR2=TMR2+138 (or something around it) and toggle a led to know what happen

    i'm a bit rusty here... and i can't test it... damn!
    Last edited by mister_e; - 3rd October 2007 at 23:15.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Joe,
    no you didn't miss something, probably because Josuetas got a error message about a wsave beyond ram end or something like that.

    So my guess is that he comment out the offending line in those files and use a specific name for it.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5


    Did you find this post helpful? Yes | No

    Unhappy Thanks for your replies

    Joe S.

    Modifications...
    i have a DT for 628A since it needs bank modification from 877A.
    In the second one i am modifing Elapsed to interrupt every 125us it is not meant for timing but for interrupting. All i did was modifing the timerconst to be $FFA7 in the case of 4Mhz Osc. I am not using this anyway you can see the TMR1 interrupt is not defined for elapsed interrupt, only TMR2.



    mister_e

    If i get this right, and from the datasheet the timer2 interrupts when Tmr2 reaches PR2 value, tmr2 "should" go to 0 after this, BUT it seemed not TO i had to turn TMR2= 0 in the interrupt routine, Otherwise i was getting weird interruptions (watched it on my osciloscope)




    Still cant get my 125us interrupt with 4Mhz internal OSC this should be possible unless DT´s routines take more than 125 instructions to work (just my guess),.. Patience....Again i am sure HE knows

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    oups... missed the Elapsed timer... i'll read the according posts/thread about it as i never used it.

    Sorry
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7


    Did you find this post helpful? Yes | No

    Lightbulb I just doesnt work.. Impossible?

    Ok i figured out a way to measure my interrupts.

    The interrupt routine simply Toggles a pin of the micro on each interrupt and i measure such pin with my oscilloscope. The frequency of sampling is wrong.

    Problems:

    1. The TMR2 doesnt just go back to 0 after reaching PR2 value.. i had to set it to 0 otherwise i get unwanted interrupts.

    2. I cant believe this to be impossible so i made a small RX int.... when i press "1" PR increases by one.. else it goes down one, so i can sweep controlling by my keyboard. RESULT: No No it doesnt work.... i never get to my 125us interrupt it suddenly jumps back to the lower frequency after a point.

    Is 125us to much to ask for 4Mhz.. teorically i would say No.. 125 instructions are a lot of instructions... and i am only sampling at this point of my software so: what could be the problem?

    I cant use other OSC since i am using internal OSC and A7 pin for other purpouses... Since i am only sampling would something like pauseuS 125 : sample work?... What should be the timing consideration in this case?

    i still need someting like:

    Code:
    Sample:
        pauseus 125
        Samples [NumSamples] = CMCON.7
        NumSamples = NumSamples + 1
        IF NumSamples = 120 THEN return
        goto Sample
    How many instructions take this sub to work? i guess i have to take them into account for my timing to be correct!!!

    Thanks on any help.. Interrupt 125uS 4Mhz still in need!!

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Josuetas View Post
    Still cant get my 125us interrupt with 4Mhz internal OSC this should be possible unless DT´s routines take more than 125 instructions to work (just my guess),.. Patience....Again i am sure HE knows
    This page might explain it.
    http://darreltaylor.com/DT_INTS-14/kudos.html
    Especially the last paragraph.
    <br>
    DT

  9. #9


    Did you find this post helpful? Yes | No

    Red face Ok now thats bad news

    So Darrel if i made this with just an ASM interrupt i would be able to get my 125uS since i wouldnt need the Reenter Context Saving...


    BUT please o please can you help me?..

    I use to get to this point where: i dont know any assembler!!!
    even worst
    A bit Array of 120 samples in Assembler .... mmm..... mmmmm....

    By the way would you consider (in my case) the pauseus 125 Take Sample option?

    Please some lead to solve this matter.

    Thanks again

    DJC

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