This bug took me a while to figure out. The reference manual specifies a specific sequence of reading off ADC registers to get the right results.
I tried writing my code this way hoping that the result would be evaluate from left to right.
C language operator precedence specifies the following evaluation ordering. If the compiler fails to follow that, then it is non-compliant.
Cosmic C ignores the C precedence and produces the wrong order of reading the registers. I swapped the ordering and it still compiles to the same incorrect sequence of assembly code.
The only way to force the correct sequence is to split up the assignment into 2 statements. Thankfully the compiler isn't smart enough to track assignments across statements.
This produces the right code sequence.
Bug #2
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.