Archives
-
Pic16f628a multiple interrupt issue
Hi,
I have two interrupts enabled in my program, one is a timer interrupt and the other is an interrupt-on-change. I have noticed that if an interrupt occurs during the service of the other interrupt (ie the timer occurring during IOC) the first interrupts(IOC) flag doesn’t get cleared. This results in the original interrupt being serviced twice:
1) The first interrupt is serviced but the interrupt flag not clearing
2) The second interrupt is serviced (and flag cleared)
3) The first interrupt is serviced again because the flag didn’t clear the first time (flag is cleared this time)
Can someone please help me with this issue.
Many Thanks.
The following is my code:
#include <htc.h>
#include <pic.h>
#include <pic16f62xa.h>
unsigned int counter = 0;
unsigned char result;
void interrupt Timer0_ISR(void)
{
if (T0IF) // timer interrupt flag set
{
counter++;
if (counter >= 50)
{
counter = 0;
}
TMR0 = 200;
T0IF=0; //Interrupt not cleared if IOC
}
if (RBIF) //IOC flag
{
result = PORTB;
RA0 =~ RA0;
RBIF=0; //Interrupt not cleared if TMR0 overflows
}
}
Init(void)
{
CMCON=0×07;
TRISB = 0xff;
TRISA = 0×00;
TMR0 = 200;
OPTION = 0×88;
INTCON = 0xa8;
// T0IE = 1;//enable TMR0 overflow interrupts
// GIE = 1; //enable Global interrupts
}
void main()
{
Init(); //Initialize the relevant registers
while(1) //Loop forever
{
}
}
Related Forum Messages
- Configure DMA interrupt properly
- Interrupt PIC16F877A
- Changing the prescaler is stopping my timer??
- UART 16f877a
- Can’t read value of PB7 more than once?
- 16F690 USART full buffer
- PIC10LF322 NCO doesn’t work with HFINTOSC
- Data table not working on 16F628A
- Problem with external interrupt on PIC24F08KA102
- MVision to mplab ide probleam????????????
- Timer 4 Interrupt
- CY FLAGE DECLARE IN C32 COMPILER IN MPLABIDE….
- Strange bug with a digital output on PIC16F1938
- PIC24FJ64GB004 -> Page erase erases 1024 instructions, not 512….
- Trouble with oscillator configuration bits on PIC18F24J50
- Setting outputs high
- WAke from Sleep via a CN interrupt on PortB
- RCON state after WDT reset on 18F14K50
- PIC24H SPI chip select go high too early
- ROTARY ENCODER THROW STEPPER MOTOR ROTATE
Hi, i'm generating a waveform using a DAC connected to the SPI bus of a PIC32. All works fine except the interrupt at the end of the tranfert of a block. The code is the following: void configPortB () { TRISB = 0x0000; // all as output AD1PCFG=0xFFFF; // all as digital port PORTB = 1; } void setDmaChannel0 () { DmaChnOpen( 0, 0, DMA_OPEN_AUTO); //DmaChnOpen( 0, 0, 0); ...Dear all, I am trying to design an interrupt for every rising edge that is given from a heartbeat pulse. I dont know if i am on the right track and also how to add more. I know i have to add Timer0 so that when RB0 generates an interrupt. then in the end i have to get the frequency from the period and display it on an LCD. any hel can be given please? my code is attached below. Thanks #include <htc.h> unsigned int counter; void interrupt isr(void) { if(INTF) ...Hey All, I am having a very strange situation occur. It appears as though when I have a prescaler set to 1:1 my timer functions properly, when I change the value to anything other than 1:1, the timer stops completely. I am stumped/frustrated . Here's my timer setup: T2CONbits.T32 = 0; //16 bit T2CONbits.TCS = 0; T2CONbits.TCKPS = 0b01; // 1:8 prescale ...Dear all, I tried some coding for transmitting and got a voltage return from my PIC, swinging between 1.25V to 1.16V and back. Do you think this is correct? my code is attached below. thanks #include <htc.h> //header file for Pic Micro #include <stdlib.h> __CONFIG (0x3F72); //configuration fuses PIC16F877 from software void init(void); void transmit(void); void main() { init(); transmit(); while(1); } void init() { unsigned int count; PORTC=0x00; TRISC=0xFF; TXSTA=0b001000110; RCSTA=0b10010110; SPBRG=0b01000000; INTCON=0b11000000; PIR1=0b00010000; PIE1=0x00; count=0; } void transmit() { while(1) { TXREG=0x00; PIE1=0x00; } ...[Helpful answer received] / [List Solutions Only] Hi All, I'm having an issue where i can't properly read the value of a push button from my PIC24FJ64GB004. basically I use the button to triggger INT0. when I've entered the function I try to read the status of the button but it seems that regrdless of the state of the button I'm stuck in the while loop: void button (void) // button is pushed and released{ //timer1 T1CONbits.TON = 0; T2CONbits.TON = 0; ...#include <htc.h> __CONFIG (WDTE_OFF, PWRTDIS, MCLRDIS); void main(void) { RCSTA = 0b10010000; // Set for N81 TXSTA = 0b00100100; // SPBRG = 23; // Set for 9600 baud SPBRGH = 23; // 9600 baud BRGH = 0; BRG16 = 0; ...I'm having trouble getting the NCO to use the high frequency internal oscillator (HFINTOSC). If I'm using FOSC as clock source it works fine but if I change to HFINTOSC I get a constant signal depending on polarity bit. I can't see something obvious that I'm doing wrong =/ #include "htc.h" __CONFIG(FOSC_INTOSC & WDTE_OFF & MCLRE_OFF & LVP_OFF); void main() { OSCCON = 0x70; TRISA = 0x08; ...Hi, I'm a relatively beginner with PICs but I have been able to successfully complete a few projects so far. I am using a data table like this: GetFractions addwf PCL,f dt d'0', d'6', d'12', d'19', d'25', d'31', d'37', d'44', d'50', d'56', d'62', d'69', d'75', d'81', d'87', d'94' I call the table like this: call GetFractions I have done similar things several times with no problem. ...Hi all, I'm having a big problem with my PIC24F08KA102's programmation. I'm trying to use one external interrupt. It's INT0 on pin 16, but with my code it doesn't work... I don't understand why because I put 3V on pin 16 and I haven't something... My PIC stays in the while loop... Can you help me, please? Best regards, Jean My code: (I'm using mplab X IDE v1.20 with compiler C30) #include <stdio.h> #include <stdlib.h> #include <ports.h> #include <p24F08KA102.h> #include "Compteur.h" #include ...hello friends, i use keil MVision ide 3 and my program is below : BDATA unsigned char StepperA ; sbit PBA0 = StepperA^0 ; sbit PBA1 = StepperA^1 ; sbit PBA2 = StepperA^2 ; sbit PBA3 = StepperA^3 ; sbit PBA4 = StepperA^4 ; sbit PBA5 = StepperA^5 ; sbit PBA6 = StepperA^6 ; sbit PBA7 = StepperA^7 ; and any function i use ...Hello, I configurated timer 4 to trigger a high level interrupt every 67us. This works fine. The problem is, if in the ISR is a lot to do (approx. 48us), the interrpt is not called every 67us anymore. It's the about 90us. In the oscillogram pin C3 is shown. Can anybody explain, why the interrupt isn't called every 67us permanently? Here is the initialisation: /* t = 1/16e6 * 2 * 134 * 4 = 67us */ T4CON = (BIT03 * 0b0001) ...HELLO FRIENDS I HAVE ONLY PROBLEM THAT HOW CAN I DECLARE ONLY "CY FLAG" IN C LANGUAGE. WHEN I USE IN ADDITION OR SHIFTING ANY PORT . SUPPOSE MY CODE IS. union{ struct{ unsigned Zero : 1 ; unsigned One : 1 ; unsigned Two : ...Hi, I have a very strange bug with the PIC16f4938. I just want to make a clock with the RA1 digital output. This is my code : #include <htc.h> #include <pic.h> #define _XTAL_FREQ 16000000 #define SCLK LATA1 void main(void) { init(); while(1) { __delay_us(200); SCLK=0; ...Can anyone confirm if this is true or not? As far as I can see it should be true only for the dsPIC33E and PIC24E devices. But each time that I delete a row, 0x400 of addresses gets erased instead of 0x200. I've verified this by writing predefined data (using RealICE) to PGM and after the erase readig the PGM back (using RealICE) This is how I do it: void FLASH_ErasePage(UINT32 addr) { WORD temp; temp = TBLPAG; ...0 Hi All, I'm attempting to use the PIC18F24J50 in a Project and will eventually add USB functionality. I am having trouble getting my clock speed to be fast enough. I am currently measuring 2MHz at CLKO. But I thought I would be expecting more like 8 or 12 or 16 MHz. Here are my config bits: #pragma config WDTEN = OFF #pragma config PLLDIV = 3 #pragma config STVREN = ON ...Hi, I am looking to generate a program which simply sets the RC0 pin of the 16F676 high, and I am wondering if someone can take a look at my program. Right now, the RC pins are at around 1.8V, I would expect them to all be at ground except RC0 which is high. I am unsure if I am utilizing the internal clock correctly. I am using Pickit 2 for programming and Hi Tech C v 9.81. Thanks very much. #include "htc.h" ...I can't seem to "get" what pin cause a CN event to wake my PIC24 up, in C30: The interrupt is fired i.e. the PIC is woken up, but this simple thing: EnableCN1; EnableCN11; // anche charger, 2012 IPC4bits.CNIP = 2; IEC1bits.CNIE = 1; oldPortB=PORTB; IFS1bits.CNIF = 0; // clear bit IRQ SERVE?? ...I'm a little confused about the state of RCON after a MCLR reset following a WDT reset. According to Table 23-3 in the datasheet, the TO bit in RCON should clear after the WDT reset but then set after a MCLR reset. This is not what I'm seeing. Below is a simplified example that exhibits the problem. I don't show the configuration bits, but the WDT is turned off and under software control. Upon a power-on reset, the code runs straight through to the end and sits in while-loop B until the WDT causes a reset. ...Hi all, i'm using microchip c30 SPI library to write simple string, my problem is the chip select signal go high too early, beafore transmit is completed. This is my code: CS_SD = 0; // chip select putsSPI1(5, (UINT*)"hello"); CS_SD = 1; and this is the result I alo try with this: _SPI1IF = 0; null = SPI1BUF; CS_SD = 0; // chip select putsSPI1(5, (UINT*)"hello"); while(!_SPI1IF); CS_SD = 1; ...[Helpful answer received] / [List Solutions Only] HELLO FRIENDS I AM USING PIC32MX575F256H AND I WANT TO ROTATE STEPPER MOTOR TO USE OF ROTARY ENCODER. AND MY CODE IS BELOW #INCLUDE<plib.h> TRISEBits.TRISE2 = 1 ; // make as a input for encoder TRISEBits.TRISE3 = 1 ; // make as a input for encoder #define mstepperAena() ...
