lloydi12345
Member
I am building a temperature reading circuit and I am using a thermistor for temperature reading with the help of PIC18F4620. How can I use 4.096V as reference voltage? What are the guidelines? The reading pin is RA0/Analog0. I assigned TRISA to 0x0F to have inputs from RA0 to RA3. I also set ADCON1 to 0x3B.
Should TRISA's Vref+ and Vref- be set as input?
Should TRISA's Vref+ and Vref- be set as analog?
RA2 was connected to GND while RA3 was connected to 4.096 voltage. The precision voltage was generated through MCP1541.
Here is a snippet of my code:
R27 is currently connected to 4.096V. With these current settings, the temperature reading is inaccurate. When I connect RA3 to 5V the reading doesn't change but when I connect R27 to 5V the reading goes right. It looks like Vref+ is still using the internal Vdd as its reference. What else did I miss?
lloyd
Should TRISA's Vref+ and Vref- be set as input?
Should TRISA's Vref+ and Vref- be set as analog?
RA2 was connected to GND while RA3 was connected to 4.096 voltage. The precision voltage was generated through MCP1541.
Here is a snippet of my code:
Code:
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
LATC = 0x00;
LATE = 0x00;
PORTA = 0x00;
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
TRISA = 0x0F; //default-0x01 make port0 as input for analog reading, make pin ra2 and ra3 inputs also
TRISB = 0x0F; //make port0-3 as input for button pressing
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
//Analog settings
ADCON0 = 0x00; //choose analog0
ADCON1 = 0x3B;
//Details:
//Connected Vref+(AN2/Pin5) to 4.096V and Vref-(AN3/Pin4) to GND
//RA2 & RA3 is analog and rest are digital, changed vref- and vref+
ADCON2 = 0xA9; //12 TAD Fosc/8
// configure Timer1
T1CONbits.RD16 = 1; // 16-bit read/write
T1CONbits.T1CKPS0 = 1; // 1:8 prescale
T1CONbits.T1CKPS1 = 1;
T1CONbits.T1OSCEN = 0; // not using external osc, so disable driver
T1CONbits.TMR1CS = 0; // internal clock
TMR1H = 0xDD;
TMR1L = 0xAA;
// enable Timer1
T1CONbits.TMR1ON = 1; // turn on timer1
// other Timer1 settings
RCONbits.IPEN = 1; // IPEN = 1
IPR1bits.TMR1IP = 1; // Timer1 high priority int
INTCON2bits.TMR0IP = 1; // Timer0 high priority int
PIE1bits.TMR1IE = 1; // Enable timer1
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
// configure A/D convertor
OpenADC(ADC_FOSC_64 & ADC_RIGHT_JUST
& ADC_12_TAD, ADC_CH0 & ADC_INT_OFF
& ADC_REF_VDD_VSS, ADC_1ANA);
Code:
void get_temperature(void){
temp_holder = 0;//variable declaration for temperature
for (convert_var=0;convert_var<3;convert_var++){
ConvertADC(); // Start conversion
while(BusyADC()); // Wait for completion
adc_result = ReadADC(); // Read result
//this is the formula based on Steinharts-harts equation
res = 3300.0 / (1024.0 / adc_result - 1.0);
resistance = log(res);
tempk = (1.0 / (Ra + (Rb * resistance) + (Rc * (pow(resistance,3.0)))));
tempf = (tempk * 1.8) - 459.67; //1.8 = 9.0/5.0
temp_holder = temp_holder + tempf;
}
temp1 = temp_holder / 3.0; // original = 3.0
temp3 = (temp1 + temp3)/2.0;
if (temp3 < 75.0){
temp3 = 75.0;
}
//in case of intense temperature fluctuations
//include this line of code below
tempB = (tempC + tempB)/2.0;
tempC = (tempC + tempB + temp3) / 3.0;
temp_holder = tempB;
}
R27 is currently connected to 4.096V. With these current settings, the temperature reading is inaccurate. When I connect RA3 to 5V the reading doesn't change but when I connect R27 to 5V the reading goes right. It looks like Vref+ is still using the internal Vdd as its reference. What else did I miss?
lloyd
Attachments
Last edited: