[SOLVED] PIC complete discussion for all

Status
Not open for further replies.
yes, im using the gogolium ebook for learning. Its very detailed tut.
Im using pic16f628..
i will try the hardware side because i already disabled the BOr as you said.

Its 3am here im still in my bed maybe i will try that later.
 

I'm starting to doubt how "regulated" your regulated power supply is actually. I would suggest adding the diode, any common 1N400X series or similar device, as the schematic shows. Also, you might add another 100nF/.1µF capacitor from the MCLR pin to Vss with a 470Ω inline and directly attached to the MCLR. The resulting RC configuration will slow the rise time after powerup and should add stability to the pull up condition.

Hope the suggestion help, please let me know if they do.

Ciao
 
yes. I will follow that. Anyway My regulated power supply is made up of lm7809 then i have also along with the pic lm7805 in my experimentation breadboard..

Your suggestion is excellent it worked that before in my 8051 i did almost the same before. I'll let you know if it will work also in my pic device..


Thanks.
 

Here's Microchip's current recommendation for configuring the MCLR pin for stability, programming and ESD protection:



Very similar to my proposal.

Ciao
 

thanks for informing me this.. I check it in the include directory and it's all there.... thanks

---------- Post added at 02:01 ---------- Previous post was at 01:57 ----------

// Power up timer enable
#define PWRTEN 0x3FF7
#define PWRTDIS 0x3FFF

by the way what do you mean by power up timer? it will delay the up time if enable?

---------- Post added at 02:09 ---------- Previous post was at 02:01 ----------

ah okay... I knew now the function of POWER on reset.. the goglium ebooks are great!! the best I ever have.. thanks

**broken link removed**

---------- Post added at 02:10 ---------- Previous post was at 02:09 ----------

the POWER ON reset is currently disabled in my configuration.. I will try that first before going to hardware.. I think this will solve my problem..
 
the POWER ON reset is currently disabled in my configuration.. I will try that first before going to hardware.. I think this will solve my problem..

Yes, that definitely could be your problem and it would explain several of the problems you have described.

Ciao
 
I did the hardware and the software but it still the same.

IF I create a simple blinking lead without using interrupt is normal and the PIC is not sensitive.. I dont understand this..

---------- Post added at 13:45 ---------- Previous post was at 12:07 ----------

I figured out the problem now.. the interrupt is working well when I use PORTB to blink a LED .. why?

blinking of LED in PORTA is happening during simulation but in real hardware it's not.. why?
 

Sorry for delayed answer....

usually the interrupts are not adviced to be used on the PORTA of PIC controllers..
Each PORTB pin has a weak internal pull-up resistor (resistor which defines a line to logic one) which can be activated by resetting the seventh bit RBPU in OPTION register. These 'pull-up' resistors are automatically being turned off when port pin is configured as an output. When a microcontroller is started, pull-ups are disabled.

Four pins PORTB, RB7:RB4 can cause an interrupt which occurs when their status changes from logical one into logical zero and opposite. Only pins configured as input can cause this interrupt to occur (if any RB7:RB4 pin is configured as an output, an interrupt won't be generated at the change of status.) This interrupt option along with internal pull-up resistors makes it easier to solve common problems we find in practice like for instance that of matrix keyboard. If rows on the keyboard are connected to these pins, each push on a key will then cause an interrupt. A microcontroller will determine which key is at hand while processing an interrupt It is not recommended to refer to port B at the same time that interrupt is being processed.

Also see if you have 10k pull up resistor for all the port pins on the hardware........
 
I dont understand this.. I programmed my PIC 400 times

when the code is like this..
simultion : working

real hardware: not working

T0IF cause the trouble

PHP:
char count;

void interrupt timer0_isr(void)
{
	
	count++;
	if(count == 16) // 16 for 1 second
	{

		PORTB++;	// effect a change on PORTB
		count = 0;
		
	}
      T0IF = 0;  // 
}

and if the code is like this

simulation : working
real hadware: working

T0IF fixed the issue but the delay is not 1 second

PHP:
char count;

void interrupt timer0_isr(void)
{
	
	count++;
	if(count == 16) // 16 for 1 second
	{

		PORTB++;	// effect a change on PORTB
		count = 0;
		T0IF = 0;  //disable timer interrupt
	}

}


---------- Post added at 15:27 ---------- Previous post was at 15:26 ----------

delay is not 1 second.. its very fast

---------- Post added at 16:58 ---------- Previous post was at 15:27 ----------

I copied all the sample codes in may e books, web tutorial but all were not working if i will clear T0IF.. it's weird

---------- Post added at 17:24 ---------- Previous post was at 16:58 ----------

I think something wrong with the hardware.. I dont believe this.. I tried all the possible solution but still no luck..


take a look this example.. this is working in simulator but in realhardware it's not..

only RB0 blinks here but RB1 is not blinking..

im trying to increment count variable count here but its only working in simulation not in real hardware...

PHP:
#include<htc.h>


__CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_ON & MCLRE_ON & BOREN_OFF & CP_OFF);

int count;

void interrupt timer0_isr(void)
{

  
   	T0IF = 0;
	count= count+1;

	
	PORTB ^= 1;

	
    
 
} 

void main()
{

	
	OPTION_REG = 0b0111;	// prescale by 256
	T0CS = 0;			// select internal clock
	T0IE = 1;			// enable timer interrupt
	GIE = 1;			// enable global interrupts
	TRISB = 0b00000000;			// output changes on LED		// Global interrupt enable
	while(1)
	{
		if(count == 5)
		{
			count = 0;
			RB1 ^= 1;
		}	
	}
	
}


---------- Post added at 17:28 ---------- Previous post was at 17:24 ----------

something wrong with the hardware?
 

romel please checkk the following and tell us....

1. is there 10K pull up for all the port pins.
2. Measure all the port pins or pull up and see if they all measure 10k or any pull up is damaged.
3. change the controller and test it.
4. what is the voltage and current rating of the power supply used.
 

1. is there 10K pull up for all the port pins.

I only put 1 pull up because i just specifically triggered 1 bit/PIN just to blink a led.. I think it's not necessary to have pull ups to other pins that are not used..
I also tried to use other PIN but still the same

2. Measure all the port pins or pull up and see if they all measure 10k or any pull up is damaged.
my 10K is okay. I change pull ups many times.. maybe I should try timer 1 and see the result

3. change the controller and test it.
as of now I have only 1 PIC all others are 8051. I will try to get 1.

4. what is the voltage and current rating of the power supply used.
my breadbord has a Lm7805 inbuilt and the current rating of my power supply is 200ma transformer.(I dont know how much current is flowing to the controller. )
 

try changing the power supply to min 500mA. But thats not a problem i feel... its hardware problem for sure.... check the oscillator oscillation and its value in frequency...
 

something like this.. I want to know what is your opinion about the problem of this.


This is working in real hardware.. it blinks RB0
PHP:
void interrupt timer_isr()
{
   T0IF = 0;
    PORTB ^= 1;

}


but this.. it will stop working.. I dont know what's the reason..

PHP:
void interrupt timer_isr()
{
   T0IF = 0;

    count++;
   if(count == 2)
  {
    
     count = 0;
     PORTB ^= 1;
 }

}


---------- Post added at 18:27 ---------- Previous post was at 18:26 ----------

try changing the power supply to min 500mA. But thats not a problem i feel... its hardware problem for sure.... check the oscillator oscillation and its value in frequency...

Im using internal clock of the PIC.. maybe I will try using external crystal..
 

another example.. it should increment count and if == to 2 RB1 must blink.. again working fine in simulator but in real hardware it's not

PHP:
int count = 0;
void interrupt timer_isr()
{
   T0IF = 0;
   count++;
}

void main()
{
  TRISB = 0b00000000;
 while(1)
 {
    if(count == 2)
    {
       count = 0;
       RB1 ^= 1;
    }
 }

}


---------- Post added at 18:43 ---------- Previous post was at 18:43 ----------

what is the initial value of count?

count is initialize from 0.

int count = 0;
 

I figured out the problem now.. the interrupt is working well when I use PORTB to blink a LED .. why?

blinking of LED in PORTA is happening during simulation but in real hardware it's not.. why?

Reference PIC16F62X Datasheet, pg 29, 5.1 PORTA and TRISA Registers




When using PORTA, have you disabled the comparators, so that the PORTA pins can be used as outputs?

Code:
CMCON = 0x07;
TRISA  = 0x00;

Reference PIC16F62X Datasheet, pg 29, 5.1 PORTA and TRISA Registers



RA5 is input only and RA4 has an open drain output, so if used as an output pin it must have a pullup resistor.
 
Last edited:
PIC is very complicated... you cannot use other ports right away.. :-?

@bigdogguro


**broken link removed**


When using PORTA, have you disabled the comparators, so that the PORTA pins can be used as outputs?

CMCON = 0x07;
TRISA = 0x00;


you said we need to set CMCON = 111 / CMCON = 0x07
I dont understand the above schematic.. when we select CMCON = 111,, RA0 to RA3 will be internally interconnected and reads as zero? so when that PINs reads as zero it means output. right?

that is how we set that ports to become outputs?




**broken link removed**
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…