Hi,
There are a couple of bad things happening in the line "adve = (((cal * (adval - c1)) / 10) + yuk)".
(adval - c1) * cal = -99960 (since cal will be 98), -99960 is way higher than PBP can handle in a wordsized variable. You then try to divide this number by 10, that will not work since PBP can't divide a negative number.
There are a few possible solutions to your problem. "adval-c1" will almost always be neagtive(assuming 10bit AD). Reverse the order to make it positive instead. The number will still be too large for PBP, decrease the accuracy by dividing cal by 2, later you will divide by 5 instead of 10 to keep it the same. Change you "formula" to ......
der = ((yuk - sifir)/(c1 - c0))
fer = ((yuk - sifir)//(c1 - c0))
ler = fer dig 2
cal = der*10 + ler
cal = cal / 2
adve = yuk - (cal*(c1-adval))/5
... this should give you correct results(assuming 10bit AD).
However, i suspect there might be a mistake even earlier aswell. The code......
der = ((yuk - sifir)/(c1 - c0))
fer = ((yuk - sifir)//(c1 - c0))
ler = fer dig 2
cal = der*10 + ler
.... may not do what you want it to do. I assume that you want to do "cal = 10 *((yuk - sifir)/(c1 - c0))". The code you've written will not do that. It will hit the correct number somtimes but not always. You could use DIV32 instead .....
dummy VAR WORD
var1 VAR WORD
var2 VAR WORD
dummy = 10
var1 = yuk - sifir
var2 = c1 - c0
dummy = var1 * dummy
cal = DIV32 var2
.... this will produce correct results.
There might be a simpler and more accurate way of doing what youre trying to do. It looks like you're trying to do some sort of "twopoint calibration". Tell me/us what you want to do more precice and i may be able to help you further.
/Ingvar




Bookmarks