• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F688 unwieldy issue for RA4

Status
Not open for further replies.

cimulation

New Member
I have tried to toggle RA4 using the following piece of code:

Code:
if ( TMR1IE == SET  && TMR1IF == SET) //If A Timer1 Interrupt
{
	ctr++;
	ctr2++;
	if(ctr2>100)
	{  
		if(flip==0)
		{
			RA4=1;
			RA5=0;
			flip=1;
		}
		else
		{
			RA4=0;
			RA5=1;
			flip=0;
		}
		ctr2=0;
	}
...
However RA5 flips fine on Timer 1 interrupt but RA4 there is no change. ie RA5 filps after every 100 interrupts but RA4 always shows 0V on a multimeter.

I use the following code to enable interrupts

Code:
    PEIE = 1;                      // Enable Peripheral Interrupts
    GIE = 1;                      // Enable Global interrupts
I am using the follwing initialize sequence:
__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
& UNPROTECT & BORDIS & IESODIS & FCMDIS); using the PICC compiler.

Can anyone spot the issue here.

Thanks a lot for your insight.:)
Sumit
 

kchriste

New Member
Forum Supporter
Have you initialized PORTA properly?
ie: Have you setup the, CMCON0, ANSEL & TRISA registers properly?
 

cimulation

New Member
Have you initialized PORTA properly?
ie: Have you setup the, CMCON0, ANSEL & TRISA registers properly?
Thanks for your suggestion. I already have the following code to initalize:
How would setting CMCON0 and ANSEL help?

Code:
TRISA=0b00000000;
TRISC=0b00100000;
PORTA=0;
PORTC=0;
Best REgards,
Sumit.
 

ericgibbs

Well-Known Member
Most Helpful Member
Thanks for your suggestion. I already have the following code to initalize:
How would setting CMCON0 and ANSEL help?

Code:
TRISA=0b00000000;
TRISC=0b00100000;
PORTA=0;
PORTC=0;
Best REgards,
Sumit.
hi,
RA4 is an open drain output, it requires an external pullup resistor when used as an output.:)

EDIT:
checking the 16F688 d/s shows that RA4 on this model has a programmable 'pullup'.
Have you programmed the pullup.?
 
Last edited:

cimulation

New Member
hi,
RA4 is an open drain output, it requires an external pullup resistor when used as an output.:)

EDIT:
checking the 16F688 d/s shows that RA4 on this model has a programmable 'pullup'.
Have you programmed the pullup.?
I am not sure how to program the pullup. Should I use the ANSEL register to program the pullup.
Per the datasheet I was not able to locate pullup specific information. What i found is-> "TRISA5 and TRISA4 bits are set when the Timer1 oscillator is enabled. RA5 and RA4 read as ‘0’ and TRISA5 and TRISA4 bits read as ‘1’."??
 

Pommie

Well-Known Member
Most Helpful Member
You should try reading the data sheet. If you look at the section on PortA you will see how the pullups are controlled.

Mike.
 

cimulation

New Member
You should try reading the data sheet. If you look at the section on PortA you will see how the pullups are controlled.

Mike.
Thanks for the direction ...i will try to play around with the WPUA and RAPU to get this working.

But just to learn something from it- I was wondering how/why is it working as-is for RA5.

Best Regards,
Sumit
 

eblc1388

Active Member
Where in the 16F688 data sheet does it mention RA4 is open drain/collector?

The port pin RA4 is stated in the datasheet as "General purpose I/O & CLK output" and the block diagram of RA4 looks like RA5 in my DS41203B datasheet. :confused:
 

kchriste

New Member
Forum Supporter
How would setting CMCON0 and ANSEL help?
The default on reset is that the IO pins are set for Analog input by ANSEL. Now, while TRISA will set them for output, when you read the pin it is still in analog input mode which will mess up any read-modify-write operations which your C code may or may not generate for the RA4=1 statement. So try setting it like this:
ANSEL = 0;

From the 16F688 datasheet:
The state of the ANSEL bits has no affect on digital
output functions. A pin with TRIS clear and ANSEL set
will still operate as a digital output, but the Input mode
will be analog. This can cause unexpected behavior
when executing read-modify-write instructions on the
affected port.
The default reset state for CMCON0 is 0 which leaves the comparators in reset, but the pins in analog mode. RA4 doesn't have comparator assigned to it, but to save you further IO grief, try setting it like this:
CMCON0 = 0x07;

I don't think the pin is open drain due to the fact that it can double as the OSC2/CLKOUT pin as well. But if the above doesn't work, try an external 470Ω pull up resistor.
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top