Reporting an Initialization bug in ADC.spin
bmentink
Posts: 107
Hi to Beau Schwabe,
There is a bug in the code. The variable asm_old does not have an initialization value before the loop, this results in a random value
being assigned at startup and because asm_old is used each time through the loop, the incorrect value persists.
The fix is to add: mov asm_old, #0 to the line following the "mov frqa,#1" line ...
Cheers,
Bernie
There is a bug in the code. The variable asm_old does not have an initialization value before the loop, this results in a random value
being assigned at startup and because asm_old is used each time through the loop, the incorrect value persists.
The fix is to add: mov asm_old, #0 to the line following the "mov frqa,#1" line ...
Cheers,
Bernie
Comments
It's not a bug.... Since the ADC value returned depends on successive reads (i.e. the difference or change between old and new), initializing that variable ahead of time wouldn't do you any good anyway. The first iteration will always produce an erroneous reading no matter what.
The existing line of code below does initialize 'asm_old' for the next successive read ...
mov asm_old,asm_new
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I understand the argument, but under the same notion, 'phsa' should also be initialized or referenced to 'asm_old'
Would something like this work right after the "mov frqa,#1" line ?
Chip actually wrote the code in an early example on the forum.· I·wrapped it up as an object exactly the way it was.
Other than saving some variable space, I'm sure that there is good reason·Chip did it the way that he did.
...that or just generally expecting that when you start anything up, there is an initial·"settling in" period.
I don't know for sure, but he way that the current code is, the error should not propagate.· Only the initial reading could be off.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 8/25/2008 6:53:00 AM GMT