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.

Polling input for continous 50hz signal ?

Status
Not open for further replies.
Change interrupt is enabled for all RB4 - RB7 pins configured as input.
 

If you have 2 Ext INT pins like INT0 and INT1 then connect them to phase 1 and phase 2 and connect output of OR gate to any pin from RB4 to RB7. I hope your PIC has INT0 and INT1.
 
  • Like
Reactions: asking

    asking

    Points: 2
    Helpful Answer Positive Rating
Change interrupt is enabled for all RB4 - RB7 pins configured as input.

But how i will detect ? on which RB4,RB5,RB6 or RB7 gets interrupt detected or not ? how to individually check the state ?
 

But how i will detect ? on which RB4,RB5,RB6 or RB7 gets interrupt detected or not ? how to individually check the state ?

Generally speaking, you have bit operators available for this purpose.

The discussion is a bit confused because different methods (RB change interrupt, external interrupt, external INT with additional logic) are discussed concurrently. I believe that 50 Hz is slow enough to use the RB change interupt without external logic or INTx. But this is completely up to you.
 

FvM is quite correct - this is a very confused thread.
First - you are using the words "polling" and "interrupts" -you will want to do one or the other.
Second - you have not defined exactly what you want to test for - there are comments here for 50% duty cycle 50 hz signal interspersed with PWM
and the topic also suggest you just want to know if its on or off but is that really all?

I would suggest you define what you need along the lines below then you might find help is clearer for us to offer:

1. If you have a signal that is either on or off but just happens to be 50hz and you want to know if its on or off - that is very easy to do with a simple pin/port change interrupt
2. If you want to actually verify that an input PWM signal is currently 50% 50Hz then thats a good deal more complicated and you need detailed specific help judging from responses here
3. If you want to just verify an incoming fixed 50Hz signal is actually a 50hz square wave at a particular moment thats a little easier than 2 and trickier than 1 but still you need to say
4. something else entirely - explain exactly

If you can define your problems better this will always help others to help you.
jack

- - - Updated - - -

OK having spotted your explanation on the mikroe web site I know understand better what you are trying to do.

You are using a TSOP1838 and trying to determine whether an IR beam has been broken or not.
You have 2 of these hence you cannot work out how to work with 2 pins at once.



Firstly forget all about 50Hz frequencies. The TSOP1838 demodulates the signal for you - see data sheet with example circuit here
https://uk.farnell.com/vishay/tsop4...8&whydiditmatch=rel_2&matchedProduct=TSOP1838

Second - you are indeed confused about interrupts and polling - something I think I warned about as starting to happen elsewhere
You are not polling - you are using interrupts - attempting to "poll an interrupt at 50hz" is a fun idea but as you can see - confusing.

Your solution is to drop the external AND gate - you dont need it.
Stop using timers - you dont need them.

Then perform a simple interrupt on change on 2 pins.
from the pic16F628A datasheet :
Four of PORTB’s pins, RB<7:4>, have an interrupt-onchange
feature. Only pins configured as inputs can
cause this interrupt to occur.

You configure the port as an input set for interrupt on change and connect your 2 input lines.
You write your interrupt() to dissable interrupts
test which line interrupted and process accordingly
then re-enable interrupts
There are many examples of how to do this with mikroe-c floating about. Its a fairly standard process.
Your IR detecter will simply change its logic state when the beam is broken - the pick will notice the change and interrupt for you.
Try to understand the difference between polling and interupts.

Hope that helps
jack

PS. Incidently I'm not convinced the device you are using is what I would choose for this application - I dont have time to read closer but it may operate only in burst mode - thereby
possibly giving you false triggers. Check this.
 
Last edited:

Dear 123Jack,

I have read the Datasheet of TSOP1838 completely and i know how it works. Just FYI. it is clearly mentioned that if direct signal of 38KHZ is imposed on TSOP1838 it will filter it out as noise and will not detect. It is written it should have some 15-90msec burst. So what i have done is very simple. I have start PWM for 5ms and stop PWM for 15 ms. So then i was getting output of 50HZ on the output pin of TSOP1838. Now my output on TSOP is PWM pulse. So directly dealing with interrupt on change would not help me as its hard for me to code it. So its very simple . What i did is... i have run the timer for 22ms and used interrupt on RB0/INT so every time the pulse comes the RB0 interrupt reset the timer from being overflow. And when someone breaks the beam time is increased and hence @ 22ms the timer overflows and gives indication. This is ok for me. But situation for me is very simple i don't understand my english is bad or i am not able to explain my dear friends regarding the problem

Problem is :-
I need to use 2 IR Tx/Rx Pairs to count the no. of people in and out. So there is only one pair ready for now. What about 2nd pair ? as there is only 1 RB0/INT so what i did is simply... multiplexed 2 signals using AND Gate and output to RB0/INT parallel connections to two inputs detecting which has interrupt signal.

Now i came to learn more about Interrupt on change but i don't know why its not working with me.

i need to test interrupt on change with just push button and led on/off but for my code below its not working please help me with this and i would be able to complete my project with help of all of your efforts.

Code:
unsigned char x;

// Interrupt Handler
void interrupt()
{
  // RB Port Change Interrupt
  if(PIR1.RBIF == 1)   // if the RB Port Change Interrupt flag is set...
  {
    PORTA.F1 = ~PORTA.F1;//LED on/off on press of switch 
    x = PORTB;      // Need to read or write to the port to clear mismatch condition
    PIR1.RBIF =0;
  }

}
// code starts here...
void main()
{
TRISA = 0b00000000;
TRISB = 0b00100000; //RB5 defined as input and push switch connected to it

  // Set Interrupt Enable bits
  INTCON.RBIE = 1;    // bit 3 RB Port Change Interrupt Enable

  //Set global Interrupt Enable bits
  INTCON.GIE = 1;     // global interrput enable

  while(1)  //endless loop
  {
  }
}
 

See if you need to enable INTCON.PEIE. Use INT0 and INT1 for phase 1 and phase 2 and RBIF for OR of phase 1 and phase 2.
 

Attachments

  • RBIF.rar
    35.9 KB · Views: 85
Last edited:

See if you need to enable INTCON.PEIE. Use INT0 and INT1 for phase 1 and phase 2 and RBIF for OR of phase 1 and phase 2.

Yes boss,

The above code i gave also works just like same. But after the led is on after pressing switch its not going to off when pressed once again....why RBIF is not clearing ? even though i have READ PortB ? and also RBIF = 0; ?

any hint ?
 

As you are using mikroC ask your question in mikroe forum.

He has done - which is where I read his full explanation.

asking - what you are doing is turning a very simple process into an extremely complicated one for no
apparent reason. You are just making life difficult for yourself.

Reading your message above it appears what you are doing is suffering from 50Hz noise.
Before you even think of doing anything else you need to eliminate that or nothing you ever do
will work reliably.
 
  • Like
Reactions: asking

    asking

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top