Counters Timeing, Cnt, Cnta, and Float a noob question.
TJHJ
Posts: 243
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.
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
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.
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
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.
None of the modes clear either FRQA or PHSA.
Post Edited (Mike Green) : 3/17/2008 5:36:05 PM GMT
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....