Reading Timers


Closed Thread
Results 1 to 3 of 3

Thread: Reading Timers

  1. #1
    Join Date
    Aug 2007
    Posts
    67

    Wink Reading Timers

    I'm trying to get my head around what should be a pretty simple concept - using timers. I've been reading this forum for the better part of the last few days and still can't find anything that really spells it out.

    I've seen tons of other posts (several on the first page) asking timer questions - and the PBP manual is conspicously sparce when talking about them - I think the community could use a good tutorial that really spells it out in simple terms so there's a clear understanding. Timers seem to require a certain amount of tribal knowledge - TONS written using them, but very little really 'about' them.

    Without writing 8 pages of details about the big picture, here are the very specific things I'm trying to do (the only part I don't understand, the rest of my application is super straight forward).

    1. All timer resolutions need to be as short as possible - the 2uS I see published running at 20mhz should be just right, but no slower. The actual PIC doesn't matter right now as I'm still prototyping - once I understand this question I'lll be able to select the right part for my use.

    2. The ONLY thing this PIC will do in this part of the program is watch for an input and wait for a clock to run out - that's it.

    3. I want to basically do the following paraphrased code:

    START TIMER to run out / overflow in exactly 3000 microseconds
    Loop:
    Check pin 1 for input (if input: Gosub - ActionHandler)
    Check if the clock has run out (check timer if timer over flow is > 0)
    Loop

    This way when the pin I'm watching changes - I jump imediately (within a couple of clock cycles I'd expect) to my ActionHandler

    I would really like the ActionHandler to be able to "read" the timer's current position and stop it (or reset it as I no longer need it) and ideally be able to tailor it's response to the period of time within the above timing period the event occured.

    So ideally I end up with:

    - The clock runs for 3ms without input, catches the "time out" at the end, does something else, then repeats

    - Or, during that 3ms, an input is almost immediatley acted upon and I'm also able to see how far into the duration of the 3ms the event occured.


    My confusion:

    I don't know how to just "read the timer". Or "start the timer" or "stop the timer" or "reset the timer".

    I found this post which was somewhat helpful:
    http://www.picbasic.co.uk/forum/showthread.php?t=4092

    I've been digging in the PBP manual, reading the greek of the Pic data sheet and just getting frustrated looking for the answer.

    I guess I'm looking for an actual code example of:

    Start Timer
    Stop Timer
    Reset Timer
    Read Timver Value

    ... and if I could do that without writing any assembly, that would be great. I'd like to learn that stuff eventually, but I'm running out of time on this project and I know it would work fine if I could just do the above, and unfortuantely I just don't have the time to learn ASM right now.


    And to get the resolution I'm looking for, it looks like I have to read a 16 bit value, which Paul Borgmieier was very helpful in the above post.

    And also, as long as I'm confused and asking silly questions:

    What does "CCP" mean? The above post mentions it, I see it all over the forum and the Pic data sheet only quotes it once as "CCP1" in the section with the rest of the greek talking about the timer - so it's got something to do with timers but I just can't figure out what. I can't find it defined anywhere.

    That's the real frustration here - I see so many terms and I'm trying to see them all used enough to figure out what they really mean and how to use them for my own purpose without asking questions like this. :-p



    Thanks huge! Sorry to be such a downer with such an attitude - I planned to get all my code blocked up this weekend and I spent the last several days just trying to figure out how timers work. Arugh. @#$#@$#.
    Last edited by kevj; - 27th August 2007 at 01:59.

  2. #2
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    I finally stumbled onto some understanding this evening when I finally began to understand what the registers were all about. I found this great set of tuts here:

    http://www.hobbyprojects.com/pic_tut...tutorial1.html

    Pretty well step by step explanation of the PIC and simple ASM - that whole ASM thing is actually pretty easy. I can see it getting mind boggling to accomplish anything worthwhile, but one step at a time - it makes sense.

    Anyway, after reading the above, the data sheet for the PIC makes a lot more sense. I'm sure I'll still have Q's on all this later this week, but now I finally see how to start and stop the timers.

    I'm still not sure on the whole multiple bytes for the 16 bit timer, how to read each and act on them. Any info apprecaited otherwise I'll just keep trying to figure it out on my own.


    Thanks!!

  3. #3
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Woah - just found this thread:

    http://www.picbasic.co.uk/forum/show...66&postcount=3

    From Joe S. - he gives credit elsewhere, but I think I get it now. It's almost 1am on Monday morning and after beating my head on this all weekend, I think I finally get it. lol.


Similar Threads

  1. Reading temperature using multi DS18B20
    By KVLV in forum Code Examples
    Replies: 16
    Last Post: - 3rd November 2017, 19:48
  2. DS18B20 error reading
    By Gaetano in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th August 2007, 16:21
  3. Pot reading jumping like crazy!!!
    By champion in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 20th November 2006, 21:24
  4. Reading Timer1 value
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 19th June 2006, 16:21
  5. Availability of PIC timers from PBP
    By coda64 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th February 2006, 07:18

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