Shop OBEX P1 Docs P2 Docs Learn Events
Reporting an Initialization bug in ADC.spin — Parallax Forums

Reporting an Initialization bug in ADC.spin

bmentinkbmentink Posts: 107
edited 2008-08-25 06:52 in Propeller 1
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

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,562
    edited 2008-08-25 05:22
    bmentink,

    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.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-25 05:41
    Beau, I dont understand your reasoning, my understanding of the code is that it outputs differences in phsa between 1 run and the next. The first time phsa starts at 0 (strictly -8 since there is 2 extra instructions executed) So if you initialize asm_old to the initial value of phsa (0 or -8) then the 1st time will also give the correct result.
  • Beau SchwabeBeau Schwabe Posts: 6,562
    edited 2008-08-25 06:41
    Timmoore,

    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 ?

    mov          asm_old,phsa          ' capture PHSA\
    sub          asm_old, #16          ' <--instead of 8 since now you have 2 more instructions
    

    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
  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-25 06:52
    That makes sense and is easier to understand why than just initializing asm_old to some value. My guess is that Chip wasn't expecting someone to use it in the way bmentink is using it, normally you would run it continously and this wouldn't be a problem.
Sign In or Register to comment.