Performing a loop every 10ms


Closed Thread
Results 1 to 40 of 41

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    It's suppoased to be a loop every 10ms.
    Not an insult every 10 ms.

    It's like a "Pack of Wolves".
    And wasssup didn't start anything.

    Y'all need to mellow out, and write some code.

    Here's mine...

    [code]ReadingTaken VAR BIT
    TRM0IF VAR INTCON.2
    TMR0IE VAR INTCON.5
    TimerReload CON 60

    ....


    Minor correction to DT's code above:
    TRM0IF VAR INTCON.2 should be TMR0IF VAR INTCON.2

    Also, I agree with DT. Here is my code thingie with my approach:

    1.03mS interrupt at 4 MHz, 1:4 Prescaler Assigned to TMR0.
    This works the opposite way of what DT does.
    DT's code interrupts every 10mS, my code interrupts every 1mS.
    Work on either one.


    Code:
    <font color="#008000">@ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,PROTECT_ON,CPD_ON, BOD_OFF
    
    </font>SetAll:
      <font color="#000080"><b>CLEAR
    </b></font>TRISA = <font color="#FF0000"><b>%00000000       
    </b></font>TRISB = <font color="#FF0000"><b>%00000000       
    </b></font>CMCON = <font color="#FF0000"><b>7               
    </b></font>VRCON.<font color="#FF0000"><b>7 </b></font>= <font color="#FF0000"><b>0
    </b></font>VRCON.<font color="#FF0000"><b>6 </b></font>= <font color="#FF0000"><b>0
    
    </b></font>PORTA = <font color="#FF0000"><b>0
    </b></font>PORTB = <font color="#FF0000"><b>0
    
    </b></font>TimeAdder <font color="#000080"><b>VAR BYTE
    
    </b></font>OPTION_REG.<font color="#FF0000"><b>5 </b></font>= <font color="#FF0000"><b>0     </b></font><font color="#000080"><i>' TMR0 internal clk select bit.
    </i></font>OPTION_REG.<font color="#FF0000"><b>3 </b></font>= <font color="#FF0000"><b>0     </b></font><font color="#000080"><i>' Prescaler Assigned to TMR0.
    </i></font>OPTION_REG.<font color="#FF0000"><b>2 </b></font>= <font color="#FF0000"><b>0     </b></font><font color="#000080"><i>' Bit 2,1,0 : 1:4 prescaler.
    </i></font>OPTION_REG.<font color="#FF0000"><b>1 </b></font>= <font color="#FF0000"><b>0 
    </b></font>OPTION_REG.<font color="#FF0000"><b>0 </b></font>= <font color="#FF0000"><b>1
    
    </b></font>T0IE <font color="#000080"><b>VAR </b></font>INTCON.<font color="#FF0000"><b>5  </b></font><font color="#000080"><i>'INTCON.5 = 1 ' Enable TMR0 interrupt.
    </i></font>T0IF <font color="#000080"><b>VAR </b></font>INTCON.<font color="#FF0000"><b>2  </b></font><font color="#000080"><i>'INTCON.2 = 0 ' TMR0 interrupt overflow bit. Must be cleared in software.
    
    </i></font>T0IF = <font color="#FF0000"><b>0           </b></font><font color="#000080"><i>' Cleared.
    </i></font>T0IE = <font color="#FF0000"><b>1           </b></font><font color="#000080"><i>' Enable TMR0 interrupt.
    </i><b>ON INTERRUPT GOTO </b></font>TMR0_Int
    
    Begin: 
        <font color="#000080"><b>IF </b></font>TimeAdder = <font color="#FF0000"><b>10 </b></font><font color="#000080"><b>THEN </b><i>' We have 10mS cycle.
           </i></font>TimeAdder = <font color="#FF0000"><b>0       </b></font><font color="#000080"><i>' Clear time adder.
           'Do something here.
           '. 
           '..
           '...
        </i><b>ENDIF
        
        
        GOTO </b></font>Begin
    
    
    
    <font color="#000080"><b>DISABLE
    </b></font>TMR0_Int:       <font color="#000080"><i>'This routine is called every 1.03mS. Act Fast here.
        </i></font>TimeAdder = TimeAdder + <font color="#FF0000"><b>1
        </b></font>T0IF = <font color="#FF0000"><b>0  </b></font><font color="#000080"><i>' Clear interrupt flag bit.
        </i><b>RESUME                   
    ENABLE     
        
        
    </b></font>
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer
    Minor correction to DT's code above:
    TRM0IF VAR INTCON.2 should be TMR0IF VAR INTCON.2
    WooHoo!, Somebody's paying attention. I love it!
    Dang dyslexia.

    Thanks Sayzer!
    <br>
    DT

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    WooHoo!, Somebody's paying attention. I love it!
    Dang dyslexia.

    Thanks Sayzer!
    <br>
    Attention is in my heart,
    Reading and posting is never hard,
    Let be friends, don't post assault,
    Share the knowledge, you won't lose a byte.


    P.S. - I am in finals going toward award.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    P.S. - I am in finals going toward award.
    At poetry.com?
    That's great!

    May the judges "Let it be".
    <br>
    DT

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 16:48
  2. Serin to Serin2 ??
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 03:56
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. newbie Q - edge detection?
    By RMCRAVEN in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 9th October 2006, 08:20
  5. Newbie question:
    By Izone in forum mel PIC BASIC
    Replies: 2
    Last Post: - 26th February 2006, 16:24

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