PIC Projects

Building the Trackbot

In this project we build a moving robot that can detect and avoid obstacles. It uses two infrared sensors (a couple of emitting IR LED and IR receiver module) mounted at its front left and front right sides. The first prototype is mounted on a solderless breadboard for testing purposes. The schematic is essentially a mixture of the ones appeared in experiments with IR and PWM. The PWM is used to control the vehicle speed. The IR transmitter/receiver couples are mounted at 90° angle from each other to minimize the intensity of reflected signals coming to the receiver of the other couple. For the same purpose the IR LEDs are put into short (1.5cm) black plastic tubes.

First prototypes

Schematic First attempt Second attempt Video clip
      clip
click (DivX, ~4.8Mb)
Embedded PIC program

The moving platform is based on the tracked vehicle chassis kit manufactured by Tamiya. This kit, however, has only one motor which makes the vehicle impossible to turn. I installed on it a twin-motor gearbox also manufactured by Tamiya. The gear ratio is 203:1. In order a set of batteries would last longer, I powered the unit from 2 cells of type C (middle image above; the C-cells are located under the horizontal punched breadboard). The 3V voltage provided by those batteries is sufficient for the vehicle to move pretty fast being powered directly from the batteries. However, since an electronic is used to change the motor direction, which chops off a fair amount of voltage from the batteries, the motor can barely rotate. The 4xAA cells were used to power the controller.

For the second attempt I powered both motors and the controller from a single 3xC battery. The 330μF can shown on the schematics reduces the voltage drops cause by the motors when they change the direction. This model works much smoother, see the video. However, more experiments must be done for find an optimal way to change the motors direction. The red LEDs play an auxiliary role indicating the detection of obstacles.

Final design

Although the above design works well, it is far from being optimal. It took me a while to come up to an appropriate solution to improve the following three aspects of the first prototypes.

Power supply

What was not so good in the above implementation is that too many batteries are used. Although motors need just 3V for normal operation, which could be accomplished by just two cells, the voltage drops down to approx. 2.5V when both motors are ON. This is below the range of voltages needed for the PIC and other electronics on board. An appropriate solution is to use a DC/DC converter. There are plenty of those available. I ordered several evaluation samples from Maxim and choose MAX619 IC for this project.

MAX619 is a step-up charge pump DC/DC voltage converter that requires only a few external elements: two ceramic flying capacitors of 0.22μF and a tantalum capacitor at the output. The schematic is as follows.

Schematic

The IC can only deliver about 30mA of current, which is more than sufficient to power the on-board electronics. This is particularly true if one disables the LEDs indicating the obstacles. But even with those LEDs the circuit works just perfect.

Motors driver circuit

A bigger problem to solve was powering the motors. The motor driver IC SN754410, although being an improvement of L293D, is inappropriate for a low-voltage use. As it involves bipolar transistors, they introduce a drop voltage of at least 0.7V each. This means that the motors actually get 1.4V less from the battery, which is about 50% loss for a 3V battery. They barely start at this voltage and cause of a need for at least a 4.5V battery.

Another disadvantage of this IC is that it needs an extensive cooling. As each of the motors draws about 200mA, the IC dissipates 2·1.4V·200mA = 0.56W of heat. After about a minute of operation it becomes incredibly hot and really needs a heat sink. But even with a heat sink on, we loose about 0.5W of power, which does not help to save the batteries.

I have two solutions to this problem. The first one is to use relays for controlling the motors. In this case we do not loose any voltage and the motors get a full power from the batteries. We need a 3V relay, the best I could find draws only 100mW of power when on. I used two 3V x 150mW low-signal relays from NEC with DPDT contacts (two groups of synchronously switching contacts).

Motor drivers Schematic Control board

The relays are controlled by small transistors equipped with current-limiting resistors and diodes protecting them from inductive load which is relay's coil. A control circuit only for one motor is shown above (the other one is similar). The bases of the transistors are connected to pins 7 and 8 of the PIC. The relays draw about 40mA of current each, but they are on only when a motor direction is changing, so it is not that bad. Although they are 3V relays, their pick-up voltage is below 2V, so they reliably work even from a well discharged batteries. The relays and their controlling circuit is mounted on a small board in the lower level of the robot.


Although the above improvements based on relays works very good, the relays are not very reliable elements and have a tendency to fail. This is particularly true if they control a significant current for their size, which is our case. I have mounted them on a 20-pin IC circuit being prepared to replace them if needed.

Another way to replace the motor driver IC based on bipolar transistors is to use MOSFETs. Those devices are free of the mentioned above limitations of the bipolar transistors. I used N-channel MOSFET of type IRF510 whose resistance in the ON state is 0.5Ohm. Therefore, they introduce only 0.5Ohm·0.25A = 0.125V voltage drop, which is negligible. In this mode the transistor dissipates only (0.5Ohm)2·0.25A = 0.06W and can work without any heat sink. A better choice would be to use IRF520 whose channel resistance is 0.2Ohm. The transistors are equipped with the voltage-limiting diodes and require no other components to interface with the motor.

ON/OFF control H-bridge Final design

The first circuit above can only switch the motor ON and OFF. This is sufficient for avoiding the obstacles in most cases. However, if both IR sensors report an obstacle the robot will stop. To prevent this situation one can use an H-bridge formed by complimentary N- and P-channel MOSFETs shown in the middle picture. However, this does not work with the transistors and voltages shown on the schematics. The reason is that one needs to provide about 5V between the source and gate pins of the MOS transistors of that types for their channel resistance to drop below 1Ohm. The bottom (N-channel) transistors will open fine this way when the control voltage goes high (5V). However, the top (P-channel) transistors remain closed as the voltage drops low (about 0V), as their source to gave voltage is below 3V. The bridge in the shown simple implementation only works reliably when it is powers from 5V or higher.

To resolve the problem I added another DC/DC converter on TC7660 that inverts the onboard +5V voltage into -5V. The chip needs only two electrolytic caps, 10μF each. The idea is to supply the ±5V voltage to the gates of the MOSFETs and this way make them completely opened. This is achieved by adding another IC consisting of 4 NAND gates used as inverters. It is important to use a CMOS gates series because the IC is powered from ±5V and hence the voltage at its output is also either +5V or -5V. The TTL series do not work from 10V while CMOS can be powered from up to 18V. The IC provides an appropriate control of the H-bride and also serves as a buffer between the PNP transistors and the MOSFET gates. The PNP transistors shift the input voltage for the inverters from the PIC's range 0-5V to the range -5 to +5V. As the result the N-channel MOSFET gets +5V at the gate and opens completely. The P-channel MOSFETs get -8V between their source and gate pins and also open completely. Additionally, the NAND gates protect the gates of the MOSFETs from static. The NAND gates themselves are protected by the pull-down resistors of 82K and the PNP transistors. This circuit provides a reliable bidirectional control of a 1 - 3V motor. Finally, one could use the second inputs of the NAND gates for PWM to control the motor's speed.

Full control Control board Another view Yet another view

So, there are two solutions to control low-voltage motors: one based on 3V relays and the other uses MOSFETs. The cost of components in the first case is about $6.50, while in the second case it is about $10. If you do not run the motors for a very long time, the first approach is simpler but is not too efficient because each of the relays consumes about 40mA when it is ON. The second approach is a bit more complicated but involves no mechanical components and is, thus, much more reliable and energy-efficient. With these modifications the robot has the same functionality as the first prototypes, but can work from a single 3V battery.

Adjusting the IR sensors sensitivity

The above developed IR sensors have too high sensitivity for this project. They detect obstacles at about 1 feet distance. This way the IR receiver modules often fail, as they get random reflections from other objects causing the robot to turn for no reason sometimes. To modify the sensitivity I used the fact that the IR receiver modules have highest sensitivity at 38kHz. Dropping the driving LED frequency down to approx. 33kHz reduces the sensor sensitivity in about a factor of 2. This is established by adding only 2 instructions in the code to increase the length of the IR driving cycle up to 30 instructions. This way the IR driving pulses have period of 30μsec, which corresponds to the frequency 33.33kHz. Another thing I modified is the number or IR LED pulses in a package (increased up to 16) and reporting an obstacle only if at least 8 pulses are received back.
The final code is trackbot2.asm

Things to consider

The robot's electronics is assembled on a perfboard by using a point-to-point technology. This allows to easily modify the circuit if needed for further experiments. For the same purpose I put a larger IC circuit that is needed for the used PIC.

With the modifications of driving the motors above one cannot control the motor speed easily. Theoretically, one could use the PIC's enhanced PWM mode. This will require 4 pins to drive a single motor. Since the PIC has only one PWM thread, one cannot control the speed of both motors from a single PIC. A better solution would be to use an H-bride driving circuit with a built-in logic for changing the motor direction and speed.

The robot design assumes an extention by adding other control board(s) for further experiments. However, placing the motors and batteries to the tail part of the vehicle reduces its stability. A preferred position for the batteries is in the middle.


Last modified:Mon, Jan 23, 2023.

05343