DIT RoboSumo IR LED ring draft code

NB This code is not actually being used in this year’s RoboSumo arena (see below for details).

This was some draft code for the ring of IR LEDs around the DIT RoboSumo arena. It outputs 36kHz pulses from PWM output 1 (CCP1, pin 17) on the PIC18F4620. The sequence, which repeats indefinitely is:

  • 0.5ms of 36kHz square wave
  • 0.5ms at 0V

As things turned out, following hours of painstaking experimentation by David Dorran, we decided to drive the ring LEDs with a constant 36kHz square wave, rather than the pulsed carrier produced by this code. For the specific requirements of RoboSumo (detecting when an opponent obscures a direct line of sight to the IR perimeter ring), the constant 36kHz carrier produces much better results with the TSOP31236 detector that most teams are using this year. If the carrier is switching and off, the detector operates with such high sensitivity that it continues to detect the IR signal even when the direct line of sight to the emitting LEDs is lost, making it useless for detecting the presence of an opponent. Of course, for data transmission over longer distances, this high sensitivity behaviour is usually exactly what is desired, but for RoboSumo the reduced sensitivity achieved through uninterrupted transmission of the 36kHz carrier signal is preferred.

Anyway, here’s the draft code:

#include <p18f4520.h>
#include <delays.h>

#pragma config OSC = INTIO67
#pragma config WDT = OFF
#pragma config MCLRE = OFF
#pragma config LVP = OFF

void main(void)
	// Set clock frequency (section 2 of the PIC18F4620 Data Sheet)
    // Set Fosc = 32MHz (including PLL multiplier), which gives Tcy = 125ns
    OSCCON = 0b01110000; // 8MHz
	OSCTUNE = 0b01000000; // enable PLL x4

	// Set up PWM (section 15 of the PIC18F4620 Data Sheet)
	CCP1CON = 0b00001100;   // PWM on CCP1
	CCP2CON = 0b00001100;   // PWM on CCP1
	TRISC = 0b11111001;     // CCP1, CCP2 as outputs
	T2CON = 0b00000100;     // Enable TMR2 with prescale = 1
	PR2 = 221;              // period = (PR2+1) * Tcy * prescale = 27.5us
	CCPR1L = 110;
	CCPR2L = 110;

	// Main loop
		// 36.363 kHz pulses on
		CCPR1L = 110;
		CCPR2L = 110;

		// 36.363 kHz pulses off
		CCPR1L = 0;
		CCPR2L = 0;
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s