PDA

View Full Version : PortA.4 not working on 16F690



modifyit
- 8th February 2007, 04:27
I am having trouble getting my 16F690 pin AN4 working as a digital output. No matter what I try the pin seems to float between high and low and creates an approx 2.6 volts using a multimeter.

I think I have all the typical items covered like the ANSEL and ANSELH registers and the comparator registers.

Here is the code, any thoughts are appreciated:

[/code]
'defines
OSCCON=%01110101
define OSC 8
DEFINE SHIFT_PAUSEUS 100
'end defines
data 0,0
'includes
'end includes

' Config Fuses
@ __config _INTRC_OSC_NOCLKOUT & _CPD_ON & _CP_ON & _BOR_ON & _MCLRE_ON & _PWRTE_ON & _WDT_ON & _IESO_OFF & _FCMEN_OFF
' PICBASIC PRO program to show button press on LED

ANSEL = %00000000 ' Set all pins digital
ANSELH = %00000000
WPUA = %00000011 ' Enable pullups for buttons
WPUB = %00000000
OPTION_REG.7 = 0
CM1CON0.0=0
CM2CON0.0=0

TRISA = %11001111 ' Set PORTA.4,5 (LEDs) to output


loop:
PORTA.4 = 1 ' Turn on 1st LED
pause 1000
goto loop

[code/]

modifyit
- 8th February 2007, 04:36
Also I have been able to get the rest of the portA pins other then RA3 and RA4 to work as digital outputs.

Thanks again

skimask
- 8th February 2007, 04:40
I am having trouble getting my 16F690 pin AN4 working as a digital output. No matter what I try the pin seems to float between high and low and creates an approx 2.6 volts using a multimeter.

I think I have all the typical items covered like the ANSEL and ANSELH registers and the comparator registers.

Here is the code, any thoughts are appreciated:

[/code]
'defines
OSCCON=%01110101
define OSC 8
DEFINE SHIFT_PAUSEUS 100
'end defines
data 0,0
'includes
'end includes

' Config Fuses
@ __config _INTRC_OSC_NOCLKOUT & _CPD_ON & _CP_ON & _BOR_ON & _MCLRE_ON & _PWRTE_ON & _WDT_ON & _IESO_OFF & _FCMEN_OFF
' PICBASIC PRO program to show button press on LED

ANSEL = %00000000 ' Set all pins digital
ANSELH = %00000000
WPUA = %00000011 ' Enable pullups for buttons
WPUB = %00000000
OPTION_REG.7 = 0
CM1CON0.0=0
CM2CON0.0=0

TRISA = %11001111 ' Set PORTA.4,5 (LEDs) to output


loop:
PORTA.4 = 1 ' Turn on 1st LED
pause 1000
goto loop

[code/]

Read the datasheet, page 59, read the grayed note in the block right above example 4-1 on the right side of the page....then read your code again...you'll laugh, you'll cry, you'll hurl!


Ok, just rechecked the datasheet. Unless I'm reading it wrong, page 59 (as described above) and page 60, paragraph 4.2.1 contradict each other.

Also, which one is it? RA4 or AN4?

Archangel
- 8th February 2007, 04:54
Where in the code do you turn off the LED?
Shouldn't Wpau = %00000111 ?

Archangel
- 8th February 2007, 04:57
Ok, just rechecked the datasheet. Unless I'm reading it wrong, page 59 (as described above) and page 60, paragraph 4.2.1 contradict each other.

Also, which one is it? RA4 or AN4?
That confused you too? I thought it was only me.

skimask
- 8th February 2007, 04:59
That confused you too? I thought it was only me.

I checked the errata...nothing there.
We must be missing something somewhere.
Maybe the only way to figure it out is to try it, or maybe one of those other config bits overrides the ANSEL bits...or maybe it's time for another beer...

sougata
- 8th February 2007, 05:44
Hi,

If the config fuses are not properly set (page 197 datasheet) this pin will function as a clock out (Fosc/4) with the internal oscillator enabled. Please check.

modifyit
- 8th February 2007, 18:31
Sorry about that phat finger disease. PortA.4, RA4 is the pin I am having issues with.

I've double checked the config and its set for INTOSCIO so it should not be acting as an oscillator out pin. I've also read the chip back into my programmer and it shows the config is set correctly.

and yes it is time for another beer :D

skimask
- 8th February 2007, 18:57
Sorry about that phat finger disease. PortA.4, RA4 is the pin I am having issues with.

I've double checked the config and its set for INTOSCIO so it should not be acting as an oscillator out pin. I've also read the chip back into my programmer and it shows the config is set correctly.

and yes it is time for another beer :D

Try the ANSEL bits the other way around. You have them set as 0's, try them set as 1's. Like I said earlier, I think the datasheet is contradicting itself.

modifyit
- 9th February 2007, 01:36
got it to work! some how my settings on the melabs programmer got goofed up and the config vars wern't writing to the chip.

Archangel
- 9th February 2007, 01:58
It seems the difficult problems are easier to find !