RA0 and RA1 low voltage problem when digital output on PIC18F2525

Thread Starter

zaferaltun

Joined Aug 31, 2016
65
Hi

I 'm not newbee with PICs, I used similar products before this PIC18F2525 SMD but this one drived me crazy all the day. I can not get high output voltage on RA0 and RA1 although they are digital output, analog converter and the comparators are disabled. The multimeter shows between 0.6 and 0.8V. If I use RA2 and RA3, they works well for example.

RA0 and RA1 connected to leds with 3.3k resistors. The PIC works with 3.3V. RA0 and RA1 options work in the simulator well by the way.

Here is my simple code.

Code:
/*
* File:   main.c
*
* Created on November 20, 2017, 10:40 AM
*/

#define _XTAL_FREQ              8000000

#pragma config OSC                 = INTIO67               // Oscillator Selection bits (Internal oscillator block, port function on RA6 and RA7)
#pragma config FCMEN            = OFF                   // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO             = OFF                   // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
#pragma config WDT              = OFF                   // no watchdog
#pragma config LVP              = OFF                   // LVP MUST be off
#pragma config MCLRE            = OFF
#pragma config PBADEN           = OFF
#pragma config LPT1OSC          = OFF
#pragma config XINST            = OFF                    // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

#include <xc.h>
#include <p18f2525.h>

void delayUS(int us);
void delayMS(int ms);
void init(void);

void init(){
    // 8 mhz osc speed
    IRCF2 = 1;
    IRCF1 = 1;
    IRCF0 = 1;

    // Disable watch dog timer
    WDTCON = 0;
    SWDTEN = 0;

    // Disable comparators/captures
    CMCON = 0b00000111;
    CVRCON = 0;
    CCP1CON = 0;
    CCP2CON = 0;

    // Disable all analog inputs to use as digital
    ADCON0 = 0;
    ADCON1 = 0b00001111;
    ADCON2 = 0;

    // Set port a as output
    TRISA = 0;
    PORTA = 0;
    LATA = 0;

    // Set port b as output
    TRISB = 0;
    PORTB = 0;
    LATB = 0;

    // Set all pins of port c as output except RX
    TRISC = 0b10000000;
    PORTC = 0;
    LATC = 0;
}

void main(void) {
 
    init();
    delayMS(500);

    // Write your code here
    while (1) {
        LATA = 0xFF;
        PORTA = 0xFF;
        delayMS(250);
        LATA = 0;
        PORTA = 0;
        delayMS(250);
    }
}

void delayUS(int us) {
    while (us-- >= 0) {
        __delay_us(1);
    }
}

void delayMS(int ms) {
    while (ms-- >= 0) {
        __delay_ms(1);
    }
}
 

Attachments

I am not familiar with the chip and don't know how helpful I can be...I thought that you had not configured CMCON but you did. This is a real learning opportunity. Removing the load from RA0 and RA1, do the pins swing?
 
Last edited:

AlbertHall

Joined Jun 4, 2014
12,347
CMCON is correctly set to 7 in the program (line 37).

The program as written works as expected in the simulator so first guess is that the problem is with the hardware. With the power switched off, check the resistance to ground from RA0 and RA1.
 

Thread Starter

zaferaltun

Joined Aug 31, 2016
65
Hi. Both of them around 730 ohms.

CMCON is correctly set to 7 in the program (line 37).

The program as written works as expected in the simulator so first guess is that the problem is with the hardware. With the power switched off, check the resistance to ground from RA0 and RA1.
 

AlbertHall

Joined Jun 4, 2014
12,347
Well that's not right. Try lifting the ends of the resistors connected to RA0 and RA1 and measure the resistance on the pins again. You might usefully also measure the resistance between those pins.
 

Thread Starter

zaferaltun

Joined Aug 31, 2016
65
I think you might be right about the damage. I removed the resistors and measured the resistance between RA0-GND, RA1-GND and RA0-RA1. They all vary strangely. They was over 5M Ohms when I measured for the first time, I continued to measure over and over again until be sure but they all decreased to around 1-10k!

The resistors are smd and I designed the GND as zone, all the board remains from the components and tracks. It seems the pins shorted in a way because of the soldering problems. Am I right?

Well that's not right. Try lifting the ends of the resistors connected to RA0 and RA1 and measure the resistance on the pins again. You might usefully also measure the resistance between those pins.
 

AlbertHall

Joined Jun 4, 2014
12,347
They all vary strangely.
I think that says it all - very strange.
5M good. <10k bad!

I built a board yesterday which had a short on the 5V. I started to remove components until the short went away. I checked that last component - no short - I checked the tracks - no short. I put the component back in the board and the short was back. Repeated the above remove-check-replace and all was well. No idea what was going on there o_O
 

Thread Starter

zaferaltun

Joined Aug 31, 2016
65
LoL! I suspected about the short abd did the almost same thing but no success yet. I will try to remove the mcu first, then measure again while it is pure. If still strange, replace the new one. If not, then there must be something short the circuit. Thanks for the tips, I could not thought to measure the resistances.

Best

I think that says it all - very strange.
5M good. <10k bad!

I built a board yesterday which had a short on the 5V. I started to remove components until the short went away. I checked that last component - no short - I checked the tracks - no short. I put the component back in the board and the short was back. Repeated the above remove-check-replace and all was well. No idea what was going on there o_O
 

Thread Starter

zaferaltun

Joined Aug 31, 2016
65
I removed the mcu but something was still shorting. I checked the leds with a battery and bingo! As I guess, they were shorting since bad smd soldering and GND zone issue. The mcu is healthy luckly!
 

dendad

Joined Feb 20, 2016
4,481
Checking the LEDs with a battery can kill them unless you have a series resistor.
Do you have the LEDs connected to +V via a resistor and the cathode of the LEDs to the port pins?
A circuit of your wiring could help.
It may be the ports are open collector so need the pullup to work. from memory, I think at least RA0 is.
 
Top