Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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
 
I've jumped quite late into the discussion, so please refresh my memory. Are you using a PIC16F628 in your design?

By the way, one of the best online tutorials for Hi-Tech C compiler I've come across is:

**broken link removed**

They cover both the baseline and midrange PICs using both Assembly and Hi-Tech C. The each tutorial is in PDF form along with the source code.
All Gooligum tutorials are very professionally done and well thought out, very impressive considering they are free.

Let me know the PIC you are using in your designs and I'll download the datasheet.

---------- Post added at 23:19 ---------- Previous post was at 22:37 ----------

Disable Brown-Out Detection by adding the Configuration Register Macro just after htc.h include statement:

Code:
#include <htc.h>

__CONFIG(WDTE_OFF & HS & ....... & BOREN_OFF)

Be sure to use the correct and appropriate configuration mask definitions which are listed in the pic16f628.h found in the include directory in the Hi-Tech compiler directory.

Code:
#ifndef	_HTC_H_
#warning Header file pic16f628.h included directly. Use #include <htc.h> instead.
#endif

/* header file for the MICROCHIP PIC microcontroller
 *  16F628
 */


#ifndef __PIC16F628_H
#define __PIC16F628_H

//
// Configuration mask definitions
//


// Config Register: CONFIG
#define CONFIG               0x2007
// Oscillator Selection bits
// ER oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, Resistor on RA7/OSC1/CLKIN
#define FOSC_ERCLK           0xFFFF
// ER oscillator: I/O function on RA6/OSC2/CLKOUT pin, Resistor on RA7/OSC1/CLKIN
#define FOSC_ERIO            0xFFFE
// INTRC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
#define FOSC_INTOSCCLK       0xFFFD
// INTRC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
#define FOSC_INTOSCIO        0xFFFC
// EC: I/O function on RA6/OSC2/CLKOUT pin, CLKIN on RA7/OSC1/CLKIN
#define FOSC_ECIO            0xFFEF
// HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN
#define FOSC_HS              0xFFEE
// XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN
#define FOSC_XT              0xFFED
// LP oscillator: Low-power crystal on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN
#define FOSC_LP              0xFFEC
// Watchdog Timer Enable bit
// WDT enabled
#define WDTE_ON              0xFFFF
// WDT disabled
#define WDTE_OFF             0xFFFB
// Power-up Timer Enable bit
// PWRT disabled
#define PWRTE_OFF            0xFFFF
// PWRT enabled
#define PWRTE_ON             0xFFF7
// RA5/MCLR pin function select
// RA5/MCLR pin function is MCLR
#define MCLRE_ON             0xFFFF
// RA5/MCLR pin function is digital input, MCLR internally tied to VDD
#define MCLRE_OFF            0xFFDF
// Brown-out Reset Enable bit
// BOD Reset enabled
#define BOREN_ON             0xFFFF
// BOD Reset disabled
#define BOREN_OFF            0xFFBF
// Low-Voltage Programming Enable bit
// RB4/PGM pin has PGM function, low-voltage programming enabled
...
...
...
...

This is the preferable method rather than using a value such as 0x3F3, as it is much easier to set/unset the correct bits in the Configuration Register.

However, a brown-out condition occurring with such regularity is an indication of more serious problems which should be dealt with directly.

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 :D

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

Note 1:
On RESET, the TRISA register is set to all
inputs. The digital inputs are disabled and
the comparator inputs are forced to
ground to reduce current consumption.

2:
TRISA<6:7> is overridden by oscillator
configuration. When PORTA<6:7> is
overridden, the data reads ‘0’ and the
TRISA<6:7> bits are ignored.



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


PORTA is an 8-bit wide latch. RA4 is a Schmitt Trigger
input and an open drain output. Port RA4 is multiplexed
with the T0CKI clock input. RA5 is a Schmitt Trigger
input only and has no output drivers. All other RA port
pins have Schmitt Trigger input levels and full CMOS
output drivers. All pins have data direction bits (TRIS
registers) which can configure these pins as input or
output.

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top