CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PORT RB3 Not Working as a Digital I/O Pin

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mcmsat



Joined: 25 May 2018
Posts: 51
Location: Nigeria

View user's profile Send private message

PORT RB3 Not Working as a Digital I/O Pin
PostPosted: Mon May 20, 2019 6:40 pm     Reply with quote

Hello, I am experimenting with PICs as a form of learning as beginner, I ran into problem using RB3 pin on PIC16F886! The function on PIN_B3 does not function! Is there any setting I am missing. If I transfer the function to another pin it works there. Please I want to know why RB3 is behaving this way. Below is my code:

Code:
#include <16F886.h>
#device ADC = 10
#FUSES NOWDT, INTRC_IO, PUT, NOPROTECT, NOMCLR, NOCPD, NOBROWNOUT,NOIESO, FCMEN,

#use delay(clock = 8000000)

#define HIGH_START 0xFF -250 //500us INT_RTCC


#define SYS       PIN_B2
#define MAINS_ON  PIN_B3
#define RL1       PIN_C0
#define MOK       PIN_B0

short DL2_5s,SDL2_5s;

long MS,CDL2_5s,Counter_sys_1s;

 
void init()                                  // Hardware initialization
{
  setup_oscillator(OSC_8MHZ | OSC_INTRC);
  setup_adc(ADC_CLOCK_DIV_8);                // 8Tosc ADC conversion time
  setup_adc_ports(sAN11);                 // Select Analog Inputs
  setup_comparator(NC_NC_NC_NC);         // disable comparator module

 
  SDL2_5s=false; 
  DL2_5s=false; 


  set_rtcc(HIGH_START);
  setup_counters(RTCC_INTERNAL, RTCC_DIV_4);
  enable_interrupts(INT_RTCC);
  enable_interrupts(global);   

}

//   the timer is incremented (8000000/4)/4 or 500000 times a sond (2 us).
//   250 x 2us = 500us

#INT_RTCC
void clock_isr()
  { 
   

    {

     
if (SDL2_5s)
        {
        if (++CDL2_5s>=(5000*2))
            {
             SDL2_5s=false;
             DL2_5s=true;
            }
        }
      else CDL2_5s=0;
}                     


{   
if (++Counter_SYS_1s>=(1000*2))
            {
            Counter_sys_1s=0;
            output_toggle(SYS);
            }
}

    }

 void main (void)
{
   init();                           // Configure peripherals/hardware
   



 while(1)
 {

/////////Mains Settings/////////Mains Settings/////////Mains Settings/////////

{
  set_adc_channel(11);               // Select channel AN11
  delay_ms(1);                       // Wait 1ms
  MS = read_adc();                   // Read from AN11 and  store in MS
  delay_ms(1);                       // Wait 1ms
   
if(MS >= 84 && MS <= 177) // >= 0.410V && <= 0.864V //  >= 140V & <=250V


{
   
      SDL2_5s=true; // 15 seconds delay before Mains Changeover
      if(DL2_5s)               
     {
     output_high(MAINS_ON);
     DL2_5s=false;
     }
}     
      else SDL2_5s=false;
 
if(MS <= 53 || MS >= 258)// <= 0.260V || >=1.26V// Below <= 120V and >= 276V
 
      {
      output_low(MAINS_ON);// Mains is not within usable range
      }
     
}
if (input_state(MOK)==1)

{
     output_low(RL1);
}

if (input_state(MOK)==0)
{
     output_high(RL1);
}

 }
}


 
 

_________________
All is well even in the well!
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon May 20, 2019 7:53 pm     Reply with quote

Since you say your program works using other pins,
start with a basic '1Hz LED' program.
Does it turn RB3 On/off at about 1 HZ ?
I suspect you may have a hardware problem. A shorted pin, a grounded pin.
now as I type... I believe that pin is also used for Low Voltage Programming. Be sure that the NOLVP fuse is enabled.

Jay
mcmsat



Joined: 25 May 2018
Posts: 51
Location: Nigeria

View user's profile Send private message

Re: PORT RB3 Not Working as a Digital I/O Pin
PostPosted: Tue May 21, 2019 1:17 am     Reply with quote

Code:
{   
if (++Counter_SYS_1s>=(1000*2))
            {
            Counter_sys_1s=0;
            output_toggle(SYS);
            }
}


As you can see, in my program, "SYS" LED flashes at 1 second using interrupt. It toggles correctly on any other pin but once ported to RB3, it will start to misbehave.

I'm suspecting, in the datasheet they say that Interrupt-on-change is associated with the PORTB. Please how can I go about it if it's the cause of the problem because one may run out of pins at times and may need to utilize every damn pin on the device.
_________________
All is well even in the well!
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue May 21, 2019 1:47 am     Reply with quote

No, Interrupt on change is not your issue.

As Temtronic says, add NOLVP to your fuses. If LVP is enabled, this pin
is the PGM enable, and won't work for standard I/O.

IOC applies to RB3 to RB7, and does nothing unless enabled.

If NOLVP doesn't fix it, as Temtronic says, honestly it sounds like you
either have a pin that is shorted or a faulty PIC.

Assuming the chip is socketed, take it out, and try pulling the pin up/down
with a resistor. If it doesn't merrily go up/down, you have found your
problem (a short somewhere...).
mcmsat



Joined: 25 May 2018
Posts: 51
Location: Nigeria

View user's profile Send private message

Re: PORT RB3 Not Working as a Digital I/O Pin
PostPosted: Tue May 21, 2019 2:26 am     Reply with quote

It is not a hardware issue. Maybe someone has not run into something like this. I have 10pcs of this device. I interchanged the Pins.

Code:

#define SYS       PIN_B2
#define MAINS_ON  PIN_B3
#define RL1       PIN_C0
#define MOK       PIN_B0

 setup_adc_ports(sAN11);                 // Select Analog Inputs

 


I changed the above to:

Code:

#define SYS       PIN_B2
#define MAINS_ON  PIN_B5
#define RL1       PIN_C0
#define MOK       PIN_B4

setup_adc_ports(sAN9);                 // Select Analog Inputs


Using it as ADC, it works but I have to rewire the board.

I know this forum rules but allow me to add this please. due to this hardware issue mentioned here, I built the circuit in Proteus Isis and simulated it and it is exactly what I experience on hardware. I am not still satisfied as why I can't use "RB3" as digital I/O pin.
_________________
All is well even in the well!
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue May 21, 2019 4:23 am     Reply with quote

We need to see your #fuses. Also how are you programming the PIC ? Which software and hardware are you using ?
Most programming devices use high voltage NOT low voltage but it is possible the unit you have is an LVP device.
BTW I've got 2 16F886 running the 1Hz LED on my bench. I used CCS PCM > MPLAB 8.92 > PICKit3.
mcmsat



Joined: 25 May 2018
Posts: 51
Location: Nigeria

View user's profile Send private message

Re: PORT RB3 Not Working as a Digital I/O Pin
PostPosted: Tue May 21, 2019 4:41 am     Reply with quote

My FUSES:
Code:
#FUSES NOWDT, INTRC_IO, PUT, NOPROTECT, NOMCLR, NOCPD, NOBROWNOUT,NOIESO, FCMEN,
#FUSES NOLVP


I use PCWHD 4.140 and Pickit3 and MPLAB IPE 4.15
_________________
All is well even in the well!
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue May 21, 2019 4:47 am     Reply with quote

Cut code to flash an LED on the RB3 pin.
Test and post that program if it doesn't work.
Providing there's no code issues, then it's a HW issue.
Jay
mcmsat



Joined: 25 May 2018
Posts: 51
Location: Nigeria

View user's profile Send private message

Re: PORT RB3 Not Working as a Digital I/O Pin
PostPosted: Tue May 21, 2019 5:03 am     Reply with quote

It Blinks the LED.


Code:
#include <16F886.h>
#device ADC = 10
#FUSES NOWDT, INTRC_IO, PUT, NOPROTECT, NOMCLR, NOCPD, NOBROWNOUT,NOIESO, FCMEN,
#FUSES NOLVP, NOWRT,
#use delay(clock = 8000000)



#define SYS       PIN_B3

 

 void main (void)
{

 while(1)
 {
   {
   output_high(SYS);
   delay_ms(1000);
   }
   {
   output_low(SYS);
   delay_ms(1000);
   }


 }
}


but it fails for my full code!
_________________
All is well even in the well!
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Tue May 21, 2019 7:01 am     Reply with quote

I think there is a problem with PIN B3 not getting its analog operation turned off and your toggle command for PIN B2 is continually resetting the state of PIN B3.
You appear to have ADC and Comparator set correctly so there may be a bug in your compiler version. Check the listing and see what ANSELH is getting set to.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group