zanor
Member level 4
Hi!
I'm using ADC on 16f819 and bit banging the result to my PC. But the adc result is so unstable, it keeps jumping up and down(ex. 950 jumps between 947 and 953).
I have connected a 1k pot to the inputs.
here's my mikroC code:
Doeas anyone have clue about what to do to make this stable? Or is ADC just this unstable?
BTW, I'm running the 8MHz internal osc.
EDIT: And when I tie the input pin directly to ground I read 0 - 4. This can't be right, or?
I'm using ADC on 16f819 and bit banging the result to my PC. But the adc result is so unstable, it keeps jumping up and down(ex. 950 jumps between 947 and 953).
I have connected a 1k pot to the inputs.
here's my mikroC code:
Code:
unsigned short data = 0, ro = 1;
unsigned short *er;
void Comm_WriteConst(const unsigned char *s)
{
while(*s)
{
Soft_Uart_Write(*s) ;
s++ ;
}
}
void SENDB(char sendme) {
Soft_UART_Write(sendme);
}
void WAITB() {
while(*er) {
data = Soft_UART_Read(er);
}
ro = 1;
}
void main() {
er = &ro;
OSCCON = 0xFF;
TRISA = 0xFF;
TRISB = 0b00000010;
PORTA = 0b00000000;
PORTB = 0b00000000;
ADCON0 = 0b01000001; // Max 20MHz, Channel 0, ADC ON
ADCON1 = 0b01000000; // 4 analogue channels and
// Left Justified (ADRESH = 8Bit result)
Soft_UART_Init(PORTB, 1, 0, 9600, 0);
Delay_ms(10);
while(1) {
WAITB();
if(data == 'a')
{
SENDB('a');
ADCON0 = 0b01000001;
Delay_ms(1);
ADCON0 = 0b01000101;
while(ADCON0 & 0x4);
SENDB(ADRESH);
SENDB(ADRESL);
ADCON0 = 0b01001001;
Delay_ms(1);
ADCON0 = 0b01001101;
while(ADCON0 & 0x4);
SENDB(ADRESH);
}
}
}
Doeas anyone have clue about what to do to make this stable? Or is ADC just this unstable?
BTW, I'm running the 8MHz internal osc.
EDIT: And when I tie the input pin directly to ground I read 0 - 4. This can't be right, or?