Jump to content
Sign in to follow this  
drumanart

18f4420 Adcon2 Problem

Recommended Posts

Hello everybody.

Can anybody tell me why the program works only if I configure the ADCON2 to Fosc/2. I use a 20Mhz external OSC. So I need (reading the datasheet of the PIC) at least 12 TAD to make the conversion correct. If I change the bits ADCS2-ADCS0 (ADCON2 registor) to something else then Fosc/2 the progrma stops working at all.

 

Thanks for help. Martin

 

void main(void)
{
init_TX_RX();

volatile bit Go_Done@ADCON0.1;	  // Note the 18fxx chip puts this in bit 1, for 16Fxx to 2;
	volatile unsigned char ad_h@ADRESH;
	volatile unsigned char ad_l@ADRESL;


short result;
char result_h;
char result_l;
unsigned long tp;
unsigned tp1;
unsigned i;


rcif = 0;
trisa = 00000001b;					// RA0 in.
trise = 00000111b;					// RE0 - RE2, analogue in.
trisb = 10100000b;					// RB5 Taster in. RB0-RB4 LED's. RB7 PRG_DATA in.
trisc = 11000000b;					// ??? all out exept RC7 RX; RC0, RC1, RC2 Tr.
trisd = 0x00;						// 7_digit LED bus.


rcreg = 0X00;

portc = 0x00;						// all LED's OFF.
set_bit (portc,4);					// PW_LED blue;

adcon1 = 00001110b;					// RA0 analog, rest digital I/O.
adcon2 = 10101000b;					// Result is right justified, conversion Ckl TAD 12, 
							// ascquisition t=Fosc/2.

while(1)
{
adcon0 = 00000001b;					// A/D turn ON.

	Go_Done = 1;


	while (Go_Done == 0);			

		result_h = ad_h;
		result_l = ad_l;


		if (result_l >= 07)
		{
		while(!trmt);					
		txreg = result_l;			
		while(!trmt);					
		txreg = result_h;			
		set_bit (portc,0);			// white_LED on.
		delay_1();
		}
		else
		clear_bit (portc,0);			// white_LED off.

}
}

Share this post


Link to post
Share on other sites
Hello everybody.

Can anybody tell me why the program works only if I configure the ADCON2 to Fosc/2. I use a 20Mhz external OSC. So I need (reading the datasheet of the PIC) at least 12 TAD to make the conversion correct. If I change the bits ADCS2-ADCS0 (ADCON2 registor) to something else then Fosc/2 the progrma stops working at all.

 

Thanks for help. Martin

Martin,

 

Shouldn't

while (Go_Done == 0);

be [/code] or

while (Go_Done != 0);

For 20MHz Oscillator try using a Tad of 16Tosc and Tacq of 4Tad

This gives an automatic 3.2uS aquisition time and 9.6uS conversion time

 

Regards

 

davidb

Share this post


Link to post
Share on other sites
Hello everybody.

Can anybody tell me why the program works only if I configure the ADCON2 to Fosc/2. I use a 20Mhz external OSC. So I need (reading the datasheet of the PIC) at least 12 TAD to make the conversion correct. If I change the bits ADCS2-ADCS0 (ADCON2 registor) to something else then Fosc/2 the progrma stops working at all.

 

Thanks for help. Martin

Martin,

 

Shouldn't

while (Go_Done == 0);

be [/code] or

while (Go_Done != 0);

For 20MHz Oscillator try using a Tad of 16Tosc and Tacq of 4Tad

This gives an automatic 3.2uS aquisition time and 9.6uS conversion time

 

Regards

 

davidb

 

Uff, yes that was wrong, now it works.

I use Source Boost with MPLAB IDE and if I'd like to send the data using the rs232_driver.h function. I get a lot of errors when I try to #include <rs232_driver.h.> .

I use a 18F4420

Is this a path problem?

Thanks Martin

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...