Paritoshgiri
Member level 5
Hi
I am using PIC 18f4550 and I am using MPLAB IDE v8.80. I am trying to convert a sensor voltage from analog to digital. The sensor voltage range was from -10 V to + 10V, so I used MAX 232. Now after the MAX, the output is 4.416 V to 4.342 V for 0 to -10 V and 0.017 V to 0.022V for 1V to +10 V. So I input the output from MAX to AN0 and give reference 2.56 V to AN2. Here's my code:
I am using 20 MHz crystal oscillator and i've also attached the configuration bits. I tried to check the outputs by putting leds in port D but in all the cases, the leds are behaving the same way. Some LEDs are blinking, some are glowing and some not glowing. What might be the main problem behind it? and how to solve it? Also, I want to view the digital signal in hyperterminal using UART. What modifications should I make for that in the code?
Please help me out. My circuit seems correct because I've successfully tested blinking leds in port B. Please Please help me with this one.
I am using PIC 18f4550 and I am using MPLAB IDE v8.80. I am trying to convert a sensor voltage from analog to digital. The sensor voltage range was from -10 V to + 10V, so I used MAX 232. Now after the MAX, the output is 4.416 V to 4.342 V for 0 to -10 V and 0.017 V to 0.022V for 1V to +10 V. So I input the output from MAX to AN0 and give reference 2.56 V to AN2. Here's my code:
Code:
void main(void)
{
unsigned char L_Byte, H_Byte, bin;
TRISD = 0; //make port D output port
TRISAbits.TRISA0 = 1; //RA0 = input for analog input
TRISAbits.TRISA2 = 1; //RA2 = input for Vref input
ADCON0 = 0x81; // Fosc/64, channel 0, A/D is ON
ADCON1 = 0xC5; //right justified, AN0 = analog, AN3 = Vref+
while (1)
{
Delay10KTCYx(100);
ADCON0bits.GO = 1; //start converting
while (ADCON0bits.DONE == 1); //wait for EOC
L_Byte = ADRESL; //save the low byte
H_Byte = ADRESH; //save the high byte
L_Byte >>= 2; //shift right
L_Byte &= 0x3F; //mask the upper 2 bits
H_Byte <<= 6; //shift left 6 times
H_Byte &= 0xC0; //mask the lower 6 bits
bin = L_Byte | H_Byte;
PORTD = bin;
}
}
I am using 20 MHz crystal oscillator and i've also attached the configuration bits. I tried to check the outputs by putting leds in port D but in all the cases, the leds are behaving the same way. Some LEDs are blinking, some are glowing and some not glowing. What might be the main problem behind it? and how to solve it? Also, I want to view the digital signal in hyperterminal using UART. What modifications should I make for that in the code?
Please help me out. My circuit seems correct because I've successfully tested blinking leds in port B. Please Please help me with this one.