PDA

View Full Version : 16f877a porta.5 resets chip



lecoind
- 29th September 2009, 02:10
I am working with a 16f877a and everything works great with my program, but when I take porta.5=0 to run the program, it's like the mclr resets. All other ports are like this using a 5k pullup resistor. After it resets, program runs perfect untill i ground ra5 again.

osc 20
adcon=7 digital off
cmcon=7

is there something special about porta.5 that does this?

Archangel
- 29th September 2009, 02:32
Hi lecoind,
Since I don't know you I won't assume you Do/Do Not know anything, so pardon me if I cover anything that is Old Hat to you.
Oscillator:


DEFINE OSC 20

This chip has No ADCON it has ADCON1 & ADCON0


ADCON1 = 7 ' All analog off seven or six, ports as digital
ADCON0 = 0 ' bits 6:7 control A/D Conversion Clock
' bits 3:5 select AN Channels
' bit 2 is A/D Go/Done 0 = done
' bit 1 unimplemented
' bit 0 ADON powers up or shuts down A/D

comwarrior
- 30th September 2009, 01:06
interupt jump into a none interupt routine?
Are you using interupts?
Have you tried disabling all interupts?

RA5 is used for...
Digital I/O.
Analog input 4.
SPI slave select input.
Comparator 2 output

ok, are you using SPI?
are you doing anything with comparator 2?
do you have RA5 set to digital?

Have you tried moving the RA5 input to another pin?

This is my chunk of code to setup analogue ports and disable interupts, Perhaps it will help...


' Setup chip
ADCON0.6 = 1 ' ADC clock set to Fosc/64
ADCON0.7 = 1 ' ADC clock set to Fosc/64
ADCON1.6 = 0 ' ADC clock set to Fosc/64
INTCON = 0 ' Disable all interupts
TRISE = %00000111 ' Set PortE to all inputs
TRISD = %00000000 ' Set PortD to all outputs
TRISC = %00000000 ' Set PortC to all outputs
TRISB = %00000000 ' Set PortB to all outputs
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = 0 ' PORTA is analog

Consulting 877A's idiots guide now...


Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
1Fh ADCON0 ADCS1 ADCS0 CHS2 CHS1 CHS0 GO/DONE — ADON
9Fh ADCON1 ADFM ADCS2 — — PCFG3 PCFG2 PCFG1 PCFG0


so ADCON1 = 7 means...
PCFG0 = 1
PCFG1 = 1
PCFG2 = 1
PCFG3 = 0

Acording to the datasheet, the value your sending ADCON1 00000111 is sortof invalid...
The closest match to it is 0000011x where x is "unknown". The purpose of this value is to set port A to all digital...

Try adding

TRISA = %00000000
After your ADCON's. This will make port A all digital outputs and will correct any possible miss-configurations...

Info found on search

Note: When using the SSP module in SPI Slave mode and SS enabled, the A/D converter must be set to one of
the following modes, where PCFG3:PCFG0 = 0100, 0101, 011x, 1101, 1110, 1111.

Found a 'conflict' with PSP port and PCFG0:PCFG2 registers

lecoind
- 1st October 2009, 13:54
Great info, I have no analog or comparators.. What would be the best commands for everthing digital so I can test it in that mode. I always get confused with the data sheets. Thanks so much, leon

mackrackit
- 1st October 2009, 15:51
Great info, I have no analog or comparators.. What would be the best commands for everthing digital so I can test it in that mode. I always get confused with the data sheets. Thanks so much, leon
Like Joe said


ADCON1 = 7 ' All analog off seven or six, ports as digital

AND


CMCON = 7

Will make the chip non analog.

comwarrior
- 1st October 2009, 18:15
I could be wrong, but doesn't a TrisA=00000000 command reset the analogue registers?

mackrackit
- 1st October 2009, 18:29
I could be wrong, but doesn't a TrisA=00000000 command reset the analogue registers?
Sort of...
TRISX sets input or output. But not the type of input.