Originally Posted by RFsolution
You broke my heart !
--------------------------
Originally Posted by RFsolution
You broke my heart !
--------------------------
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Hi
This is what I have but dont see any light in "my" tunnel
OSCCON = $60
DEFINE OSC 4
DEFINE adc_bits 10
DEFINE adc_clock 3
DEFINE adc_sampleus 50
adcresult VAR WORD
dummy var word
adcon1=%100000010
maxvalue var word
minvalue var word
scale var word
result_64 var word
init:
maxvalue = 64000 'this is 359,8 degrees
minvalue = 2200 ' this is equal to 0 degrees
loop:
gosub readadc
Scale = MaxValue - MinValue
dummy = (AdcResult - MinValue) * 64
dummy = dummy * 360
Result_64 = DIV32 Scale
SerOut 6,6,["adc=",#adcresult," scale=",#scale," dummy=",#dummy," res64=",result_64,10,13]
goto loop
readADC:
ADCIN 0, adcresult
return
OK, a lot of code, but no hint as to what is going wrong!
When getting up a new project, try to cut it into as many small slices as possible, get first to work, then move on to the next slice.
Slice 1: getting out debug info. Method: just post dummy data.
Slice 2: Read A2D. Method: read it, then output as debug info
Slice 3: Convert to degrees. Method: as discussed
Originally Posted by RFsolution
You have 10bits of res. Thus you need the result as right justified. But you have adcon1=%100000010 one extra 0 is typed here. So the result becomes as left justified. Thus you get your results as 64000 and 2200.
Change it to adcon1=%10000010. So you now have correct right justified setting.
Then check the readings again.
-------------
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Hi,
I think that your maxvalue and minvalue should be the raw value from the adc ie. between 0 and 1023 and not the raw value times 64.
Otherwise this will not work:
You get a value between 0 and 1023 from the ADC. Then you subtract 2200 from that which will make it negative and you don't want that.Code:dummy = (AdcResult - MinValue) * 64
Try setting the max and min value to the raw reading from the ADC.
/Henrik Olsson
Hi sayzer and henrik thanks for your help
Well,
ADCON was wrong so I was getting more than a 10bits ADC result
so ofcouse my minvalue and maxvalue that i noticed was wrong
so all mathemacics also resulting in a non res_64 variable
I'm now getting a value of res_64 but and after dividing it by 64 I have
a nice 360 deg readout,
Can anyone help with the bitshifting and additional dividing ? to have a
.1 deg variable and readout ?
Thanks
With a 10 bit A2D you have a max reading of 1023 counts, which represents 360 degrees. Therefor, each count is 1023/360=2.84... degrees.
You don't have .1 degree resolution here, you have 3 degree resolution. That .1 degree is not a true number.
Hi ErnieM,
I do not think your formula is ok. Your result is not in "degree" by the way. 2.84 is the step for per degree.
Lets leave 0.1 degree sensitivity issue to our teacher, Alain!
I love to learn.
----------------------
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Bookmarks