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.

[Moved] Can I enable both TMR0 and RB change interrupts at the same time?

Status
Not open for further replies.

min2max

Advanced Member level 4
Joined
Jul 12, 2011
Messages
104
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,308
Location
China
Activity points
2,209
Hello guys,

I find difficulty handling the TMR0 and RB change interrupts at the same time with a PIC16F877A.

I'm making a LED grid clock with IR remote control. I put the LED scan routine in the TMR0 ISR to get a constant scanning rate. At the mean time, I connect the signal pin of a HS0038B (IR decoder) to RB6 and try to figure out the timing of the remote controller's signal in the corresponding RB<7:4> change ISR.

I'm not able to decode the signal because the timing of the decoded signal series is never in compliance with the protocol. After long time of investigation, I've found the cause is probably the fact that GIE is reset automatically as soon as the ISR is invoked handling another interrupt (TMR0 in this case) which makes some change(s) of RB6 not properly detected and handled.

During the process of debug, it becomes clearer to me that I cannot enable both TMR0 and RB change interrupts at the same time. Is my understanding correct?
[More strictly speaking, I should say -
I can enable both TMR0 and RB change interrupts but I cannot handle both interrupts at the same time]

And does any guy have any suggestion on my project? My basic goal at the time being is to keep a constant refresh rate of LED grid and get the IR signal instantaneously decoded. If this goal cannot be achieved with this chip, which one do you recommend?

I'm coding in C with MPLAB and HI-TECH PIC C complier.

Thanks for any help.

Max
 
Last edited:

Re: Can I enable both TMR0 and RB change interrupts at the same time?

you cant use Both at same time.
Use CCP module to capture the IR code. PORTB interrupt will not give you exact values. It will give you timing of Low and High level of IR signal received by HS0038B . it is best for IR decoding.
 
  • Like
Reactions: min2max

    min2max

    Points: 2
    Helpful Answer Positive Rating
Re: Can I enable both TMR0 and RB change interrupts at the same time?

Thanks for your information.

I'd glad to know a better and more 'natural' way of IR decoding. But according to my understanding, the limitation of being able to handle ONE event at any certain time still exists - The Capture event is just another form of interrupt which can not be handled immediately by software (just as RB change interrupt) while TMR0 is being processed due to the 'single-threaded' nature of PIC (at least at the software/user side).

I'll definitely dive deeper on my own in this issue but still welcome any form of help/information. :)

Without this demand fully met, I have another question here needing help -

I want the PIC16F877A to play music with a beeper. This is also a timing critical task. What's the most appropriate resource I should use to achieve this goal in addition to the existing above mentioned features?

Thanks in advance.
 
Last edited:

Re: Can I enable both TMR0 and RB change interrupts at the same time?

After reading the Tips 'n Tricks (as follows), it's clearer to me that the Capture event (interrupt) also needs in-time, if not real-time, process - or any event may be lost.

Does that mean I should turn to more powerful PIC's with interrupt priority?

Snap1.png
 
Last edited:

Re: Can I enable both TMR0 and RB change interrupts at the same time?

It's seems like I've put this post in a sector of the forum which does not suits most inadvertently.

Could the forum admin please move this thread to a section you deem most appropriate, say "Microcontrollers"?

My apologies.

---------- Post added at 02:32 ---------- Previous post was at 02:13 ----------

After a little rethinking of this issue. I'm reaching an understanding slightly different to what I used to have.

Yes, the 'single-threaded' nature of PIC16Fxxx (at the software side) is not changeable. And during the process of handling TMR0 interrupt, such interrupt as either RB change or CCP is not able to be handled. But this does not necessarily mean, at least for this case, both TMR0 and CCP(Capture) interrupt cannot be adequately processed.

The reason here is, even though while handling TMR0 the interrupt response mechanism will be blocked for a while, the Capture even can still be recorded with CCPIF beening set and timer register being stored, by hardware at _real-time_. As soon as the ISR is available again, as the CCPIF is already set, another CCP interrupt will immediately be triggered and the stored time register values retrieved and processed. This will make on one hand the TMR0 event be processed at real-time and on the other hand the CCP event also handled in time, as long as the time period of TMR0 ISR does not span longer than the shortest interval of any contiguous CCP triggers.

I hope I've made it clear, and look forward to any comments/thoughts.
 
Last edited:

Even though there seems to be solution as mentioned above, I eventually changed my MCU from PIC16F877A to PIC18F4550 for the following reasons:

1. To make the TMR0 ISR so brief to meet the requirement of not spanning over two contiguous RB change events of the shortest time interval is not so trivial in my project;
2. That method is just theoretically feasible and hardly worth being adopted in real project as the correct capture of the signal's timing is obvious not easy, not robust and error-prone;
3. As suggested by taroot, I'll handle the IR stuff with a more natural way - CCP (Capture) module of PIC, which makes the interrupt priority a must-have.

I've found some code of IR decoding and will make it my starting point.

I'm still in need of suggestions on PIC's playing music in my project.

Thanks.
 

Re: Can I enable both TMR0 and RB change interrupts at the same time?

Here is a photo of my LED grid clock:
DSCN4413.jpg
 

Did you get UR decoder code. you can find some on MIKROE website. CCP is best option for IR decoding.
 
Last edited:
Thank you taroot for your kind information.

I've downloaded a complete set of IR decoder from somewhere (I forget). It works pretty well now.

Yes, CCP is almost just designed for such use cases.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top