Go to Post Just to be clear, NOTHING anyone says here is a confirmation. The ONLY source for official answers to questions like this is the FIRST Q&A system. - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Control System > Sensors
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 13-01-2008, 13:45
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 589
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Programming the Infrared board

Hi -

I wrote a quick sample program that reads the infrared board connected to 4 digital inputs. The problem is that the pulses are 100ms from the board so it's easy to miss one if your program is in a Wait.

The quick solution was to register a repeating timer - so every 30 milliseconds the code checks the four ports (4, 5, 6, and 7 in this case) and if the value changed from off to on, it sets a corresponding bit in a char variable. This all happens in the interrupt service routine for the timer. Then you can read the values in your code that may not be checking as often.

This particular program is build for Vex, but everything but the header files is the same.

Code:
#include "BuiltIns.h"
#include "ifi_picdefs.h"
#include "Vex_ifi_aliases.h"

volatile static unsigned char irCommands = 0;
volatile static unsigned char previous = 0;

// Timer interrupt service routine
// Poll the remote receiver input ports every 30ms and check if a recognized code
// came in. This will work even if the main program is in a Wait statement or doing
// other things. The IR receiver pulses for 100ms when a valid code is received.

// This will potentially show multiple hits
void CheckIR(void)
{
	unsigned char current = 0;
	unsigned char changed;
	if (rc_dig_in05) current |= 1;
	if (rc_dig_in06) current |= 2;
	if (rc_dig_in07) current |= 4;
	if (rc_dig_in08) current |= 8;
	
	changed = previous ^ current;
	irCommands |= (~previous) & current;
}

// Sample test program to 
void main(void)
{
	RegisterRepeatingTimer(30, CheckIR);
	while (1)
	{
		Wait(4000);
		printf("_____________________\r\r");
		if (irCommands & 1) 
		{
			irCommands &= ~1;
			printf("Command 1\r");
		}
		if (irCommands & 2)
		{
			irCommands &= ~2;
			printf("Command 2\r");
		}
		if (irCommands & 4)
		{
			irCommands &= ~4;
			printf("Command 3\r");
		}
		if (irCommands & 8)
		{
			irCommands &= ~8;
			printf("Command 4\r");
		}
	}
}
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pic: Programming prototyping board Andrew Schuetze Extra Discussion 3 08-12-2007 18:30
Perf Board = BS2-IC Carrier Board? indieFan Electrical 2 16-09-2004 08:28
What is the true field infrared emitter? scottm87 Programming 4 20-04-2004 18:22
Ordering the TSOP34840 Infrared Receivers yaman Electrical 5 23-01-2004 02:10
Infrared Beacon Board AlphaOmega870 Electrical 5 23-01-2004 01:58


All times are GMT -5. The time now is 21:47.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi