
| Silver Sumo Hardware Routines | Main Sumo Program | Guardian Program |
To accommodate for additional hardware, the IgORElib needed to be modified. Most of the major additional routines that were needed, were to be done in each individual code application.
On to the Code!
Original code will be done in GREEN, and any modifications that I have added to the code will be in YELLOW.
You can download the code in Zip format HERE
The only thing that was needed in the header file was to add a single define statement.
#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0
#define FLASH 2
#define AUTO_UPDATE 3
A new header file had to be included because some of the calls later in the IgORElib.c will need the function definitions.
#include "igorelib.h"
#if !defined( IGORE_LIB_VID ) || ( IGORE_LIB_VID != 102 )
#error "You must use the IgoreLib Version 1.02 Header (.h) for this file"
#endif
#include "SS_Hardware.h"
One of the interrupt routines needed to be modified to allow the level meters to be updated within the routine.
/****************************************************************************/
/** Interrupt Handling */
/****************************************************************************/
/**/
/**/ #pragma code set_high_irq_vector = HIRQ_V //----------------------------
/**/ void set_high_irq_vector( void ) // SET HI PRIORITY INT VECTOR
/**/ { //----------------------------
/**/ _asm //
/**/ goto high_IRQ_handler // - load vector
/**/ _endasm //
/**/ } //
/**/ #pragma code //
/**/ //
/**/ #pragma interrupt high_IRQ_handler //----------------------------
/**/ void high_IRQ_handler( void ) // HIGH PRIORITY INT HANDLER
/**/ { //----------------------------
/**/ if( INTCONbits.TMR0IF ) // - chk TMR0 overflow
/**/ { //
/**/ WriteTimer0( SYSTEM_CLOCK_RELOAD ); // - reload TMR0
/**/ SYSTEM_CLOCK++; // - inc sys clk
/**/ INTCONbits.TMR0IF = 0; // - clr TMR0 int flag
/**/ //----------------------------
/*NC*/ if (Meter_Mode == (uint8)AUTO_UPDATE) // Update for Meter_Set fctn
/*NC*/ Meter_Update(); //
/**/ //----------------------------
/**/ if (STATUS_LED_MODE == (uint8)FLASH) // - stat led in flash mode?
/**/ LATBbits.LATB1 = !LATBbits.LATB1; // - then toggle to flash it
/**/ } //
/**/ } //----------------------------
Within the initialization routine, the state of some of the I/O pins had to be changed. No biggie, just changing TRIS<port> variables.
void igore_init( void )
{
TRISA = 0xEF; // A5=I A4=O A3=I A2=I A1=I A0=I
TRISB = 0xD1; // B7=I B6=I B5=O B4=O B3=0 B2=0 B1=0 B0=I
TRISC = 0x90; // C7=I C6=O C5=O C4=I C3=0 C2=0 C1=0 C0=O
TRISD = 0xE3; // D7=I D6=I D5=I D4=O D3=O D2=O D1=I D0=I
RCONbits.IPEN = 1; // enable interrupt priority levels
init_PWM();
OpenI2C( MASTER, SLEW_OFF ); // setup I2C
SSPADD = 39; // rate generator ... 100 KHZ
OpenUSART( USART_ASYNCH_MODE & USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 66 );
OpenADC( ADC_FOSC_RC & ADC_RIGHT_JUST & ADC_8ANA_0REF, /*ADC_CH0 &*/ ADC_INT_OFF );
init_port_b(); // setup Port B
init_system_clock(); // setup system clock
global_interrupts( ON ); // enable global interrupts
}
I also added the code into the calibration routine to setup the threshold for the ground IR sensors.
NOTE: This could have been done many way, I just threw this in so that I would have a way to set the light values if I absolutely needed to.
void set_line_threshold( void )
{
// Right Sensor should be on the line, left should be in the ring
LINE_THRESHOLD = sample_AD( IR_OUTSIDE_LEFT ) + (sample_AD( IR_OUTSIDE_RIGHT ) - sample_AD( IR_OUTSIDE_LEFT ));
}