Shop OBEX P1 Docs P2 Docs Learn Events
frqa gets added to phsa? — Parallax Forums

frqa gets added to phsa?

m1nutemanm1nuteman Posts: 6
edited 2007-08-11 22:27 in Propeller 1
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?' ??
·

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-08-09 17:06
    I do not understand your question(s).
    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 smile.gif

    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
  • rjo_rjo_ Posts: 1,825
    edited 2007-08-09 17:21
    m1nuteman

    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
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-09 18:27
    Ok, I give up trying to figure from context. Can someone tell me what AN001 and/or variant AN0001 is?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-08-09 18:30
    Application note one availible on the downloads page of the Propeller.

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

    Parallax, Inc.
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-09 18:45
    ... here www.parallax.com/dl/appnt/prop/AN001-PropellerCountersv1.1.zip

    And like many others I am anxiously waiting for AN002 smile.gif

    Post Edited (deSilva) : 8/9/2007 8:09:23 PM GMT
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-08-09 19:02
    Ok, then I am not so dumb after all. Its printout is the first thing in my ringbinder.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-08-09 20:25
    AN002 is the video generators, but I haven't started on it. Full datasheet has priority.

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

    Parallax, Inc.
  • edited 2007-08-09 21:34
    Hello m1nuteman,
    m1nuteman said...
    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.
    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)
    m1nuteman said...
    Also can anyone please expand on 'Where the 624 comes from?' ??

    "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.
  • m1nutemanm1nuteman Posts: 6
    edited 2007-08-10 15:15
    I have to thank everyone for their replies. Thanks for spending the time on me with these two issues.

    Good news, I understand now the 624 number....Great!


    Andy, on the prescaling issue...
    Andy Lindsay said...


    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)
    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
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2007-08-10 16:30
    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
  • m1nutemanm1nuteman Posts: 6
    edited 2007-08-11 22:27
    Tracy Allen said...
    ...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.
    Ummmm! Got it now... so I can move on·to the next section. Great 'PE Kit Lab series'·by the way.
    Thanks everyone.

    rgds
    Paul

  • 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

    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.




Sign In or Register to comment.