ADC LIB is Work but code not

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
gedo
Posts: 53
Joined: 02 Aug 2006 16:42

ADC LIB is Work but code not

#1 Post by gedo » 30 Dec 2017 02:54

HI guys. Here have two sample. 1 routine is working perfect that is used lib. Bat when I use the second I get data from AN0 . What is wrong or what doing different lib ?

Code: Select all

sbit ADGD at GO_DONE_bit;
unsigned int voltage_val;
unsigned char ADHIGH, ADLOW;

void main() {
char txt[7];
OSCCON=0b01110110;
LATA=0x00;
ADCON2 = 0b10101111;// ;right justify, Frc, 12 TAD ACQ time
ADCON1 = 0b00000000;// ;ADC ref = Vdd,Vss
TRISA=0xFF;
ANSEL=0x00;
  C1ON_bit = 0;               // Disable comparators
  C2ON_bit = 0;
ADCON0=0b00000001;// AN1, ADC on
/*
0000 = AN0
0001 = AN1
0010 = AN2
0011 = AN3
0100 = AN4
0101 = AN5(1)
*/
//////////////// FIRST ROUTINE ///////////////////
ADC_Init();
UART1_Init(115200); // initialize UART1 module
Delay_ms(100);
do {
voltage_val = ADC_Read(1); // Get 10-bit results of AD conversion
IntToStr(voltage_val, txt);
UART_Write_Text("CH1:");
UART_Write_Text(txt);
UART1_Write(0x0D);
UART1_Write(0x0A);
} while(1);


//////////////// SECOND ROUTINE ///////////////////
ADGD=1;

UART1_Init(115200); // initialize UART1 module
Delay_ms(100);


do {
ADGD = 1;
voltage_val = 0;
voltage_val = (ADHIGH << 8 ) + ADLOW;

IntToStr(voltage_val, txt);
UART_Write_Text("CH1:");
UART_Write_Text(txt);

UART1_Write(0x0D);
UART1_Write(0x0A);

while(ADGD == 1) {};
ADHIGH = ADRESH;
ADLOW = ADRESL;
} while(1);

Code: Select all

}

gedo
Posts: 53
Joined: 02 Aug 2006 16:42

Re: ADC LIB is Work but code not

#2 Post by gedo » 01 Jan 2018 14:11

Sorry guys I found my mistake :)

bit 5-2 CHS<3:0>: Analog Channel Select bits
0000 = AN0
0001 = AN1
0010 = AN2
0011 = AN3
0100 = AN4

old
ADCON0=0b00000001;// AN1, ADC on

right conf
ADCON0=0b00000100;// AN1, ADC on

Post Reply

Return to “mikroC PRO for PIC General”