PIC16F1829 pins not working as GPIO, why?

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
rajat2905
Posts: 2
Joined: Wed Nov 22, 2017 8:00 pm

PIC16F1829 pins not working as GPIO, why?

Post by rajat2905 » Wed Nov 22, 2017 8:04 pm

this is my simple code which is failing:


/*
* File: newmain.c
* Author: Administrator
*
* Created on 22 November, 2017, 9:38 PM
*/

#include <stdio.h>
#include <stdlib.h>

// PIC16F1829 Configuration Bit Settings

// 'C' source line config statements

#include <xc.h>

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)

// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)

/*
*
*/
int main(int argc, char** argv) {
ANSELB=0x00;
ANSELC=0x00;
TRISB=0x00;
TRISC=0x00;
while(1){
LATB=~LATB;
}
return (EXIT_SUCCESS);
}

output:
RB6= 0 to 2.0V
RC6 = 0.5 to 1V (even when i am not toggling PORTC)
RB5 = 0 to 3.3 V but with delay and fluctuations
RB7 = 0.1 to 2.0 V
RB4 = 0 to 3.3V perfect

i have a doubt that all these pins are related to MSSP 1 and MSSP2 ports somehow? so why these are not behaving as a normal GPIO?
i have tried the PIC16F1829 on general purpose pcb and three different pcb boards but the result is same. Plz help!!

User avatar
phalanx
Non-SFE Guru
Posts: 1972
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: PIC16F1829 pins not working as GPIO, why?

Post by phalanx » Thu Nov 23, 2017 6:47 pm

The default clock speed for the internal oscillator is 500KHz which works out a 125KHz instruction rate. There is no delay in your while loop to slow down the toggling of your LATB register so including the while loop overhead, you are probably togging the pins somewhere around 60Khz. This is too fast for a typical multimeter to measure peak voltages and would be flicker free to your eyes if controlling an LED. I would suggest putting a delay routine in your while() loop to slow things down to human perceivable rates and measure again.

Also, what does "general purpose pcb" mean? Show us a schematic because anything connected to those pins could potentially affect them.

-Bill

rajat2905
Posts: 2
Joined: Wed Nov 22, 2017 8:00 pm

Re: PIC16F1829 pins not working as GPIO, why?

Post by rajat2905 » Sat Nov 25, 2017 1:49 am

i have put the 50 ms delay in toggling. but the strange thing i am observing is when i configure RB5 of pic15f1829 as an input, RB6,RB7,RC6,RC7 stop toggling. they become constant. why?

User avatar
phalanx
Non-SFE Guru
Posts: 1972
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: PIC16F1829 pins not working as GPIO, why?

Post by phalanx » Sat Nov 25, 2017 7:52 am

There is no inherent reason that I'm aware of that would cause your problem. Post your current code so we can take a look.

In the mean time in your configuration bits, turn off LVP, PLLEN, FCMEN, IESO, and BOREN.

-Bill

Post Reply