I am running PIC18F46J50 at Fosc = 20MHz. I have configured ADCON0, ANCON0, and ANCON1 registers.
I want to know what should be the value od ADCON1 register.
The bit 7 and 6 will have values 1 and 0, but I want to know what should be the values of bit 5 - bit 0.
That is ACQT2-ACQT0 and ADCS2-ADCS0. It is not mentioned in the datasheet the min TAD required and the time for 1 TAD.
min TAD is 0.7us and the datasheet says that the TAD should be as less as possible but greater that the minimum TAD. So I chose Fosc = 20 MHZ, Tosc = .05us
min TAD = 0.7us, 16 * Tosc = 0.8us which is greater than the minimum TAD required. So the value of ADCS2-ADCS0 = 010
Should I use 25us for TAD as mentioned in page 523?
FOSC/16 should be okay, since TAD > minimum value of 0.7us. However, it's very close to the minimum (very small margin). So, just use FOSC/32. A slower conversion won't decrease your accuracy. If anything, it will increase accuracy. So, for ADCS<2:0>, use 010 or maybe even 110 (FOSC/64).
Can you upload your project file, hex file and simulation so that I can take a look?
OK. I used ADC_Get_Sample(0); but getting the same wrong values.
Check with this file. I have included mcHID.dll. put it in windows\system32 folder and then rum the simulation. maybe usb hid is hanging the simulation.
Connected in series from LM35 ground to circuit ground. Why did you do this?
I'm sure the error is in the constant.
Remove D1 and D2 and connect LM35 ground to circuit ground.
For 150'C, you'll get 1.5V output. ADC reference = 1.875V
So, that'll give ADC reading of 819.2
So, constant is 150/819.2 = 0.1831054688.....
The way the circuit is arranged, I don't think a linear relationship is maintained.
Actually, I want to measure temp from -55 to + 150 degree centigrade. That is why I have used the diodes. I will read adc(0) and adc(1) and take the difference of the 2 values.
OK. I did as you said, but after removing the diodes, the values don't vary in real time.
So, you should do that in this code as well. Because of the 2 diodes, you don't have a proportional relationship as in (y=mx), but a linear relationship as in (y=mx+c). That's why for other temperatures the formula you used doesn't work.
RTC doesn't run and adc value doesn't change on changing the LM35 temp value.
I have attached the video. You are right, by removing the diodes i am getting the right values, but how to remove hanging?
- - - Updated - - -
OK. I got it working. The USB HID enable code was commented out. and I was trying to write to usb. OK. The problem got solved. Thanks once agian Tahmid. You found the correct problem. after removing the diodes it is giving the right values.