-
Notifications
You must be signed in to change notification settings - Fork 3
IR Matrix
This robot has a square matrix of IR sensors pointing to the ground which gives the ability to detect complex patterns on the floor.
Since it's a 7 by 7 square matrix it becomes unfeasible to connect every single IR sensor to an ADC input pin, thus a multiplexer was used to alternate between each row. This means that data is read in parallel row by row by setting the multiplexer's select pins.
This configuration not only decreases MCU pin count usage but also greatly reduces power since each row is connected to a single 12V power rail. Special attention has been given to the size of the resistor in series with the parallel of all rows, and because there is a transistor at the end of the rail to be able to switch off the sensors when not needed this introduced another resistance in series so both had to be taken into account. Additionally, there was left on the design a space to solder a 0 Ohm resistor if one desires to ditch the transistor and work with an always on configuration.
The circuit was designed so that each IR LED would have a current of 20mA through them. This means (according to the datasheet) that a voltage drop of 1,28V would exist in each of them. Since there are 7 sensors in each row, the total voltage drop due to the LEDs is of 8,96V. Therefore the resistor and the transistor would need to drop the remaining 3,04V. Considering the current through them (140mA) the required resistance is easily calculated (21,7 Ohm). Since the value of the resistance of the transistor (when it is on) is in the order of miliOhms then the resistor value was the only one considered for the calculations. So the final value of the chosen resistor is 22 Ohm.
7 of the sensors can be read at once. Which sensors are read is dependent on the value set on the SEL bits:
- 0 doesn't allow for reading any sensors;
- 1 is used to read row 0 of sensors;
- 2 is used to read row 1 of sensors;
- ...
After sending the correct SEL value the multiplexers take 720ns to completely switch. So before reading each row there should be an appropriate waiting time. To that time it should be added that of the MCU ADC. For each of the 7 values read the ADC takes at most 417ns. This adds up to a total of 3,64 microseconds necessary to read each row. This means that it takes 25,5 microseconds to read all values from the IR matrix.
It should be mentioned that the power control transistor takes 3ns to commute and the LEDs take 20 microseconds to turn on (or off). So if the matrix is turned off and on for each time the matrix values are read, then the time it takes to read all values drastically increases to 44,7 microseconds (this value took into consideration that the first selection could be done in parallel with the commutation of the transistor).
The matrix is connected to the following MCU pins:
- ADC1 Channels 3,4,7,8,9,14 and 15
- IR Row/Column Selection -> PB2
- IR Enable -> PE7