Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interrupt Not Working For RF Receiver

Status
Not open for further replies.
Hi,
I have an RF receiver which is 315MHz and i want to interface it with PIC (Without Encoder And Decoder IC I want to use External interrupt of PIC (18F452) @ 10Mhz .
The Problem Is Interrupt dose not trigger when i connect the Data out pin of the receiver module i used audacity to view the waveform (attached).
my question is is it possible for the PIC to handle interrupt at this frequency i imported audio file to proteus but its not working when i use clock signal from proteus it triggers but not on this signal i increased the amplitude to 5v but still no response kindly help.
Thanks in Advance Aaa.JPG
 
What voltage/current does the Data Out pin of the Rx module provide?
What is the data rate? Surely Audacity can't handle 10MHz?
What are the configuration settings of the PIC?
 
If you are attempting to get the data output from a device like this into an 18F452; then yes you should be able to.

The questions you have to address are:
1) What is the data rate?
2) Where is the data coming from? I presume here the data is coming from a transmitter similar to this. The first step would be to complete the setup without the wireless link. It is much easier to debug you code that way. This would tell you if the logic is correct, if the interrupt routing is correct, etc.
 
Thanks For Your Replies.
Actually transmitter is built with PT2264 and receiver has syn400R IC(Data Sheet Says 800bps 315MHz) 10uA push pull Data Out Pin i bought it from market with a remote having 4 buttons and separate receiver which has a gnd a vcc a shut and a data out pin.i tried to attach the pic but it failed i can attach it latter if you preffer.
when i connect DMM to Dataout Pin at idle it gives 2.7V approx and when i press any button from remote it goes down to 1.7v or below do i need to amplify the output?.
 
The SYN400R IC should be able to drive the 18F452 uC ok. It does require some configuration, but the question is whether it should be able to drive it; the answer is yes.

If you are having trouble getting the communication working, the best way to debug it is to remove the wireless portion. The PT2264 is an encoder IC, and you can definetly debug the link with a wire connected between this encoder IC and the 18F452 (who controls the receiver). That allows you to debug your algorithm. Once you have this working, move to the wireless portion. Of course, you can approach this as you think best.
 
when i connect DMM to Dataout Pin at idle it gives 2.7V approx and when i press any button from remote it goes down to 1.7v or below
If the output is rectangular pulses at 800bps your DMM will be reading an average voltage; so 2.7V may well be 0-5V peak-to-peak, with a duty cycle ~54%.
 
HI,
Thanks For The Great Idea yes interrupt triggers i first connected a wire to Output of Encoder and made it input to external interrupt of PIC and after many trials and errors i found that there is a delay of 14.5 ms between the repitition of same pulse for example if i keep press one key from remote there will be a pause of 14.5ms atleast before it resends the same code. so i decided to make this pause as a starting point of the code. in ISR i run a timer and measured the time of pause if it detects the pause lets say 28509 in my case(16MHz Prescale = 1:2) the i set a flag to decode the coming bit stream else ignore after detecting pause i measured the off time of pulses (Falling Edge Triggered Interrupt) and converted them to 1's and 0's depending on the timer value in may case (TMR>700&&TMR<1100) is a 0 (Range of a Short Pulse) and (TMR>2200&&TMR<2900) is a 1 i ignored the firs 16 bits because they are always same on each key press last Byte is changed so i got that byte and it is working good on a direct wire connection afterwards i moved to wireless section n i tried a lot but having trouble with it Interrupt is triggering but Result is not accurate sometimes it detects the code on first keypress without trouble and some times after many key presses or even holding the key i cant solve it i need it to be perfect and less error prone. one more thing 1 button is almost missed out of four my algo cant resolve that it is decoded sometimes but verry less than the other 3 kindly help,,,
I am Posting my code Sorry i dont have to much comments in code,,,,,,,

//************************************************//
#include<p18f452.h>
#include<delays.h>
#pragma config OSC=HS,WDT=OFF,LVP=OFF

#define DI PORTBbits.RB0

//*************************//
unsigned int TL,TH,TT,CNT=0,FLG_RF=0,FLG_RF_OK=0,C1=0,C0=0;
unsigned long int DATA=0,DATA_OLD=0;
int LENGTH=0; //Determines The Length Of The Char Array
char CHAR[] = "RF 315MHz";
//**************************************//
typedef struct
{ // bit field definition
//unsigned b0 : 1;
unsigned b1 : 1;
unsigned b2 : 1;
unsigned b3 : 1;
unsigned b4 : 1;
unsigned b5 : 1;
unsigned b6 : 1;
unsigned b7 : 1;
unsigned b8 : 1;
unsigned b9 : 1;
unsigned b10 : 1;
unsigned b11 : 1;
unsigned b12 : 1;
unsigned b13 : 1;
unsigned b14 : 1;
unsigned b15 : 1;
unsigned b16 : 1;
unsigned b17 : 1;
unsigned b18 : 1;
unsigned b19 : 1;
unsigned b20 : 1;
unsigned b21 : 1;
unsigned b22 : 1;
unsigned b23 : 1;
unsigned b24 : 1;
unsigned b25 : 1;
unsigned b26 : 1;
}bits;
bits bs;
//**************************************//
void Serial()
{
TXSTA=0b00100100; //BRGH = 1;
RCSTA=0b10000000;
SPBRG=103; //9600bps
}
//**************************************//
void Serial();
void TX_TEXTs(char CHAR[]);
void TX_Byte(long int);
void init(void);
void External_0();
void main()
{
init();
while(1)
{
if(FLG_RF_OK==1)
{
INTCONbits.GIE=0;
if(DATA_OLD==207)
{
PORTDbits.RD7=1;
}
if(DATA_OLD==252)
{
PORTDbits.RD6=1;
}
if(DATA_OLD==243)
{
PORTDbits.RD5=1;
}
if(DATA_OLD==63)
{
PORTDbits.RD4=1;
}
Delay10KTCYx(1);
FLG_RF_OK=0;
CNT=0;
INTCONbits.GIE=1;
}
} //while
}//main
//**************************************//
void init()
{

INTCONbits.GIE = 1; //Global Interrupt Enable
INTCONbits.PEIE = 1; //Peripheral Interrupt Enable
INTCONbits.INT0IE = 1; //External Interrupt 0 Enable
INTCONbits.INT0IF = 0; //External Interrupt Flag 0
INTCON2bits.INTEDG0=0; //Interrupt on Rising Edge

T0CON = 0b0000000;
INTCONbits.TMR0IF = 0; //Timer0 interrupt Flag

PORTBbits.RB0=0;
TRISBbits.TRISB0=1;
PORTCbits.RC6=0;
TRISCbits.TRISC6=0;
TRISC=0;
PORTC=0;
TRISD=0;
PORTD=0;
TMR0L=0;
TMR0H=0;

}
//**************************************//
//**************************************//
#pragma code HIGH_INTERRUPT_VECTOR = 0x08
void high_ISR (void)
{
_asm
goto External_0
_endasm
}
#pragma code
#pragma interrupt External_0
//**************************************//
void External_0()
{
INTCONbits.GIE=0;
T0CONbits.TMR0ON=1;
PORTCbits.RC0=1;
while(DI==0);
PORTCbits.RC0=0;
T0CONbits.TMR0ON=0;
TL = TMR0L;
TH = TMR0H;
TT = TMR0H*255 + TMR0L;

if(CNT==0)
{
if(TT>27500&&TT<32000)
{
FLG_RF=1;
CNT++;
}
}
if(FLG_RF==1&&CNT>0)
{

CNT--;
if(TT>700&&TT<1100)
{
switch(CNT)
{

case 17:bs.b17=0;break;
case 18:bs.b18=0;break;
case 19:bs.b19=0;break;
case 20:bs.b20=0;break;
case 21:bs.b21=0;break;
case 22:bs.b22=0;break;
case 23:bs.b23=0;break;
case 24:bs.b24=0;break;

C0++;
}

}

if(TT>2200&&TT<2900)
{
switch(CNT) //Because We Need Last 8 Bits Others Are Same
{

case 17:bs.b17=1;break;
case 18:bs.b18=1;break;
case 19:bs.b19=1;break;
case 20:bs.b20=1;break;
case 21:bs.b21=1;break;
case 22:bs.b22=1;break;
case 23:bs.b23=1;break;
case 24:bs.b24=1;break;

C1++;
}
}

if(CNT>24)
{
FLG_RF=0;
FLG_RF_OK=1;
DATA=DATA|bs.b24;
DATA=DATA<<1;
DATA=DATA|bs.b23;
DATA=DATA<<1;
DATA=DATA|bs.b22;
DATA=DATA<<1;
DATA=DATA|bs.b21;
DATA=DATA<<1;
DATA=DATA|bs.b20;
DATA=DATA<<1;
DATA=DATA|bs.b19;
DATA=DATA<<1;
DATA=DATA|bs.b18;
DATA=DATA<<1;
DATA=DATA|bs.b17;
DATA=DATA<<1;

DATA=DATA>>1; //Dropping Last Bit
DATA_OLD=DATA;
DATA=0;
}
CNT=CNT+2;
}
TMR0H=0;
TMR0L=0;
TL=0;
TH=0;
INTCONbits.INT0IF=0;
INTCONbits.GIE=1;
}
//**************************************//
void TX_TEXTs(char CHAR[])
{
LENGTH=0;
while(CHAR[LENGTH]!='\0')
{
TXREG = CHAR[LENGTH];
while(PIR1bits.TXIF!=1);
LENGTH++;
PIR1bits.TXIF=0;
Delay1KTCYx(20);
}
}
//**********************//
void TX_Byte(long int res)
{
int x1,x2,x3,x4,x5;
x1=res%10 +(48);
res=res/10;
//x2=res%10+(48);
//res=res/10;
//x3=res%10+(48);
//res=res/10;
//x4=res%10 +(48);
//res=res/10;
//x5=res%10 +(48);
//PIR1bits.TXIF=0;
//TXREG=x5;
//while(PIR1bits.TXIF!=1);
//PIR1bits.TXIF=0;
//Delay1KTCYx(50);
//TXREG=x4;
//while(PIR1bits.TXIF!=1);
//PIR1bits.TXIF=0;
//Delay1KTCYx(50);
//TXREG=x3;
//while(PIR1bits.TXIF!=1);
//PIR1bits.TXIF!=0;
//Delay1KTCYx(50);
//TXREG=x2;
//while(PIR1bits.TXIF!=1);
//PIR1bits.TXIF!=0;
//Delay1KTCYx(50);
//TXREG=x1;
while(PIR1bits.TXIF!=1);
PIR1bits.TXIF!=0;
Delay1KTCYx(50);
TXREG=13;
while(PIR1bits.TXIF!=1);
PIR1bits.TXIF=0;
}
//************************************************//
 
9600 is way to fast if your not using a incoder about 2400 baud is
It sending serial data
 
my pic is getting reset again and again when i connect rf sensor or serially transmit data i have tied MCLR pin to VDD via 10k even i applied direct VDD but still getting reset.what should be the reason please help...
 
Could be supply brown-out or supply noise, if you're driving Rx and PIC from a common supply with inadequate decoupling.
 
I re-formated your code so I could read it (hint, hint). I can't follow your logic on void External_0() routine.

I think while(DI==0); should be while(DI==1); .

I'm also struggling with the following. It looks like you're stuck in this loop.
Code:
	if(CNT==0)
	{
		if(TT>27500&&TT<32000)
		{
			FLG_RF=1;
			CNT++;
		}
	}
	if(FLG_RF==1&&CNT>0)
	{
		CNT--;
	...}

Anyways, I'm with alec_t; you may have a brownout condition. Or, judging by the size of your interrupt routine, a stack overflow. You can printout the STKPTR and RCON registers after your init() to verifiy the cause of a reset.


reformatted code
Code:
//************************************************//
#include<p18f452.h>
#include<delays.h>
#pragma config OSC=HS,WDT=OFF,LVP=OFF

#define DI PORTBbits.RB0

//*************************//
unsigned int TL,TH,TT,CNT=0,FLG_RF=0,FLG_RF_OK=0,C1=0,C0=0;
unsigned long int DATA=0,DATA_OLD=0;
int LENGTH=0; //Determines The Length Of The Char Array
char CHAR[] = "RF 315MHz";
//**************************************//
typedef struct
{ // bit field definition
	//unsigned b0 : 1;
	unsigned b1 : 1;
	unsigned b2 : 1;
	unsigned b3 : 1;
	unsigned b4 : 1;
	unsigned b5 : 1;
	unsigned b6 : 1;
	unsigned b7 : 1;
	unsigned b8 : 1;
	unsigned b9 : 1;
	unsigned b10 : 1;
	unsigned b11 : 1;
	unsigned b12 : 1;
	unsigned b13 : 1;
	unsigned b14 : 1;
	unsigned b15 : 1;
	unsigned b16 : 1;
	unsigned b17 : 1;
	unsigned b18 : 1;
	unsigned b19 : 1;
	unsigned b20 : 1;
	unsigned b21 : 1;
	unsigned b22 : 1;
	unsigned b23 : 1;
	unsigned b24 : 1;
	unsigned b25 : 1;
	unsigned b26 : 1;
	}bits;
bits bs;
//**************************************//
void Serial()
{
	TXSTA=0b00100100; //BRGH = 1;
	RCSTA=0b10000000;
	SPBRG=103; //9600bps
}
//**************************************//
void Serial();
void TX_TEXTs(char CHAR[]);
void TX_Byte(long int);
void init(void);
void External_0();
void main()
{
	init();
	while(1)
	{
		if(FLG_RF_OK==1)
		{
			INTCONbits.GIE=0;
			if(DATA_OLD==207)
			{
				PORTDbits.RD7=1;
			}
			if(DATA_OLD==252)
			{
				PORTDbits.RD6=1;
			}
			if(DATA_OLD==243)
			{
				PORTDbits.RD5=1;
			}
			if(DATA_OLD==63)
			{
				PORTDbits.RD4=1;
			}
			Delay10KTCYx(1);
			FLG_RF_OK=0;
			CNT=0;
			INTCONbits.GIE=1;
		}
	} //while
}//main
//**************************************//
void init()
{
	INTCONbits.GIE = 1; //Global Interrupt Enable
	INTCONbits.PEIE = 1; //Peripheral Interrupt Enable
	INTCONbits.INT0IE = 1; //External Interrupt 0 Enable
	INTCONbits.INT0IF = 0; //External Interrupt Flag 0
	INTCON2bits.INTEDG0=0; //Interrupt on Rising Edge

	T0CON = 0b0000000;
	INTCONbits.TMR0IF = 0; //Timer0 interrupt Flag

	PORTBbits.RB0=0;
	TRISBbits.TRISB0=1;
	PORTCbits.RC6=0;
	TRISCbits.TRISC6=0;
	TRISC=0;
	PORTC=0;
	TRISD=0;
	PORTD=0;
	TMR0L=0;
	TMR0H=0;
}
//**************************************//
//**************************************//
#pragma code HIGH_INTERRUPT_VECTOR = 0x08
void high_ISR (void)
{
	_asm
	goto External_0 
	_endasm
}
#pragma code
#pragma interrupt External_0
//**************************************//
void External_0()
{
	INTCONbits.GIE=0;
	T0CONbits.TMR0ON=1;
	PORTCbits.RC0=1;
	while(DI==0);
	PORTCbits.RC0=0;
	T0CONbits.TMR0ON=0;
	TL = TMR0L;
	TH = TMR0H;
	TT = TMR0H*255 + TMR0L;

	if(CNT==0)
	{
		if(TT>27500&&TT<32000)
		{
			FLG_RF=1;
			CNT++;
		}
	}
	if(FLG_RF==1&&CNT>0)
	{
		CNT--;
		if(TT>700&&TT<1100)
		{ 
			switch(CNT)
			{
				case 17:bs.b17=0;break;
				case 18:bs.b18=0;break;
				case 19:bs.b19=0;break;
				case 20:bs.b20=0;break;
				case 21:bs.b21=0;break;
				case 22:bs.b22=0;break;
				case 23:bs.b23=0;break;
				case 24:bs.b24=0;break;
				C0++;
			}
		}

		if(TT>2200&&TT<2900)
		{
			switch(CNT) //Because We Need Last 8 Bits Others Are Same
			{
				case 17:bs.b17=1;break;
				case 18:bs.b18=1;break;
				case 19:bs.b19=1;break;
				case 20:bs.b20=1;break;
				case 21:bs.b21=1;break;
				case 22:bs.b22=1;break;
				case 23:bs.b23=1;break;
				case 24:bs.b24=1;break;
				C1++;
			}
		}

		if(CNT>24)
		{
			FLG_RF=0;
			FLG_RF_OK=1;
			DATA=DATA|bs.b24;
			DATA=DATA<<1;
			DATA=DATA|bs.b23;
			DATA=DATA<<1;
			DATA=DATA|bs.b22;
			DATA=DATA<<1;
			DATA=DATA|bs.b21;
			DATA=DATA<<1;
			DATA=DATA|bs.b20;
			DATA=DATA<<1;
			DATA=DATA|bs.b19;
			DATA=DATA<<1;
			DATA=DATA|bs.b18;
			DATA=DATA<<1;
			DATA=DATA|bs.b17;
			DATA=DATA<<1;

			DATA=DATA>>1; //Dropping Last Bit
			DATA_OLD=DATA;
			DATA=0;
		}
		CNT=CNT+2;
	} 
	TMR0H=0;
	TMR0L=0;
	TL=0;
	TH=0;
	INTCONbits.INT0IF=0;
	INTCONbits.GIE=1;
}
//**************************************//
void TX_TEXTs(char CHAR[]) 
{ 
	LENGTH=0;
	while(CHAR[LENGTH]!='\0') 
	{ 
		TXREG = CHAR[LENGTH];
		while(PIR1bits.TXIF!=1);
		LENGTH++; 
		PIR1bits.TXIF=0;
		Delay1KTCYx(20); 
	}
}
//**********************//
void TX_Byte(long int res)
{
	int x1,x2,x3,x4,x5;
	x1=res%10 +(48);
	res=res/10;
	while(PIR1bits.TXIF!=1);
	PIR1bits.TXIF!=0;
	Delay1KTCYx(50);
	TXREG=13;
	while(PIR1bits.TXIF!=1);
	PIR1bits.TXIF=0; 
}
//************************************************//
 
Yes i am driving rx n pic from the same source it may not be the supply noise because i am using 12v lead acid battery n not using wall adapter it may be because of rf receiver what should i do for decoupling.
Thanks..
 
Void External_0()...is falling edge triggered n after interrupt occurs i am waiting for a pause of 14ms approx if its detected
Cnt variable is incremented n flag is set (i just realized that only flag is enough for telling that pause is detected) anyways after detection cnt incrementd n in next statement its decremented n after checking all conditions its double incremented so cnt is 2 now but on next falling edge it will be decremented first n then conditions will be checked n again double increment n goes on till 24 bits...
 
Thanks i will print those register tomorrow n will find the cause....
One more thing when i disconnect power n again connect then at first attempt my algo will detect the pressed key since i put it to infinite loop after detecting 1 key just fuor the sake of debugging but after 1 key if i reset my controller externally then it will show the same value for all keys even after reset the only soln is to remove power n again press the second key n then remove power n next key it seems like controller stores the previous key n on reset after detecting key it again shows the previous key...sounds stupid but its happening .....:(
 
Last edited:
What are the respective max currents drawn by the Rx and PIC?
 
I hav't checked for currents will try tomorow but do you think this could be the problem because my v regulator is not getting hot n battery is rated 1.2Ah?
 
Sorry, I went along with the comment on your code: "INTCON2bits.INTEDG0=0; //Interrupt on Rising Edge". That comment did not jive with a falling edge triggered interrupt.

I now see the CNT = CNT + 2 near the end.
 
I hav't checked for currents will try tomorow but do you think this could be the problem
I only asked about the currents in order to calculate minimum/optimum decoupling component values to try if you don't already have them. If the PIC is driving one or more loads then the load current will probably be the dominant factor.
Do you have decoupling caps (including the usual 100nF as close as possible to the PIC supply pins) in place?
Does the Vreg have the recommended caps at input and output?
Is the circuit built on a breadboard?
 
@languer yes actually i forgot to change the comment to falling edge i am working on falling edges .....
and i have 1000uf cap after regulation but no decoupling cap source is battery n total current consump is 50mA....(PCB)
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top