Has anyone else encountered that the "long" type variables roll over well before they reach the max value of it?
I've been trying to implement simple calibration to certain values (temperature), but i need to show some decimals too, and when i multiply calibration values by 10 and adc by 10 and calculate the corrected values, the results are unexpected. Then i started to break down the calculation to see where it fails and why...
In simulation everything works like it should, but when on real HW, the numbers seem to roll over:
This is from real HW test on 16F18877 target:
Code: Select all
DEBUG: ADC0: 1023
DEBUG: ADC1: 293
KEY press= 0
DEBUG: VAL_TEMP before calculation: -39
DEBUG: ADC_OFFSET: 10230
DEBUG: CAL_RANGE: 10230
DEBUG: REF_RANGE: 1400
DEBUG: RANGE_OFFSET: 35152
DEBUG: UNCORRECTED VALUE: 3
DEBUG: CORRECTED VALUE: -397
DEBUG: VAL_TEMP AFTER CALC: -39
DEBUG: VAL_TEMP_PART AFTER CALC: 81
DEBUG: .temp string: ERR
DEBUG: ADC0: 1023
DEBUG: ADC1: 513
Code: Select all
DEBUG: VAL_TEMP before calculation: -39
DEBUG: ADC_OFFSET: 6570
DEBUG: CAL_RANGE: 10230
DEBUG: REF_RANGE: 1400
DEBUG: RANGE_OFFSET: 22960
DEBUG: UNCORRECTED VALUE: 2
DEBUG: CORRECTED VALUE: -398
DEBUG: VAL_TEMP AFTER CALC: -39
DEBUG: VAL_TEMP_PART AFTER CALC: 81