Friday, April 13, 2007

Kobots flocking

7 Kobots are flocking.

Friday, December 22, 2006

Tuesday, December 5, 2006

KOBOT videos, obstacle avoidance

No speed up in the videos! It is the actual speed of KOBOT but not maximum.

For a detailed description of the obstacle avoidance algorithm please refer to Area measurement of large closed regions with a mobile robot, by Erol Sahin, Sertan Girgin and Emre Ugur.




Modifications performed in the software of short-range sensing system

In the previous post, we have given the code segment running in the host microcontroller which requests and then receives sensor reading from each 12F683. This code waits for the sensor reading to be sent indefinitely, which may hang up the host microcontroller. Watchdog timer of the host microcontroller is enabled to overcome this problem, which is actually quite successful. It is preferred to modify the code segment to prevent hang up, instead of using watchdog timer in 16F877A (watchdog timer is still used in 12F683's). The code is modified and is given below:

timeout = 0;
output_toggle(SENSOR0_TX);
while (!kbhit(SENSOR0)&&(++timeout<100))
...delay_us(1);
if(timeout<100)
...sensorData[0] = getc(SENSOR0);
else
...sensorData[0] = 0;

In this code, the host microcontroller waits for approximately 100 us for the sensor reading to be sent and if it is not received it sets the reading to 0 and passes to the next sensor. In this way, the host doesn't hang up indefinetly. Two important points to note in this code segment are:

  • delay_us(1): The delay should be as small as possible not to miss the start bit.
  • if(timeout<100): This if condition is used to test whether the program exited while condition due to timeout condition or reception of startbit. In this if statement, timeout condition should be checked instead of kbhit() because if the starbit is received, checking kbhit() will make 16F877A miss the next data bit (since kbhit() function will treat the next data bit as the start bit).

Deadlock in short-range sensing system

Short-range sensing system and the main control card passed the power-up test explained in the previous post, Yet another problem with short-range sensing system. Next test is the stress test, in which the system is operated for hours to detect if there is any problem in any part of the system. Everything is fine up to now, but when the stress test is performed we faced another problem. The sensor PIC locks in an unknown state and doesn't send the reading results to PC. No problem is detected in the main control card, it is operating even when the sensor PIC fails. This shows clearly, power failure isn't the cause of the problem. The problem is probably about the software of either the sensor PIC or 12F683's.

As explained in the previous posts, First sensor is working and An overview of the Short-range Sensing System, host microcontoller, sensor PIC, requests data from each 12F683 sequentially waiting to get data from each of them. When there is a problem with one of the 12F683's, sensor PIC gets into a deadlock. The following C-code (running on sensor PIC) explains the things more clearly:

output_toggle(SENSOR0_TX); //request pin is toggled to inform 12F683 to send sensor reading
while (!kbhit(SENSOR0)); //wait for serial data to be sent
sensorData[0] = getc(SENSOR0); //get serial data

When the request pin of 12F683 is toggled, an interrupt occurs and 12F683 immediately sends the current reading results to 16F877A, then it returns back to its measurements. The problem arises just at that point. There may be a chance that 12F683 be in a time critical section of the code and when it jumps to the interrupt vector, it looses time and may get stuck and stop working properly. When a certain 12F683 is in deadlock state 16F877A immediately fails since it waits the sensor sensor reading to be sent indefinetly. That seems to be exactly what we observe in the system.

In order to overcome this problem watchdog timer, defined by Wikipedia that: "A watchdog timer is a computer hardware timing device that triggers a system reset if the main program, due to some fault condition, such as a hang, neglects to regularly service the watchdog (writing a 'service pulse' to it, also referred to as 'patting the dog'). The intention is to bring the system back from the hung state into normal operation", feature of the PIC's is planned to be used.

Watchdog timers of both 16F877A and 12F683 micrcontrollers are enabled. It is easy to enable watchdog timer in CCS C compiler. The important point is to be careful in the delay loops, since microcontrollers wait in delay loops and watchdog timer can easily detect this as a deadlock and reset the microcontroller. To avoid that situation, the following is suggested in CCS C compiler:

/* Delay for 20 mhz crystal */
#use delay (clock=20000000, restart_WDT)

#use delay macro is used by the delay loops everytime they are called. When we add the term restart_WDT the watchdog timer is reseted when there is a delay loop which prevents watchdog timer to operate incorrectly. Selection of the period of watchdog timer is dependent on the application and the algorithm used as an example (this example is given for 16F877A microcontroller) we have used 288 ms as the period which means that when the microcontroller hangs for about 288 ms, watchdog timer will reset it.

setup_wdt(WDT_288MS);

After setting the watchdog timer both for 16F877A and 12F683 microcontrollers, we started the stress test and observed that the system operates as expected.

Yet another problem with short-range sensing system

We faced a power-up problem in the short-range sensing system, actually in the PIC's. We have completed the sensor card, test it a little bit, found that it is OK. We have then moved to the main control card, soldered the main controller card and tested it. There seems to be no problem with this card, too. The next point is to connect those two cards via the 60-pin HIROSE connector. Two cards are connected to test them together.

The test is as follows:

  • The host micrcontroller of the sensor card, 16F877A, takes readings from the eight sensors and sends them continuously to PC via its hardware serial port. In the original configuration it will send the reading information to the PIC in the main control card via I2C, but for the sake of simplicity and ease in debugging, we prefer to send data serially to PC instead.
  • PIC in the main control card, continuously blink the blue debugging LED in front of the robot which is like an heart-beat signal to indicate that this PIC alive and working.

When the system is powered up it is observed that the system works perfectly almost all the time. But when the power is turned on then turned off it is observed that both the main PIC and the host PIC in the sensor card lock. They don't work properly, sensor PIC stops to send serial data and main PIC can't blink the blue LED.

Solution(1):

The first solution that comes to mind is the use of a big DC power supply. This power supply has big capacitors, may not satisfy the minimum initial rise time, which is stated as 0.05V/ms in the datasheet, requirement of the PIC's. A battery-pack having 3-AAA sized 2300mAh NiMH batteries is utilized in the tests and the power is rapidly turned on and turned off. The result is the same it is even worse, both of the PIC's lock almost everytime in the tests.

Solution(2):

The problem seems to be harder than we thought. We have catagorized the problem as power-up problem and search for a solution. Reset alternatives of PIC is analyzed thoroughly from the datasheet and from the perfect book about the PIC microcontrollers, Design with PIC Microcontrollers by John Peatman, http://www.amazon.com/Design-Pic-Microcontrollers-John-Peatman/dp/0137592590. There are several ways to solve power-up problems. These are:

  • Power-up timer: Power-up timer together with oscillator start-up timer facilitates a delay of approximately 28ms before the code execution begins in PIC's. Because errorenous execution of the code may be observed if PIC starts to run code before its voltage is below 4V (4V is specific to our case, standard 16F877A microcontroller may work between 4-5V, LF type PIC's may work at much lower voltages but with a lower clock rate). The power-up timer has already been enabled in our case but couldn't solve our problem. The power-up timer has one draw-back it can't function properly when the minimum initial rise time criteria isn't satified.
  • Brown-out detector: Brown-out is defined by Wikipedia that "the voltage level is below the normal minimum level specified for the system". The "A" series PIC's have built in brown-out detectors that can be enabled by the configuration bits. The brown-out detector as stated by Peatman has four important functions: (a) When the PIC is turned off and voltage drops below 4V, the minimum operating voltage, brown-out detector puts the PIC in reset condition, (b) when a brown-out condition occurs, i.e. when the system is power-up from a DC supply and the input voltage (220V DC, in Turkey) to the DC supply drops below a certain value DC supply can not regulate its output hence voltage may drop below 4V, in this case brown-out detector again puts PIC in reset condition until voltage stabilizes above 4V, (c) while the PIC is operating power glitch may occur, which causes VDD (supply voltage) to drop below 4V and brown-out detector puts PIC in reset state, if the glitch is longer than 100 us, until VDD stabilizes, (d) brown-out reset circuit puts PIC in reset state when the power-on reset conditions aren't satisfied, i.e. brown-out detector resets PIC even the minimum initial rise time is not achived (please note that there is no mechanism in PIC to prevent mulfuction when the initial minimum rise time criteria is not satisfied, dispite the brown-out detector).

Brown-out detectors of both main PIC (16F877A) and sensor PIC's (16F877A and 12F683's) are enabled and the previous power-up test is repeated. The power is again rapidly turned on and turned off, and the system works perfectly! Brown-out detector has solved our power-up problem.

Monday, December 4, 2006

Strange blue LED problem!




Blue LED-PIC connection diagram

The first problem we faced is in the blue LED of sensor 5 (sensor numbers start from 0, being the front sensor, sensors numbered in CW direction and 4 being the rear sensor). Blue LED of sensor 5, is connected to the RA4 (bit 4 of port A) of the host microcontroller of the short-range sensing system as indicated in the above figure. The LED will be lit when RA4 is set to HIGH, and LED will be turned off when RA4 is set to LOW, but this is not the case! The LED behaves erratically.

Open-drain output diagram of RA4


When we look at the datasheet of 16F877A, we have noticed that the RA4, has open-drain output characteristics, as shown in the above figure. It is noted in http://www.brouhaha.com/~eric/pic/open_drain.html that:

Open-drain outputs are outputs which at any given time are either actively sinking current (i.e., low voltage, typically considered logic 0) or are high impedance, but which never source current (high voltage, logic 1). Open-drain refers to the drain terminal of a MOS FET transistor. The equivalent concept on a bipolar device is called open-collector.

Most microcontrollers don't have dedicated open-drain outputs. On some PICs the PA4 pin (also known as RTCC) may be used as an open-drain output. Most of the other port pins are bidirectional, and have separate output data registers and direction registers. On the PIC, the direction registers are called TRIS registers, an abbreviation for Tri-state, which is actually a trademark of National Semiconductor. The TRIS register bits should be set to logic 0 for lines that should be active outputs, and logic 1 for lines that should be high-impedance inputs. Note that this is the reverse of the conventions used by almost all other microcontrollers and peripheral devices.

In order to obtain the effect of open-drain output, it is necessary to use the TRIS register bit to control the output rather than the more usual use of the data output register. This is most easily accomplished by leaving the appropriate bit of the data output register set to 0, and setting the corresponding TRIS bit to 0 when the output should sink current, and 1 when the output should be in the open-drain (high-impedance) state.

The important point to note is that open-drain ports can not source current, they can only sink current. In our configuration, shown in Blue LED-PIC connection diagram, we are sourcing current to the blue LED's to lit them. This connection type is appropriate for I/O pins having TTL characteristic only, not suitable for open-drain output pins. Hence a small modification is performed on the LED of sensor 5. The ground connection of the sensor is cut using a sharp knife and 5V is connected to this trace instead. The polarity of the LED is also reversed since current will flow from 5V to RA4 port of the PIC (the port will sink current).

The following C-code(CCS PIC C compiler) is used to turn on and turn off the LED:

To turn on LED:

output_low (SENSOR5_LED); //changes the state of RA4 to LOW

bit_clear(trisa,4); // makes RA4 as output and RA4 sinks current

To turn off LED:

output_low (SENSOR5_LED); //changes the state of RA4 to LOW

bit_set(trisa,4); // makes RA4 as input which means it is in high-impedance state and no current flows

Main control card



Main control card is used to execute the main behavior algorithm of the KOBOT. It is 20x80mm in size and has a PIC16F877A microcontroller at 20 MHz, two SI9988 motor driver IC's from Vishay, a PCA9306 from TI for I2C voltage level conversion between 3.3V and 5V systems and two MAX3371's from MAXIM for voltage level conversion between 3.3V XBee OEM RF module mounted on the sensor board and PIC16F877A. (XBee module has not been mounted yet and will be mounted and tested after I2C tests between main control card and sensor card microcontrollers.) The main control card is connected to sensor board via a 60-pin HIROSE connector. The microcontroller is programmed via ICSP (In Circuit Serial Programming via 5 pins) using the KOBOT data cable. A serial connection for this microcontroller is also available on the data cable connector. This connection is designed configurable as hardware serial or software implemented serial connection via 0R0s. Motor control IC's have also voltage or current feedback capability. In this card we have implemented the voltage feedback circuit.

Currently, the microcontroller and SI9988's (without feedback circuit) are mounted.
Tests made so far:
- Programming via KOBOT data cable,
- Hardware serial connection at 115.2k,
- Debugging leds (mounted on the sensor board. red, green and blue),
- Buzzer(mounted on the sensor board, 12mm piezo),
- Motor driving test using 78Khz PWM signal.

Tests left:
- I2C communication with the sensor board microcontroller,
- Programming via XBee OEM RF module,
- I2C communication with the PXA card,
- Motor voltage feedback circuit control

First video from KOBOT:



An overview of the Short-range Sensing System

In the short-range sensing system; there are eight infrared sensors 45 degrees apart. Each sensor has its own 12F683 microcontoller for making measurements and for communication with the host microcontoller. The sensors have a range from 0 to 30 cm and they discretize the range into eight levels (1 to 8). Each sensor makes continuous readings and sends the current result via serial port upon request of the host microcontroller. There is a blue LED near each sensor, which is clearly seen by the user to indicate that there is an object within the detection range of each sensor.

The host microcontroller, which is a PIC 16F877A, requests the current reading results from each sensor, and waits for the data to be sent and continues this process until all of the sensors sent their reading results (the result can be a number from 1 to 8 according to range or 0 for no object condition.). The first thing that the host microcontroller does is to lit the corresponding blue LED nearby each sensor if the sensor has detected an object within its operating range. The LED's are controlled by the host microcontroller instead of 12F863's. This is a necessity rather than a decision since 12F683 is an 8-pin microcontroller, all of its pins are used for power, operation of IR LED/detector and serial communication and no pin is left for the indicator LED. This necessity is also useful for debugging the operation of the sensors and the communication between sensors and the host microcontroller since the LED's can only be lit when sensor is operating correctly and serial communication is successful.

The host microcontroller, after turning on/off the blue LED's according to the reading results, sends readings of eight sensors via I2C to the main microcontroller, which is again a PIC 16F877A, upon its request.

Monday, November 27, 2006

Saturday, November 25, 2006

Design Notes-2

Log for smd XTAL problem:
- At first ECX-53B 20MHz XTAL is mounted with two 22pF capacitors. The pic is programmed but does not work.
- Then ECX-53B unmounted and a normal dip XTAL is mounted while 22pF capacitors still mounted. The pic does not work again.
- The normal dip XTAL is unmounted and a programming test is performed without any XTAL successfully.
- 22pF capacitors are unmounted and the pic is tested using the normal dip XTAL and works.
- Then ECX-53B (previously unmounted one) is mounted again without 22pF capacitors and the pic works for about 3 minutes.
- A new ECX-53B is mounted without 22pF capacitors and the pic works (and still working with this XTAL). At this last step the inconsistency between ECX-53B's mentioned in "Quick Notes-1" post is realized.

First Sensor is working




First sensor is mounted and working properly. But some calibration is needed. There is not any problem with the range (~30 cm using 12x12cm white paper) but 8th level is very narrow. Blue led is shining since the sensor senses an object. The sensor has a PIC12F683 microcontroller and measures the distance using IR signals. It sends distance information to the sensor card controller (PIC16F877A) upon the controller's request. Request is made using interrupt features. Blue led is controlled by the sensor card controller. Object information is also sent to the PC via serial connection at 115200 baud using the Kobot data cable for testing purposes.

Friday, November 24, 2006

Quick Notes-1











- PIC16F877A on the sensor board is mounted and first led test is OK! A problem occured with the 20MHz smd XTAL. It is solved by unmounting 22pF capacitors. Why they caused a problem is unknow yet! But we have realized that two different but same part numbered XTAL has different pin out style. The pictures clearly shows this inconsistency. :S

- A simple serial communication test is also performed successfully.

- Now it is time to move on first sensor....

Thursday, November 23, 2006

Design Notes-1

A possible soldering order for the components of the power system:
  1. Flying capacitors on the bottom side of the power card: These components are very critical for output to be ripple free and very sensitive to heat. So, try to finish soldering as possible as quickly to avoid even slight differences in the capacitance values.
  2. TPS60130's: Do not forget to apply grease to the PowerPADs (two rectangles with 9 vias on each) before soldering. PowerPADs are needed to dissipate the heat on the ground plane.
  3. Input capacitors.
  4. Output capacitors, tantal and ceramic.
  5. Voltage divider for low battery input circuit: 680k, 390k and 100nF on the bottom side.
  6. Low battery indicator led and its resistor.
  7. Microcontroller and its peripherals.
  8. JST connector on the sensor board.
  9. Fuse on the sensor board
  10. Female header on the sensor board. You may have difficulty while soldering +5V and GND pins due to large power planes!
  11. Male precision headers. A simple trick: Plug them to the female headers on the sensor board and then plug the power card to the male headers. Solder four pins, unplug the power card and solder rest of them. With this way, alignment problems can be avoided.

Soldering the Power Card


The power card is soldered and seen on top of the sensor board. The critical components in the card is the two TPS60130 step-up converters, the ceramic input capacitors, the ceramic output capacitors and the ceramic flying capacitors which are not seen on the picture since they are on the bottom side. There is also one SMD red LED (near the bottom right corner) to show the condition of the battery. The red cable is used to connect Vin to the ENABLE pin of TPS60130 which makes the power card always ON. This configuration is temporary and for testing purposes only. There will be a PIC 10F202 microcontroller that will take input from LOW BATTERY output of TPS60130 and from power button of the Kobot. In this way Kobot can be turned on and turned off by the user. Also when the battery is low, the microcontroller sends a signal to the microcontroller on the main card to take precautions before the system is shutdown. The power system includes also a fuse mounted on the bottom side of the sensor board.

Power Card

We started building the Kobot from the power card. The power card is the main power source of Kobot's. It is 30X20mm in size and has two TPS60130 step-up converter chips from TI. The input to the power card is either from one-cell Li-Poly battery having a nominal voltage of 3.7V or from 3-cell AAA-size NiMH batteries having a nominal voltage of 3.6V. The output is a constant, almost ripple free 5V.


Wednesday, November 22, 2006

Getting Started

We have just created the blog and started our mission...