Shop OBEX P1 Docs P2 Docs Learn Events
Alternate method of creating a timer?? — Parallax Forums

Alternate method of creating a timer??

James LongJames Long Posts: 1,181
edited 2007-04-09 20:43 in Propeller 1
Ok....so I know I could use the waitcnt command to create a timer.

Is there an alternate method that I don't have to pause a cog to get a accurate time with.

I'm looking for seconds.....

I really don't want to pause a whole cog for time retrieval.

anyone with any ideas??

Could I use a CNTR to get a time result??

Thanks for any suggestions,

James L

Comments

  • T ChapT Chap Posts: 4,223
    edited 2007-04-09 06:38
    The CTR is great for that. Ther are some examples in the AN001 notes.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-09 06:41
    If you have a free pin, you can use two counters together. The first would output a high pulse each second, the other counter would count each time the first counter went high.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • James LongJames Long Posts: 1,181
    edited 2007-04-09 14:04
    Paul,

    Must I use a pin to use the CTR's?

    If I must i can....not a problem.....

    Now to figure out how to configure them.

    James L
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-04-09 17:28
    Yes, because you need a means of communication between the two, the first would be set up in duty mode of 1/clkfreq, the second would be in LOGIC A mode where it's input is the output of the duty cycle.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • cgraceycgracey Posts: 14,133
    edited 2007-04-09 18:01
    James Long said...


    Is there an alternate method that I don't have to pause a cog to get a accurate time with.

    I'm looking for seconds.....

    I really don't want to pause a whole cog for time retrieval.
    No problem. Let's say you have a Spin or assembly software loop. You just have to check to see how many increments have occurred in CNT. You'll need to get an initial CNT value and then maintain an absolute tracking. It could look something like this:


    c·:= 80_000_000··· 'how about once·a second at 80MHz?
    t := cnt·········· 'get the initial cnt value

    repeat············ 'here's·your loop

    · <normal code here>

    · if·cnt - t·=>·c· 'has the critical amount of time elapsed?
    ··· t += c······· 'yes, update target

    ··· <timer code here>

    This will be a little jittery, but will have no cumulative error. So, you could even use it for timekeeping.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.

    Post Edited (Chip Gracey (Parallax)) : 4/9/2007 8:44:04 PM GMT
  • James LongJames Long Posts: 1,181
    edited 2007-04-09 18:40
    Chip,

    Wouldn't the last line actually read:

    t += c

    Think the t1 was a typo.

    But I think that would work....without using the ctr command........

    Thanks......

    James L

    Edit: I had something similar.......but I think I was doing something weird causing it not to ever pass the if statement.

    Post Edited (James Long) : 4/9/2007 7:16:33 PM GMT
  • cgraceycgracey Posts: 14,133
    edited 2007-04-09 20:43
    James Long said...


    Wouldn't the last line actually read:

    t += c

    Think the t1 was a typo.
    Woops! You're right. I just·fixed it. Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
Sign In or Register to comment.