Editing A Tutorial on PIC interrupts using BoostC including Example Programs

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 123: Line 123:
 
[[Experimenting with IR Remotes using a PIC running BoostC Project]] to link to the whole project.
 
[[Experimenting with IR Remotes using a PIC running BoostC Project]] to link to the whole project.
  
=== The problem: ===
+
The problem:
  
 
An IR transmitter sends bursts of infra red to a receiver.  This receiver converts the IR to pulses which ( in the case we will consider the NEC protocol ) consists of about 70 transition over a period of time of about .1 seconds.  We want to measure these transitions and determine what button was pressed on the IR transmitter.  Note that the code here is a bit simplified, the better to show the essential ideas.  To make it work go to the project and get the full code.  Email me if you are having problems.
 
An IR transmitter sends bursts of infra red to a receiver.  This receiver converts the IR to pulses which ( in the case we will consider the NEC protocol ) consists of about 70 transition over a period of time of about .1 seconds.  We want to measure these transitions and determine what button was pressed on the IR transmitter.  Note that the code here is a bit simplified, the better to show the essential ideas.  To make it work go to the project and get the full code.  Email me if you are having problems.
  
=== Solution: ===
+
Solution:
  
 
The receive goes through several states all of which are interrupt driven.  
 
The receive goes through several states all of which are interrupt driven.  
Line 133: Line 133:
 
First we need to wait for a quiet time in the IR signal.  To do this we set two interrupts one on timer1 and one on the IR signal.  If the IR signal is quiet then the timer1 interrupt will go off first and we are ready to receive, if the timer goes off first then the IR signal is not quiet.  We track all of this with a state variable IRState = IRSTATE_WAIT while we are waiting, and  IRState = IRSTATE_BUSY    IRState = IRSTATE_READY  if the IR was quiet and we are now ready to receive.
 
First we need to wait for a quiet time in the IR signal.  To do this we set two interrupts one on timer1 and one on the IR signal.  If the IR signal is quiet then the timer1 interrupt will go off first and we are ready to receive, if the timer goes off first then the IR signal is not quiet.  We track all of this with a state variable IRState = IRSTATE_WAIT while we are waiting, and  IRState = IRSTATE_BUSY    IRState = IRSTATE_READY  if the IR was quiet and we are now ready to receive.
  
===== Issues for IR receive =====
+
Issues for IR receive
  
 
* Issue: How do we avoid tying up the CPU during the receive?
 
* Issue: How do we avoid tying up the CPU during the receive?
Line 161: Line 161:
 
Response 3: Some protocols have error checking built in.  For the NEC protocol the data in the third byte is repeated, and inverted in the fourth byte.  If you exclusive-or (XOR) the bytes together, you should get FF or 11111111.
 
Response 3: Some protocols have error checking built in.  For the NEC protocol the data in the third byte is repeated, and inverted in the fourth byte.  If you exclusive-or (XOR) the bytes together, you should get FF or 11111111.
  
===== The program design =====
+
The program design
  
 
We could have the program go in a tight loop counting the number of times it loops and checking the input port for the transition in the IR signal.  Each time it changes we record the count and restart at 0.  This is how the program '''IR.c''' works.  It is called a blocking routine because it blocks the microcontroller from doing any other operation (except for interrupts) during the receive.  So we will make our routine interrupt driven to end this blocking.
 
We could have the program go in a tight loop counting the number of times it loops and checking the input port for the transition in the IR signal.  Each time it changes we record the count and restart at 0.  This is how the program '''IR.c''' works.  It is called a blocking routine because it blocks the microcontroller from doing any other operation (except for interrupts) during the receive.  So we will make our routine interrupt driven to end this blocking.

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)