[SOLVED] 18f1330 pin RA1 problem

Status
Not open for further replies.

Kaleborg

Member level 4
Joined
Nov 2, 2008
Messages
75
Helped
7
Reputation
14
Reaction score
5
Trophy points
1,288
Activity points
1,776
Hello!

I'm having problems in setting the RA1 pin as digital.
Code:
void InitHware(void){
	
	OSCCON = 0x60;	//4MHz clock
	TRISA = 11101000;	
	TRISB = 0;	
	CMCON = 0;		//comparators disabled
	ADCON0 = 0;
	ADCON1 = 0;		//disable A/D
		
	RCONbits.IPEN = 1;	//enable IPEN, which enables interrupt priority lrvels
	INTCONbits.GIE = 1;
	INTCONbits.PEIE = 1;		/*all interrupts enabled*/
This is how i'm configuring it and everything seem to be working fine(PWM, timers, uart) exept the pin RA1 it just does not go high.
I thought that the chip may be faulty but same thing happens on the other chip.
Is there something that i'm missing here.
I appreciate any tips.

Regards
 

you should read the datasheet very carefully and compare it against your code to see if you are doing everything right.

in this case, the mistake is so glaring that you should be able to spot it quickly.
 

    Kaleborg

    Points: 2
    Helpful Answer Positive Rating
Ok it turned out to be A/D setings. It should be set
Code:
ADCON1=0x07
But it is not what is says in datasheet.In datasheet it looks like that:
Code:
bit 4 VCFG0: Voltage Reference Configuration bit (VREF+ source)
1 = Positive reference for the A/D is VREF+
0 = Positive reference for the A/D is AVDD
bit 3 PCFG3: A/D Port Configuration bit for RA6/AN3(1,2)
1 = Port is configured as AN3
0 = Port is configured as RA6
bit 2 PCFG2: A/D Port Configuration bit for RA4/AN2(1)
1 = Port is configured as AN2
0 = Port is configured as RA4
bit 1 PCFG1: A/D Port Configuration bit for RA1/AN1(1)
1 = Port is configured as AN1
0 = Port is configured as RA1
bit 0 PCFG0: A/D Port Configuration bit for RA0/AN0(1)
1 = Port is configured as AN0
0 = Port is configured as RA0

So the way i read it was that 1 sets it as Analog and 0 as digital. So am i reading it wrong?? I'm just curious now.

But anyway thanks for help
 

Code:
bit 4 VCFG0: Voltage Reference Configuration bit (VREF+ source) 
1 = Positive reference for the A/D is VREF+ 
0 = Positive reference for the A/D is AVDD 
bit 3 PCFG3: A/D Port Configuration bit for RA6/AN3(1,2) 
1 = Port is configured as AN3 
0 = Port is configured as RA6 
bit 2 PCFG2: A/D Port Configuration bit for RA4/AN2(1) 
1 = Port is configured as AN2 
0 = Port is configured as RA4 
bit 1 PCFG1: A/D Port Configuration bit for RA1/AN1(1) 
1 = Port is configured as AN1 
0 = Port is configured as RA1 
bit 0 PCFG0: A/D Port Configuration bit for RA0/AN0(1) 
1 = Port is configured as AN0 
0 = Port is configured as RA0
Well yes, at least this is how i understood it.
This thing above comes from datasheet.

EDIT: Yeah the datasheet had a mistake in it
Just found errata to it. Its the second time that i fell for something like that. Microchip is horrible with their documentation...from now on I'll be reading datasheets as well as erratas.
 

so how's setting the corresponding bits in ADCON1 reconciling with the datasheet?
 

This is what datasheet says:
Code:
bit 4 VCFG0: Voltage Reference Configuration bit (VREF+ source) 
1 = Positive reference for the A/D is VREF+ 
0 = Positive reference for the A/D is AVDD 
bit 3 PCFG3: A/D Port Configuration bit for RA6/AN3
1 = Port is configured as AN3 
0 = Port is configured as RA6 
bit 2 PCFG2: A/D Port Configuration bit for RA4/AN2
1 = Port is configured as AN2 
0 = Port is configured as RA4 
bit 1 PCFG1: A/D Port Configuration bit for RA1/AN1
1 = Port is configured as AN1 
0 = Port is configured as RA1 
bit 0 PCFG0: A/D Port Configuration bit for RA0/AN0
1 = Port is configured as AN0 
0 = Port is configured as RA0
Which is wrong, it should be 1 sets as Digital and 0 sets as Analog
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…