Oops, missed that one. I personally would use this:
d = 100
dummy = adc_in * d
adc_value = DIV32 256
Substitute 341 for the 256 is using the 0-300 lbs scale. The adc_value variable will contain the lbs.
Oops, missed that one. I personally would use this:
d = 100
dummy = adc_in * d
adc_value = DIV32 256
Substitute 341 for the 256 is using the 0-300 lbs scale. The adc_value variable will contain the lbs.
Last edited by CocaColaKid; - 21st September 2005 at 13:27.
thanks a lot guys
but more probelms occured...
after testing the program and testing the voltage received using a multimeter
the actually voltage range is approx 0.44 volts +/- .009 volts and the max load we were able to obtain is approx 4.99 volts +/- .009 volts.
can you please explain to me how the equations so i can understand the analog to digital conversion + plus can if possible, derive a new equation to fix this problem.
here's the source code:
Define LOADER_USED 1
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 0
Define LCD_EREG PORTB
Define LCD_EBIT 1
DEFINE OSC 4 ' Set Xtal Frequency
DEFINE ADC_BITS 10 ' Set resolution of conversion
DEFINE ADC_CLOCK 8 ' Set clock source (x/FOSC or FRC)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time (in uS)
'---------------------------------------------------------------
' INTCON.7 = 0 ' Enable PORTB pullups
' ADCON1 = 7 ' Make PORTA and PORTE digital
Low PORTB.2 ' LCD R/W low (write)
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
'---------------------------------------------------------------
d VAR word
dummy var word
adc_in var word
W VAR WORD
adc_value var word
ADFM var ADCON1.7 ' ADC result format select bit
PCFG3 var ADCON1.3 ' ADC port configuration bit
PCFG2 var ADCON1.2 ' ADC port configuration bit
PCFG1 var ADCON1.1 ' ADC port configuration bit
PCFG0 var ADCON1.0 ' ADC port configuration bit
PCFG0 = 0 ' Configure AN0 as analogue input, others digital
PCFG1 = 1
PCFG2 = 1
PCFG3 = 1
ADFM = 1 ' Right justified result in ADRESL and ADRESH
loop:
adcin 0,adc_in ' Place the conversion of channel0 into adc_in
d = 100
dummy = adc_in * d
adc_value = DIV32 256
W = adc_value
pause 500
Lcdout $FE, 1
Lcdout $FE, $80, #W," lbs"
pause 500
goto loop
anymore help would be appreciated
thanks a lot
Ok, here's one way to do it.
The general formula would be ....
result = (adc_in - CalLO)*Range/(CalHI-CalLO)
.... where
adc_in = input from ADconverter
Range = Maximum load
CalLO = adc_in when load is zero
CalHI = adc_in when load is "Range"
You could calculate and "hardcode" the last two, but the best solution would be to make a small calibrationroutine that gathers the readings. I'll use 0.44v as zero load and 4.99v at maximum load(300lbs).
If you want rounding you could do .....Code:Range CON 300 adc_in VAR WORD CalLO VAR WORD CalHI VAR WORD div_val VAR WORD result VAR WORD dummy VAR WORD CalLO = 90 ' calculated calibrationvalue (0.44/5*1024) CalHI = 1022 ' calculated calibrationvalue (4.99/5*1024) div_val = CalHI - CalLO dummy = (adc_in - CalLO) * Range result = DIV32 div_val
/IngvarCode:Range CON 3000 adc_in VAR WORD CalLO VAR WORD CalHI VAR WORD div_val VAR WORD result VAR WORD dummy VAR WORD CalLO = 90 ' calculated calibrationvalue (0.44/5*1024) CalHI = 1022 ' calculated calibrationvalue (4.99/5*1024) div_val = CalHI - CalLO dummy = (adc_in - CalLO) * Range result = DIV32 div_val result = (result + 5) / 10 'rounded result
Thanks a lot Ingvar
You are the best
I'll try that code out
scale isn't accurate...
the code is logical and it makes sense, but the scale itself doesn't weight correctly
can it be that i have a faulty sensor?
is there a way to correct this?
Last edited by houa; - 27th September 2005 at 04:05.
Bookmarks