Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20601

BASCOM-AVR : pulse length capture : REPLY

$
0
0
[quote:241657e6d3="philm"]The value of the code can be decided by the OP.[/quote:241657e6d3] Not really, my code for example wouldn't work with a counter-variable other than a word. [quote:241657e6d3]It's pretty obvious that bits are missing, and it won't compile.[/quote:241657e6d3] Sure noticed that, but you haven't wrote the snippets from memory I guess, instead you did a copy/paste. It would surprise me, that in this order commas made it into the code. [code:1:241657e6d3]There can never be a "race condition", if I understand what you mean by "race condition". It either measures a capture or overflow, never both.[/code:1:241657e6d3] As you simply limit the result at overflow, a race-condition is rather unlikely, I did explain that later. [quote:241657e6d3]Bascon doesn't throw up a syntax error, and yes, it does what I expect.[/quote:241657e6d3] It may happen, that the compiler ignores wrong syntax, it also be that the complete order after a wrong syntax is ignored, in this case the NOSAVE option. [quote:241657e6d3]And I don't know why you do subtraction from the old tcnt value to get the current real capture, when zeroing tcnt and reading the values directly would do the same thing.[/quote:241657e6d3] Because that's the correct way. The benefit of ICP is: capturing the timer value is done exclusively by hardware, if you zero the timer in software, the ISR, you loose that advantage. Let's say ICP is triggered first at timer-value 500 and next time at 1000, let's also assume the first trigger is delayed by another competing ISR by 100 cycles. Then zeroing of the timer happens actually not at timer-value 500, instead at 600 + say 15 cycles needed for executing the ICP-interrupt till the timer is actually zeroed. That means your result is wrong, as it will show 385, while my version will show 500. However, if you don't have competing interrupts, you won't experience that issue. Nevertheless it's the wrong use of the ICP-unit. Letting the timer run all the time and reading/subtracting only the ICP-register avoids that.

Viewing all articles
Browse latest Browse all 20601

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>