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.
I understand now why it is needed...

here is my way of disabling the interrupt.. it can be this way or it is not the right way?

PHP:
void interrupt timer0()
{
    
    
    if(T0IF == 1)
    {
        T0IF = 0;
        count++;
        if(count == 15)
        {
            RA2 ^= 1;  //toggle LED
            count = 0;
            
        }
        
    }
    PEIE = 0; // Disables all peripheral interrupts
}
 

yes. its correct, but when you use multiple interrupt then you have to disable only that interrupt.. and not others. so every ISR will disable itself before exiting ISR....
 

let say for example timer0.. I will only disable T0IE bit to specifically disable the interrupt of timer0.. am i right?
 

let say for example timer0.. I will only disable T0IE bit to specifically disable the interrupt of timer0.. am i right?


thanks.. just like what I did before in my 8051 projects.. thanks.. it helps a lot..

---------- Post added at 14:57 ---------- Previous post was at 14:44 ----------

tomorrow I will try timer0 using external clock and generate 1 sec delay..
 

Sir,
Now i am confused...
TIMER0 interrupt is working in hardware even PEIE=0;


:-?
 

Im also puzzled by my actual PIC hardware. it is very sensitive in power interruption.. unlike in my 8051 it works well even I intend to interrupt the power.. my power supply is regulated..

even when I clear the MCLR pin of my pic it will not reset and stop working after the power interruption.... the power interruption i am mentioning is when I turn and off the switch of my power source.

---------- Post added at 16:28 ---------- Previous post was at 16:23 ----------

I need to interrupt the VCC again to get it working.. it's weird.. Im pretty sure this issue has lot to do with the PIC.... i tried the normal delay without using the interrupt and this issue is not happening...
 

dear romel,

Its the problem of brownout reset or (BOR).. this cause sensitive to the circuit.. BOR resets the circuit if there is any variation in the supply pin.. so when you do the configuration at the beginning of the program you have to disable the BOR register and then start the main program....
 

Sir,
TIMER0 interrupt is working in
my hardware (PIC16F877A)even if i set PEIE=0. Why this is happening?
 

Im also puzzled by my actual PIC hardware. it is very sensitive in power interruption.. unlike in my 8051 it works well even I intend to interrupt the power.. my power supply is regulated..

even when I clear the MCLR pin of my pic it will not reset and stop working after the power interruption.... the power interruption i am mentioning is when I turn and off the switch of my power source.

Is this a PIC circuit you've construct yourself? Or is it a development board? If it is one you put together yourself, ensure you have a 100nF/.1µF capacitor across the Vdd and Vss as close to the PIC as possible, this alleviates some of the "sensitivity" you spoke of . Also make sure you have a pull-up resistor, 10KΩ, attached to MCLR pin, some diode protection won't hurt as well. See circuit diagram below:



These tips should help you with the "Reset" problems you are experiencing.

Ciao

---------- Post added at 18:21 ---------- Previous post was at 18:09 ----------

Sir,
TIMER0 interrupt is working in
my hardware (PIC16F877A)even if i set PEIE=0. Why this is happening?

Reference PIC16F87XA Datasheet, pg 24, 2.2.2.3 INTCON Register

Note: Interrupt flag bits are set when an interrupt
condition occurs regardless of the state of its
corresponding enable bit or the global
enable bit, GIE (INTCON<7>). User software
should ensure the appropriate interrupt flag
bits are clear prior to enabling an interrupt.
 

Yes i disabled the flag in ISR. But my problem is, timer0 interrupt is not depending on the PEIE , it occures even if PEIE=0.
 

Yes i disabled the flag in ISR. But my problem is, timer0 interrupt is not depending on the PEIE , it occures even if PEIE=0.

Correct. The Peripheral Interrupt Enable bit (PEIE) does not enable/disable TMR0 interrupts. However, the TMR0 Overflow Interrupt Enable bit (TMR0IE) in the INTCON Register does enable/disable TMR0 interrupts.

Reference PIC16F87XA Datasheet, pg 24, 2.2.2.3 INTCON Register
 
Last edited:
Correct. The Peripheral Interrupt Enable bit (PEIE) does not enable/disable TMR0 interrupts. However, the TMR0 Overflow Interrupt Enable bit (TMR0IE) in the INTCON Register does enable/disable TMR0 interrupts.

So you mean, if we never set the PEIE and we set only the TMR0IE and GIE, then also the timer0 interrupt occure as usual?
But what i learned is if we disable or clear the PEIE, then no peripheral interrupt will occure, even if their individual interrupt enable bit is set already....

Now totally confused...
 

The TMR0 interrupt is enable/disable solely by TMR0IE in the INTCON register, while both TMR2 and TMR3 interrupts are enable/disable by TMR1IE and TMR2IE respectfully in the PIE1 Register. All interrupt enable bits contained in the PIE1 and PIE2 are enable only if the PEIE bit, in the INTCON Register, is enable.

Reference PIC16F87XA Datasheet, pg 24, 2.2.2.3 INTCON Register and pg 25, REGISTER 2-4: PIE1 REGISTER

In short, the TMR0 interrupt is not included in the Peripheral Interrupt Register (PIE1 or PIE2), therefore Peripheral Interrupt Enable bit (PEIE) has not effect on TMR0 interrupts.

Hope this info clears things up for you.

---------- Post added at 19:41 ---------- Previous post was at 19:26 ----------



It has been said, "A picture is worth a thousand words."

So maybe, this diagram will help clear things up:




The state of the GIE bit effects all interrupts, while the state of PEIE bit effects only the interrupts shown on the left.
 
No problem.

Just for future reference, the diagram depiction of which interrupts will wake the MCU is incomplete and incorrect. Refer to the PIC16F87XA datasheet for more comprehensive and correct details.
 

Is this a PIC circuit you've
construct yourself? Or is it a
development board? If it is one
you put together yourself,
ensure you have a 100nF/.1µF
capacitor across the Vdd and Vss as close to the PIC as
possible, this alleviates some of
the "sensitivity" you spoke of .
Also make sure you have a pull-
up resistor, 10KΩ, attached to MCLR pin,

i have the 10k pull up in Mclr pin but dont have 100nf instead i attached 220uf.

By the way how to disable the B0R other than disabling it in the fuse bits setting?
 

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.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top