Never seen this before!!


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: Never seen this before!!

    Quote Originally Posted by SteveB View Post
    Quote Originally Posted by Megahertz View Post
    Code:
     
    movlw   -97
    addwf   TMR0
    I have never come across any negative number getting loaded into a variable.
    Is this the same as Loading 159-> (256-97=159) to Timer0 ?
    It sure is.
    That's not exactly correct. Notice that the constant value is being added to the free running TMR0 register. In this case it seems the author is using Timer 0 to generate precise 100 cycle intervals. Of course this only works if you're not using the TMR0 prescaler since any write to TMR0 will also clear the prescaler. The -97 value accounts for one cycle for TMR0 overflow and the inherent two cycle delay you get after writing TMR0 before TMR0 starts counting again.

    Hope this information helps.

    Cheerful regards, Mike
    Last edited by Mike, K8LH; - 2nd July 2012 at 15:26.

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Never seen this before!!

    Good point. I was focused on the fact that the movlw had a negative value. Your explaination takes it to the next step as to why the value would be there in the first place. Nicely done!

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