Wednesday, July 31, 2013

Connecting the PNA4602 IR sensors to the PIC 16F628


As the PIC 16F628 has 5 interrupts (RB0/4-7) my design for the PNA4602 IR detectors is to have 5 detectors in total to detect the other sumo bot in the ring.  Two would be forward facing and one each for the left side/right side/rear.  The two forward detectors would operate in a crossed over (i.e. cross eyed) setup with the right detector looking left and the left detector looking right.  This would result in an overlap region at the front of pennybot.  Thus my detection regions are

forward left
directly forward (ie detected by both front sensors)
forward right
right side
rear
left side

I assigned the rear sensor to RB0 and the other four IR detectors to RB4-7.  I did this because I was toying with the idea of removing the rear IR sensor and instead using the RB0 interrupt pin for a front bump (ie micro switch) sensor.  It seemed a good way to separate between the two sets of interrupt pins.

To test each IR sensor the line was grounded as the PNA4602 goes low when a signal is detected.  This way the logic of what direction to turn depending on what sensor was activated could be easily tested.

On an aside two of the interrupt lines (RB6-7) are used for programming.  Since these two pins are normally at 5V (due to the PNA4602 output pin being high normally) this interfered with the in-circuit programming of the device.  After doing some web research the standard workaround for this was to put a resistor between the PicKit3 programmer and the rest of the circuit.   So going from the PNA4602 I have for both RB6 and RB7

PNA4602 -- 8.2K ohm resistor -- PIC16F628 RB6/7
    |
    -- PicKit3