richardlaishram
Member level 4
- Joined
- Jan 6, 2013
- Messages
- 77
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Location
- Planet Earth
- Activity points
- 1,804
void InitADC(void)
{
TRISA0 = 0x01; // PortA Pin0 configured as input
ADCON1 = 0x00; // PortA configured as Analog input with Vref as Vdd
ADCON0 = 0x41; // ADC Enabled
}
unsigned int ADCValue0(void)
{
ADCON0 &= 0x45; // Start AD Conversion
ADCON0 |= 0x40; // Conversion Cycle in Progress
__delay_ms(10);
while(ADCON0 |= 0x40); // Wait for AD conversion to Complete
return ADRES; // ADC result stored
}
void InitADC(void)
{
ADCON1 = 0x80;
TRISA = 0x2F;
ADCON0 = 0x81;
}
unsigned int ADCValue(void)
{
ADCON0 &= 0x87;
ADCON0 |= 0x08;
__delay_ms(10);
GO_nDONE = 1;
while(GO_nDONE);
return ((ADRESH<<8)+ADRESL);
}
void InitADC(void)
{
TRISA0 = 0x01;
ADCON1 = 0x00;
ADCON0 = 0x41;
}
unsigned int ADCValue0(void)
{
ADCON0 &= 0x45;
ADCON0 |= 0x40;
GO_nDONE = 1; //changes
__delay_ms(10);
while(ADCON0 |= 0x40);
return(ADRES); //changes
}
unsigned int ADCValue(void)
{
ADCON0 &= 0x45;
ADCON0 |= 0x40;
__delay_ms(10);
GO_nDONE = 1;
while(GO_nDONE);
return ADRESH;
}
Even this is not working. I tried using the ADRESH register and it's working fine with Proteus.
Code:unsigned int ADCValue(void) { ADCON0 &= 0x45; ADCON0 |= 0x40; __delay_ms(10); GO_nDONE = 1; while(GO_nDONE); return ADRESH; }
I need to check it again with the actual hardware, though. I'm not able to find any register with the name ADRES in the Compiler Help pdf also, so I guessed and tried ADRESH, and luckily it worked in Proteus.
Zip and post complete project files.
Code C - [expand] 1 __CONFIG(FOSC_XT & WDTE_ON & PWRTE_ON & CP_OFF & BOREN_OFF);
what is happening in hardware can you post the schematic??
I have gone through the datasheets, sir.I think you used code of some other PIC with the PIC you are using. If that is right then ADCONx values change. Read the datasheet.
Exactly.. The Source and uc shd have a common ground and the value to be measured is shd be stable unless no use in software corrections.......Now I tried connecting the power supply to a 12V battery and seems like the ADC value is showing the correct value. Can the problem be because of the 12V AC-DC adapter used for powering the board?
Exactly.. The Source and uc shd have a common ground and the value to be measured is shd be stable unless no use in software corrections.......
Maybe your AC-DC power adapter doesn't have good filtering.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 __delay_ms(250); adcval2 = ADC_Chan0(); o = adcval2%10; n = (adcval2%100)/10; m = adcval2/100; __delay_ms(250); WriteCommandToLCD(0xC5); WriteDataToLCD(o+0x30); WriteDataToLCD(n+0x30); WriteDataToLCD(m+0x30);
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 __delay_ms(250); adcval2 = ADC_Chan0(); o = adcval2%10; n = (adcval2%100)/10; m = adcval2/100; __delay_ms(250); WriteCommandToLCD(0xC5); WriteDataToLCD(o+0x30); WriteDataToLCD(n+0x30); WriteDataToLCD(m+0x30);
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?