Why use a counter and not CNT?
Akkarin
Posts: 43
Hi,
I'm curious what the advantages of using a dedicated counter are instead of using the CNT (register,variable?) for example to measure pulsewidth? I mean, either way you would use waitpeq and/or waitpne to trigger start and stop of measurement, right? If you account for the overhead as it says in the SPIN help (width := -cnt, SOME CODE,..., width += cnt - 544, where 544 was determined before) the measurements should be quite the same as with a counter and the handling is much easier.
Please don't say now: because it's more accurate. If it is more accurate, please explain why. Same with speed of execution or something like that.
Thank you.
I'd really like to understand this. It's not that I don't believe that using the counter is sometimes (or always) better.
- Akkarin
I'm curious what the advantages of using a dedicated counter are instead of using the CNT (register,variable?) for example to measure pulsewidth? I mean, either way you would use waitpeq and/or waitpne to trigger start and stop of measurement, right? If you account for the overhead as it says in the SPIN help (width := -cnt, SOME CODE,..., width += cnt - 544, where 544 was determined before) the measurements should be quite the same as with a counter and the handling is much easier.
Please don't say now: because it's more accurate. If it is more accurate, please explain why. Same with speed of execution or something like that.
Thank you.
I'd really like to understand this. It's not that I don't believe that using the counter is sometimes (or always) better.
- Akkarin
Comments
Now let's do the same with just waitpxx and manual cnt sampling. No matter how you do it, the SPIN interpreter reads the insn to sample cnt (hub access), gets the value from the cnt register and then does further processing. This value is therefore always aligned to the hub window (16n system cycles) which effectively lowers your accuracy.
Similar issues apply between waitpxx at PASM level exiting and the SPIN interpreter getting the next insn.
Edit: That being said, doing the waitpxx/cnt sampling in PASM will give you equivalent accuracy to the counter approach and may well be easier as you can do it on the fly without sacrificing a counter.
thank you. I think I get the point.
I knew I should have asked this before I write my routines in SPIN using CNT
Now I have to rewrite the whole thing And for that I have to go deeper into PASM programming since I never used it before.
- Akkarin
I'm currently reading Application Note AN001 to make myself familiar with the counter setup.