Shop OBEX P1 Docs P2 Docs Learn Events
Counters Timeing, Cnt, Cnta, and Float a noob question. — Parallax Forums

Counters Timeing, Cnt, Cnta, and Float a noob question.

TJHJTJHJ Posts: 243
edited 2008-03-17 17:43 in Propeller 1
Thanks again for the help.

So can someone tell me if I say this it is correct, I keep reading but im just confusing myself more.
By hooking up a external crystal, I am overwriting the internal RC oscillator, such that the system time, and all time keeping elements are now based off of this external crystal. The Cnt, timer of the system is incrementing at the rate defined, and the main reason for this is to improve the accuracy of the chip.

How much accuracy if the above is correct? Are we talking errors in times of MS, NS using the system clock?

How long would it take with a 5mhz external crystal, at 4x, so system speed is 80mhz, for the internal clock to roll over?
Minutes? an hour? a day?

So in relation to this, Is there a better description of the modes for Cnta? What mode would I use if I just want it to increment with the system clock? I think I want to do this to prevent a time keeping error from the cnt timer rolling over.

So that I can then use a time code that looks like this

Repeat
Feqa := 0
Wait for what ever.
Time := Frqa

if I use
Time1 := Cnt
Wait for something
Time2 := Cnt
Time := Time2 -Time1
eventually the clock will roll over giving me a large incorrect result. such that time1 is a very large number and time 2 is very small.


And the last dumb question is, if I use a float constant does it pre round it when used in muilpication or division?

Con
Float Number .909

Pub Main
Some work to get var number2
Number 2 = 1000



Timedelay := Number * Number 2

Do I get 909 in timedelay or 1000?

do I get the same results using this?

Timedelay := .909 * timedelay


Thank you for your time and your help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-17 15:51
    1) With a 5MHz crystal, you get a 20MHz system clock with PLL = 4x and an 80MHz system clock with PLL = 16x.

    2) With an 80MHz system clock, it takes around 54? seconds for CNT to roll over.

    3) Read AN001 (application note) on the system counters for a description of the modes and examples of how some are used. You can download this from the downloads page off the main Propeller page.

    4) If you always compare like (final time - initial time) > elapsed time, then you won't have any problem with roll over up to about 27 seconds of elapsed time because the subtraction will also roll over at 32 bits. Try it on paper.

    5) Spin only supports floating point arithmetic in constants and constant expressions. You have to use explicit calls to a floating point library to do floating point arithmetic using variables. I'm not sure whether you will get an error message if you try to use a floating point constant with an integer arithmetic operator or if the compiler will just take the 32 bit representation of the floating point number and treat it as a 32 bit integer for the operation and give you an unexpected result. I suspect it's the latter because there are legitimate reasons to process floating point values with integer operators using the internal representation of the floating point.
  • TJHJTJHJ Posts: 243
    edited 2008-03-17 17:10
    Thanks I love how I miss the obvious examples.

    Ill have to take your word for it, on the 27 seconds. I cant even think how to write a 32 bit number, I guess something with 32 digits in it. But thanks for your help as always
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-17 17:17
    A 32 bit counter rolls over at 4,294,967,296. This is 2 to the 32nd power. I computed it by taking 65,536 * 65,536. I happen to know 65,536 is 2 to the 16th because it's where a 16 bit counter rolls over.
  • TJHJTJHJ Posts: 243
    edited 2008-03-17 17:24
    Ok just to confirm I am thinking about this correctly, If ctra is operating in %11010 mode logic APIN=1 once APIN is high, it will add values to FRQA acting as a pulse measurement. When the pin goes low, does FRQA Reset to zero? Or does it hold its old value? and then contiune to add from there?

    Or Am I reading this whole thing wrong and it will simply add 1 each time Apin goes high to FRQA acting as a counter. If this is true then I should be using mode %01000 logic APIN=1. Is there any really any difference between these modes?

    Thanks again, Sorry Im so slow at this.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-17 17:29
    I believe that functionally modes %01000 and %11010 are equivalent. They add FRQA to PHSA on every clock cycle when pin A is 1.
    None of the modes clear either FRQA or PHSA.

    Post Edited (Mike Green) : 3/17/2008 5:36:05 PM GMT
  • TJHJTJHJ Posts: 243
    edited 2008-03-17 17:43
    Ok im getting there.

    So just to confirm, If In mode
    ctra := %01000_000
    Frqa := 1
    Dira[noparse][[/noparse]0]~ ' apin to input.

    The result in PHSA would be number of clock cycles Apin has been high, to then get time from this.

    (80_000_000)/ (PHSA / 4) = Time passes.
    Per example when PHSA = 320,000,000
    1 second would have passed, Since it added each clock cycle and 4 cycles occur per oscillation,

    Maybe....
Sign In or Register to comment.