Performing a loop every 10ms


Closed Thread
Results 1 to 40 of 41

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    When I was growing up and Mom said that she was getting a SWITCH...She was not referring to an electrical component
    Ya, mine too...it think it was an OKMU switch...One kid, multiple uses...for some reason, I begin to think that I was always the one that turned that switch on........and it seems like it never turned off!

  2. #2
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Thumbs down

    There you go people, my point has been backed up by these last few replies. I notice there are alot of assumptions being made.
    E.g. 1 From skimask: "You wanted it handed to you on a platter so you could modify it and call it your own and impress your teachers or your buddies...whatever..."

    Now that is some assumption. You jumped to that conclusion skimask, I know some other people on this form may do that, but all I needed was a somewhere to start. Go and look at my first post. See how innocent that looks? I guess the assumptions started right there. (:

    E.g. 2 From mackrackit: "Whatever happened to people that want to learn.. Seems like all anyone wants these days is their problems solved for them with as little effort as possible on their part."
    This person made the same assumption. What made you think I just wanted the answer straight up? It would have helped if someone could step me through how to set up Timer0.

    Acetronics thought this was a cut and paste party. All I needed was some guidance.

    Hmm I wonder what's going to be said next?
    Last edited by wasssup1990; - 15th February 2008 at 03:20.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by wasssup1990 View Post
    Hmm I wonder what's going to be said next?
    Allow me.... ('cause most will )
    Post #1 = +
    Post #2 = +
    and so on...
    Post #15 = +
    Post #16 = +
    Post #17 = NEGATIVE - and it'll all downhill from there...thanks to...anyone...anyone...yep, you guessed it...

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


    Did you find this post helpful? Yes | No

    Default

    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
    
    OPTION_REG = %11010111   ; Assign Prescaler to TMR0, 1:256, internal clock
    TMR0 = TimerReload       ; Load timer for first delay
    TMR0IF = 0               ; Clear the interrupt flag
    ReadingTaken = 0         ; indicate reading hasn't been taken yet
    
    TMR0IE = 1               ; Enable TMR0 interrupt
    ON INTERRUPT GOTO TakeReading
    
    Main:
        If ReadingTaken then ; Wait for reading to be taken
            ReadingTaken = 0 ; Indicate the reading has been handled
    
            ; -- Reading has been taken, do something with it here --
        endif
    
    GOTO Main
    
    DISABLE
    TakeReading:
        TMR0 = TimerReload   ; reload timer for next period
        TMR0IF = 0           ; Clear the interrupt flag
    
       ; -- this is called every ~10.036ms -- (with 20mhz OSC)
       ;    Take your reading
    
       ReadingTaken = 1      ; Tell main loop that a reading has been taken
    RESUME
    ENABLE
    HTH,
    DT

  5. #5
    Join Date
    Feb 2008
    Posts
    10


    Did you find this post helpful? Yes | No

    Thumbs up

    Thankyou Darrel
    Admin has come to the rescue.

    Thankyou for that usefull code. If I ever use any of it I will put credit to you in my source code and whoever else you think deserves credit for it.

    I hope I never run into trouble like this again on this forum. I'm just a electronics and programming hobbiest needing a little programming help. I didn't need any of that rubbish above.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    MHhhhhh,

    Thinking to it, Darrel is perfectly right ... ( as most of time ! )

    We are here for programming pics tricks ... and Everything else is just "optionnal". May be this thought could avoid further fighting parties ...

    Here are My two cents !

    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 " !!!
    *****************************************

  7. #7
    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

  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 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

  9. #9
    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

  10. #10
    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