littletransistor
New Member
Hey there,
Nice to be back! Ok, so I'm making my homebrew room thermometer, which is actually made from some transistors, a LM335Z temp. sensor (10mV per Kelvin), a 2 7-seg display and a PIC18F1320.
The thing is the multiplexing works pretty well, but not for the A/D conversion. The numbers on the display is very freaky, and not displaying anything that made sense. (It ended up displaying 09 instead of a room temperature, which is approx. 26 degrees celcius!)
Both of the A/D and Multiplexing are in interrupts by the way.
Here's the code. By the way, I have included a hefty conversion from Kelvin to Celcius. I have made it right-justified, and placed all the interrupt vectors properly. What could I have been missing?
Also, when I tested this LM335Z on a voltmeter, it's showing values around 2.80-2.88V when it is supposed to be warmer than that! I guess I should calibrate the sensor!
Nice to be back! Ok, so I'm making my homebrew room thermometer, which is actually made from some transistors, a LM335Z temp. sensor (10mV per Kelvin), a 2 7-seg display and a PIC18F1320.
The thing is the multiplexing works pretty well, but not for the A/D conversion. The numbers on the display is very freaky, and not displaying anything that made sense. (It ended up displaying 09 instead of a room temperature, which is approx. 26 degrees celcius!)
Both of the A/D and Multiplexing are in interrupts by the way.
Here's the code. By the way, I have included a hefty conversion from Kelvin to Celcius. I have made it right-justified, and placed all the interrupt vectors properly. What could I have been missing?
Code:
#pragma config OSC = HS
#pragma config PWRT = OFF, BOR = OFF
#pragma config WDT = OFF
#pragma config DEBUG = OFF, LVP = OFF, STVR = OFF, MCLRE = OFF
#include <P18F1320.h>
void T0_ISR(void);
void AD_ISR(void);
#pragma interrupt chk_isr
void chk_isr(void)
{
if (INTCONbits.TMR0IF == 1)
T0_ISR();
if (PIR1bits.ADIF == 1)
AD_ISR();
}
#pragma code HiPrioInt = 0x0008
void HiPrioInt(void)
{
_asm
GOTO chk_isr
_endasm
}
#pragma code
char d0, d1, flag, L_byte, H_byte;
char temp;
unsigned int num;
char lookup[] = { 0x7e, 0x30, 0x6d, 0x79, 0x33,
0x5b, 0x5f, 0x70, 0x7f, 0x73
};
void main(void)
{
TRISAbits.TRISA0 = 0; // First Digit (Most Significant)
TRISAbits.TRISA1 = 0; // Last Digit (Least Significant)
TRISAbits.TRISA2 = 0;
TRISB = 0x0;
PORTB = 0x00;
PORTAbits.RA0 = 0;
PORTAbits.RA1 = 0;
TMR0H = 0xCF;
TMR0L = 0x2C;
T0CON = 0x08;
INTCONbits.TMR0IF = 0;
INTCONbits.TMR0IE = 1;
T0CONbits.TMR0ON = 1;
ADCON0 = 0b00001001;
ADCON1 = 0b01110011;
ADCON2 = 0b10101101;
PIR1bits.ADIF = 0;
PIE1bits.ADIE = 1;
INTCONbits.PEIE = 1;
INTCONbits.GIE = 1;
flag = 0;
temp = 0;
// d0 = 1;
// d1 = 6;
while(1)
{
ADCON0bits.GO = 1;
num = 0.4762 * temp + 6.8042;
d0 = num / 10;
d1 = num % 10;
}
}
void T0_ISR(void)
{
flag = ~flag;
if (flag == 0)
{
PORTAbits.RA1 = 0;
PORTB = lookup[d0];
PORTAbits.RA0 = 1;
}
else
{
PORTAbits.RA0 = 0;
PORTB = lookup[d1];
PORTAbits.RA1 = 1;
}
TMR0H = 0xCF; // reload values into the TMR0H and TMR0L
TMR0L = 0x2C;
INTCONbits.TMR0IF=0;
}
void AD_ISR(void)
{
L_byte = ADRESL;
H_byte = ADRESH;
L_byte >> 2;
L_byte &= 0b00111111;
H_byte <<= 6;
H_byte &= 0b11000000;
temp = L_byte | H_byte;
PIR1bits.ADIF = 0;
}
Also, when I tested this LM335Z on a voltmeter, it's showing values around 2.80-2.88V when it is supposed to be warmer than that! I guess I should calibrate the sensor!