Peter Nachtwey
Member
NewValue=NewValue-(NewValue>>3)+AnalogIn
This is not right. You are effectively mulitplying by -7.
NewValue=(NewValue>>3)-NewValue+AnalogIn
is correct but loses too much resolution. My way is better. You should at least add a rounding term
NewValue=((NewValue+4)>>3)-NewValue+AnalogIn
This will keep from adding a negative bias to the output because of the continual truncating.
It doesn't surprise me that your compiler would automatically find the the best way to multiply by 7. Many compilers for small micros will convert multiplies to inline shift and adds or shift and subtracts rather than call a general multiply routine. You must have one of the better one though.
This is not right. You are effectively mulitplying by -7.
NewValue=(NewValue>>3)-NewValue+AnalogIn
is correct but loses too much resolution. My way is better. You should at least add a rounding term
NewValue=((NewValue+4)>>3)-NewValue+AnalogIn
This will keep from adding a negative bias to the output because of the continual truncating.
It doesn't surprise me that your compiler would automatically find the the best way to multiply by 7. Many compilers for small micros will convert multiplies to inline shift and adds or shift and subtracts rather than call a general multiply routine. You must have one of the better one though.