frqa gets added to phsa?
m1nuteman
Posts: 6
At your suggestion, I've been slowly working my way through the PE Kit Labs. Pretty cool and lots of fun. Now I've started the 'Counter Modules + Circuit Applications' PE Kit Lab and I'm stumped.
On page 6 it says,· frqa := clkfrq/1_000_000 is used to count in uSecs. So, for an 80MHz clock this is 80, which is added to phsa at every clock tick (or every 12.5nSecs, 1/80MHz).
For example, if I want to measure a 5uSec pulse, this is 400 ticks. The phsa will have 32000. How does this help to count in uSecs?... shouldn't the phsa have just 5.
Also can anyone please expand on 'Where the 624 comes from?' ??
·
On page 6 it says,· frqa := clkfrq/1_000_000 is used to count in uSecs. So, for an 80MHz clock this is 80, which is added to phsa at every clock tick (or every 12.5nSecs, 1/80MHz).
For example, if I want to measure a 5uSec pulse, this is 400 ticks. The phsa will have 32000. How does this help to count in uSecs?... shouldn't the phsa have just 5.
Also can anyone please expand on 'Where the 624 comes from?' ??
·
Comments
624 is explained well on page 6. It is the time the SPIN code code needs. It you have the impression, this is A LOT you are quite right
What do you mean by "measure 5 mys"?
FRQA is added to PHSA every clock tick, and there are certain actions performed on bit 31 or on overflow depending on the timer/counter mode you have selected. So what is your question??
The AN001 explains everything extremely well...
Post Edited (deSilva) : 8/9/2007 8:12:22 PM GMT
I agree with deSilva...I don't understand your question.
I've read through the lab... it is amazing. But I find the material far easier to understand that to retain. I'm planning an immersion experience to try to get a better gestalt going in my brain.
Could you re-phrase your question a little?
Rich
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
And like many others I am anxiously waiting for AN002
Post Edited (deSilva) : 8/9/2007 8:09:23 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Setting frqa to clkfreq/1_000_000 isn't for counting in microseconds, it's for prescaling the measurement to useful units for some kind of output that needs microsecond units.·
When frqa is set to 1, the value 1 gets added to the phsa register for every clock tick that it detects a high signal.· By setting frqa to 80, which is the result of clkfreq/1_000_000 when the propeller is running at 80 MHz, the value 80 will get added to the phsa register for every clock tick that the decay measurement is high.
In your example, the Propeller chip is running at 80 MHz and the decay measurement turns out to be 400.· With clkfrq/1_000_000 = 80 in the freqa register, the phsa register will store 32000 instead of the 400 it would store if phsa was 1.·
How does this help?· Let's say your application is requried to wait 1 us for every decay measurement clock tick.· By setting·frqa to clkfreq/1_000_000 = 80, you can skip a multiplication step and go straight to:
···· waitcnt(phsa + cnt)
Now if phsa were not prescaled (frqa would be 1 instead of 80), the value 400 would get stored in phsa, and you would instead have to use a command to scale for the delay before you get to the waitcnt command:
···· delayTicks := phsa * (clkfreq/1_000_000)
···· waitcnt(delayTicks + cnt)
"To start the decay measurement, clear the PHS register, and then set the I/O pin that’s charging the
capacitor to input:
···· phsa~
···· dira[noparse][[/noparse]17]~
...
To complete the measurement, copy the phsa register to another variable and subtract 624 from it to
account for the number of clock ticks between phsa~ and dira[noparse][[/noparse]17]~."
Spin is a high level interpreted language.· The interpreter takes 624 clock ticks between the time it starts counting ticks and the time it sets dira[noparse][[/noparse]17] to input, which is what starts the decay.· There's no decay happening during those 624 clock ticks because before that, the I/O pin is still keeping the capacitor fully charged since it's sending a high signal.
Now, if you you are prescaling, you'll also have to subtract 624 prescaled units instead of subtracting 624.
Hope this helps.
Andy
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
Good news, I understand now the 624 number....Great!
Andy, on the prescaling issue... So, for 1uS delay, instead of using:
····················································· delayTicks := phsa * (clkfreq/1_000_000)
····················································· waitcnt(delayTicks + cnt)
············································
It's better to prescale and use:
····················································· waitcnt(phsa + cnt)
But, if during the time the pin is high, phsa is constantly incrementing at every clock tick either 1,2,3,4,5.. or 80,160,240,320.. the 1uSec delay will only be achieved if these previous commands read phsa exacty after the first clock tick ??
I'm sure I'm missing something here...·are there any code examples using this?
rgds
Paul
I think what you may be missing is the intent of the statement, "Let's say your application is requried to wait 1 us for every decay measurement clock tick." There is nothing that says that you have to cause phsa to increment by 80. That is just a convenient value to use in this particular application where the next thing that happens is a delay in microseconds related to the prior measurement. There are 80 clock ticks in a microsecond, so by counting in units of 80 you end up with exactly the number you need to initiate the delay. It just saves that extra step in this application. In some cases you might want to count in clock ticks directly. Or maybe you want an answer to provide a waitcnt delay in milliseconds, in which case the increment could be by 80_000 instead of 80. Or suppose the RCTIME measurement came from, a photodiode current dependent on light level. You could come up with an increment number that would result in a numerical value directly in lux or footcandles, say.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks everyone.
rgds
Paul
Thank you ! i also was puzzled with this 624 number. The book give information how it is calculated but not on the rational about it.
By the way, the PEKIT book is a great starting book. It should be recomended to people that bought the activity board. Even if it's a bit old, or not quite close to the activity board, all spin information it contains are really usefull.