Laser Tank - Basic tracked robot with Targeting Laser pod!

 

THIS ARTICLE IS NOT READY YET!I'LL START DOCUMENTING AGAIN SOON... SORRY FOR DELAY...

 

 

IF YOU WANT HAVE A LOOK AT THE DS2438Z SMART BATTERY MONITOR. WE ARE COMING BACK WITH

A BETTER VERSION AND A MODULE READY TO PACKED WITH A BATTERY PACK MONITORING VOLTAGE

CURRENT IN AND OUT (meaning that you can track both battery life circles and charging) TEMPERATURE

AND EVEN PROVIDING SOME STORAGE FOR DATA...

 

THANKS FOR YOUR PETIENCE...

 

It's been a while I was using only my Basic Stamps for building robots... But Basic Stamps lack both the speed and the flexibility for most applications even though the are perfect for learning structured programming and the BASIC language. So now the time has come for me to use AVR in my robots... AVR are nice microcontrollers with many features, like interrupts, timers and so on..., they are much faster that the Basic Stamps and the have bigger memory allowing us to write more code... Also they are very easy to use requiring only power to operate (and if you like a crystal - osclinator) and very easy to program (There are many nice circuits out there in Google... I just prefer the 10pin STK500 ISP). So in this project we'll be using the ATMEGA16 @16MHz. But as every project... it must have something special, something to be able to look different from other... But what???

I 've seen many robots with photosensors (photovore, photophobe), many linefollowers, many object avoiders, some heat seakers, sumobots, micromouse and others... BUT, very few had a battery monitor... Most of them run on a new or freshly recharged battery... If the battery was drained and wasn't simply enough capasity to feed the robot???

That's why I incorporate a Dallas Semi DS2438 in my circuit board... I don't like usually to advertise but this chip had everything... A current sensor, a voltage sensor, a thermometer and so other goodies we won't be needing...

 

Now navigation... Since it'll be a simple navigator - free roaming robot (with some extra features) I'll be using a simple IR_pair for the robot, but if I have time (aaa exams exams exams exams they are killing me!!!) I'll also include a Sonar... The pair will consist of a TSOP1907 and some single IR Leds...

 

And now it's picture time... Since I have assebled the case years ago and don't like to rip it up right now... I'll be showing some basic pictures of the case of the robot explaining how it was built and which are the thoughts for the future =P....

So here is an overview of the robot case:

Main Case Overview

 

And here is the front view of the robot... As you can see the case is quite close to the ground but our subject here is not machining clearly but programming the robot behaviors...

Front view

 

Here is the bottom view of the robot... It used to be used as a place for the batteries but as experience grow it teaches me to place the battery (and any other heavy thing) in the front of the robot to be able to climb hills with easy... But more details coming...

And the bottom of the robot

 

And here is the machining tips for the wheels!!! I got some servo cross-like horns cutted 'em to fit the inner of the wheel, placed a screw in an empty hole of the wheel and glue it for safety with some super glue!!! And finish... Also I kept the outter axis of the wheel (it was there from the time I bought this poor toy) and after shorting it a little, I fitted it back in. So the Case and the wheels are bond together making the locomotion system more stample than ever. NOTE: that the locomotion system that was with the toy was extremely weak that's why I placed in the servos!!!

Finally, and also very important, after mounting the servos to the case I jointed 'em with that golden pipes (don't know how to call 'em sorry). And here we are... the locomotion system and the case in finished!!! Now it's batteries' time...

And some of the wheels machingAnd the servos joints

 

And now the hardest part for me... mounting the batteries... Batteries usually are the heaviest part of a robot. Because we have a tracked robot, placing the batteries in the front is crusial for the balancing of our robot and it's ability to climb step hills!

 

By placing the batteries that way:

Battery holder

 

I hane the robot balancing it's weight at about the middle of the robot so it's just very ok!!! As you can see the holder is very simple just a part of a pcb mounted to the case with some screws and glue and so long pin headers to hold the battery. So with the battery, it should look like that:

 

battery mounted

 

And now the big deal... The electronics. I have been trying to use two microcontroller since the beginning but always something was about the fail... LCD fail, IR fail, frequency generator fail... And do on which I really hate to describe (my hours being lost for nothing). And the biggest of my problems... That f*ckin# TSOP were broken, they were old - yes, but broken??? AAggghh!!! All my Sunday for a pretty nothing... Uugghh, sorry for this but I think everyone can understand me... So, finally, I had 'em replaced with some nice Panasonic ones I had... (desoldered 'em from older boards I have made and almost never used...) Surpassing these promblems after many hours having been wasted I finished the main board consisting of a ATtiny2313 @ 20MHz that I won't refer to cause it's never used, the main processor which is an ATMEGA16 @ 16MHz, a simple regulation circuitry, a NE555 tuned at ~38KHz for the IR leds and the pride of the board! The DS2438!

Before I get any closer to the software I'll give the schematics...

 

So here are the schematics for the main board of the robot:

Main_Board

 

The regulation circuit consist of a simple 7805, some filter capacitors and some anti-current spike capacitors

And here it is:

Power_Supply

And now the NE555 schematics:

555

So after all these the board should look like that:

Board_Finished

 

And finally the board mounted on the case!!! I feel just nice...

Robot_with_board

 

How to Smart Battery Monitor - DS2438

First of all, I DO NOT advertise any product, but I was really amased by capabilities of the IC...

 

Just an idea on what we will be working on... Enjoy the vid!!!

 

http://www.youtube.com/watch?v=lkWBCdWDAr4

 

The DS2438 is a everything about the battery IC... It can measure Voltage of the battery and record it, it can measure current in and out the battery pack... It can also measure the temperature of the pack... And also has some spare EEPROM room... A all in one chip!!! The communication protocol is 1wire so, I was not just getting the readings directly... In 1wire communication many devices can exist on the same bus. So the microcontroller has to address every device seperatelly... How? Every 1wire device has it's special ID number which is laser in the ROM. In order to select a device, you firstly have to reset the device with a pulse. After that the device repplies with a presence pulse. Then the master has to choose a ROM function. There are 4 ROM functions in every 1wire device...

The READ ROM function which makes the device to sent the lasered ID to the master and then the master gains access to the CONTROL functions of the device.

The MATCH ROM function in which the master sents out 64bit. If all these 64bit match the device special ID then the device is accessible to the control function. If not, the device is inaccessible.

The SEARCH ROM function. Actually I have never used it, so I may be mistaken. When selected this function makes the device to sent 128bits. These 128bits are actually the 64bits of the lasered ROM. But how can they be double??? The device firstly sents two bits, the first with the TRUE value of the first bit of the lasered ROM (64bit all together) and the other with the FALSE value. Then the master must sent a bit back to the device. If this bit matches the first one of the lasered ROM, then this continues with the next bit and so on until the last bit matches. If so the device is further accessible. If not the device is inaccessible.

The SKIP ROM function, which just skips the ROM and gives you access in the CONTROL functions of the device.

And here is the flowchart from the .pdf of the device:

Flowchart1

If multiple device exist on the same bus, only the MATCH ROM function is recommented. Otherwise, a data collition may occure resulting to wrong data.

 

Now, that was some general info on accessing a 1wire device. Let's say we have a DS2438Z and we have accessed the CONTROL functions of the device. What next???

Most 1wire devices uses a scratchpad to communicate with the master. Whatever the master wants to say to the device writes it on the scratchpad and reverse. So controlling the scratchpad of the device in co-operation with the EEPROM, It's the most important thing in the DS2438Z (plus every 1wire device).Here are the basic functions with the scratchpad: (when I refer to SP it's scratchpad)

NOTE: In DS2438 the scratchpad consists of 8 pages. The right address for every page is from h00 to h07

 

The WRITE SP function. In this function the master sents the number of the page of the SP
and then the master sents bytes of data. The maximum number of bytes is 8. If the 8th byte is reached the deviced must be reseted by the master.

The READ SP function. In this function the master sents the number of the page it wants to read and then the device starts to sent the 8 bytes each page has. If the 8th page is reached then the deviced must be reseted by the master. The reading can be ended prematurely by having the master to reset the device.

The COPY SP function. In this function the master sents the number of the page of the scratchpad which will be copied to the respective page of the EEPROM of the device. When this action ends the device must be reseted by the master.

The RECALL MEMORY function. In this function the master sents the number of the page of the EEPROM of the device that will be copied to the respective page of the scratchpad. It's the reverse action of what COPY SP function does. When this action ends the device must be reseted by the master. The RECALL MEMORY function is nessessary for reading the data out of the device. When the device measures current, voltage or temperature it stores the data in the first page (h00) of the EEPROM. Cause the master can only read the scratchpad, we have to copy the data from the EEPROM to the scratch pad. And this is what we do here.

Now in order to have new data available (temperature, voltage, current) be must tell the device to convert the respective readings to data. Current readings are automatically converted every 27msec. But we must tell the device to convert the temperature and the voltage readings. This is done with the following functions:

The CONVERT T function. With this function we convert temperature readings to data. When this ends the device must be reseted.

The CONVERT V function. With this function we convert voltage readings to data. When this ends the device must be reseted.

Note that with every function that consist of the CONTROL functions we can reset the device prematurly. This DOESN'T mean that the function will not take place. Every action that must be done will be done no matter if reset occures. Here is the flowchart of the CONTROL functions:

Flowchart2Flowchart3

 

Now let's get a little bit more practical - enough with theory. The DS2438 -yes- it can measure voltage and sent it to us. But, from where does it gets the voltage readings? Mama - Dallas has configured the chip to read the voltage on VDD pin, but we want to use the VAD pin, which is connected straight to the source (the battery pack). So we must reconfigure it. How? Guessed right... back to theory.

The most important page of the scratchpad of the DS2438Z is page h00 or the first page. The page looks like that, it's important to note:

 

Page_h00

 

This page like the others consists of 8 Bytes of data. The first Byte which is the most important to us is the Status byte. It tell us whether a convertion is over ( voltage(ADB) - temperature(TB) ), if the copy from scratchpad to EEPROM is done(NVB) ( COPY SP function) and the on board configuration.

If the IAD is setted to 1 then current measurements will be taken at the rate of 36.41Hz.

If the CA is setted to 1 then the current accumulator is working. The current accumulator shows as how much current is going in and out the battery pack, but I won't be using it probably in this tutorial so I won't get any further.

If the EE is setted to 1 then the current accumulator data is saved on the EEPROM of the chip, we are not intrested in here neither.

And finally what we wanted from the begining. The AD status bit. This bit if set to 1 the voltage measurement are taken on the Vdd pin. If setted to 0 then the current measurements are taken on the Vad pin.

So we must set this bit to 0. How? Well the first byte of the first page of the DS2438Z looks like this:

 

 

Status_byte

The acronames were displayed previously.

 


Now, X, ADB, NVB, TB can NOT be written, although if mistake occurs that doesn't mean you lose the device. We can only write bits AD,EE,CA,IAD.

In it's binary form this byte comes from mama - Dallas like that:

00001111 or in HEX h0F

 

We want to convert this to:

00000111 or in HEX h07

 

So here is what we'll do in a simples flowchart - table (everything which has a h infront of it is hex code)

 

1. We reset the device.

2. The device repplies with a presence pulse.

3. We write to the device hCC which is the SKIP ROM function in order to access the IC immediately.

4. We write to the device h4E to issue a write to scratchpad function.

5. We write to the device h00 to select the page of the scratch pad.

6. We write to the device h07 which is the first byte we wanted to write to the device as shown.

7. We reset the device to end the write sequence prematurly.

8. The device repplies with a presence pulse.

9. We write to the device hCC to SKIP ROM.

10. We write to the device h48 to issue a Copy SP to EEPROM command. This way we store the changed

byte we previously sent.

11. We write to the device h00. This determines the page of the SP copied to EEPROM, we changed page h00

or the first page of the device so this is the one to copy to the EEPROM.

12. We wait 20msec. The Copy SP to EEPROM usually takes 10msec, but just to be secure we wait a little bit

more.

13. We reset the device.

14. The device sends back a presence pulse.

15. We write to the device hCC to SKIP ROM.

16. We write to the device hBE to issue READ SP command.

17. We write to the device h00 to determine the page of the scratchpad we want to read. (h00 - first page)

18. The device sents as 9 bytes. The 8 Bytes of page h00 and a CRC (don't care).

19. We see if Byte 0 matches our pattern (00000111). If yes we are ok!!! If not, you did something wrong.

Of course as soon as you read the first byte do don't have to read the others. So you can issue the reset

earlier if you like.

20. The device after the reset sends a presence pulse. We are done!!!

 

Now we have the device ready and set!!! Nice!!! But since reality is not that theoritical let's see how the code is like. I program in BASIC. It's a easy to learn language which is based on structured programming, so by learning basic which is a enter to Matrix language, you can easier go to C, C++ and other languages that are based on structured programming. Since I use the ATMEL family microcontrollers, I use the BASCOM compiler to write my programs. The free version supports 4 kB of code, which is enough for us now. You can find it at:

http://www.mcselec.com/index.php?option=com_content&task=view&id=14&Itemid=41

 

I assume you 've already have installed and opened the program. Here is the part of code we need to write to reconfigure the device as shown above.

 

' --------[ Device Config]----------------------------------------------------

$regfile = "m16def.dat"
$crystal = 16000000
$baud = 9600


' --------[ LCD Config ]------------------------------------------------------

Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.5
Config Lcdpin = Pin , Db7 = Portc.4 , E = Portc.1 , Rs = Portc.0
Config Lcd = 20 * 4


' --------[ Port Config ]-----------------------------------------------------

Config 1wire = Portb.2


' --------[ Variable Config ]-------------------------------------------------

Dim I As Byte , W As Byte
Dim Crc As Byte
Dim Table(3) As Word
Dim Status As Byte
Dim Thresh As Byte
Dim Reg_no(8) As Byte

' --------[ Characters ]------------------------------------------------------


' --------[ Initialize ]------------------------------------------------------

' Start

' At first we reset the device.
1wreset
' The ATMEGA automatically receives the presence pulse and ignore it.
' Then we skip the ROM.
1wwrite &HCC
' Then we issue the write to SP command.
1wwrite &H4E
' And now we select the page of the scratch pad we want to write in.
1wwrite &H00
' Since we want to write on one byte we sent only one.
1wwrite &H07 ' 07 = 0000 0111
' And we issue reset to stop the write sequence.
1wreset
' And the device gives as back a repply, we ignore it.
' And we skip ROM again
1wwrite &HCC
' Now we copy what we writed on the scratchpad in the EEPROM to secure the data.
1wwrite &H48
' And we select the page to be copied.
1wwrite &H00
' We wait some time so the whole thing is over.
Waitms 50
' And we reset the device.
1wreset
' Again we ignore the presence pulse.
' And now we read what we wrote... if correct we are ok!!!
' First skip the ROM
1wwrite &HCC
' Then we issue the read scratchpad function
1wwrite &HBE
' And we select the page we want to view
1wwrite &H00
' And now... start sucking data baby!!!
' Note: Status is a variable.
Status = 1wread()
' And we see what we have done in binary form!!!
Lcd Bin(status);
' If it's 00000111 we are free to go!!! Nice doing!!!
End 'end program
' Don't forget the End command and leave the processor hanging....

 

Now let's get a program to enable us to read the temperatute, the voltage and the current reading. DS2438 doesn't write all these data on the scratchpad, but on the EEPROM. That's why we have to recall the memory, to have the data written on the scratchpad so the master can read 'em. REMEMBER a 1wire device and a microcontroller (master in general) can only communicate through the scratchpad. So we first issue a RECALL MEMORY function and then we read the scratchpad... So here is the program:

' --------[ Device Config]----------------------------------------------------

$regfile = "m16def.dat"
$crystal = 16000000
$baud = 9600


' --------[ LCD Config ]------------------------------------------------------

Config Lcdpin = Pin , Db4 = Portc.3 , Db5 = Portc.2 , Db6 = Portc.5
Config Lcdpin = Pin , Db7 = Portc.4 , E = Portc.1 , Rs = Portc.0
Config Lcd = 20 * 4


' --------[ Port Config ]-----------------------------------------------------

Config 1wire = Portb.2


' --------[ Variable Config ]-------------------------------------------------

Dim I As Byte , W As Byte
Dim Crc As Byte
Dim Temp1 As Byte , Temp2 As Byte
Dim Tempfix As Word
Dim Table(2) As Word
Dim Status As Byte , Thresh As Byte
Dim Reg_no(8) As Byte

' --------[ Initialize ]------------------------------------------------------

' Main routine - The program will be executed continiously
Cls
Cursor Off
Lcd " DS2438Z Report "
Lowerline
Do
' Reset the device.
1wreset
' SKIP ROM.
1wwrite &HCC
' Issue temperature convertion.
1wwrite &H44
' Each temperature convertion takes 10msec, better wait.
Waitms 10
' Reset the device.
1wreset
' SKIP ROM.
1wwrite &HCC
' Issue voltage convertion.
1wwrite &HB4
' Each voltage convertion takes 4msec, better wait.
Waitms 5
' Reset the device.
1wreset
' SKIP ROM.
1wwrite &HCC
' Issue a RECALL MEMORY function on page h00.
1wwrite &HB8
1wwrite &H00
' Reset the device.
1wreset
' SKIP ROM.
1wwrite &HCC
' Issue a READ SP function on page h00.
1wwrite &HBE
1wwrite &H00
' Start sucking data
Status = 1wread()
Temp2 = 1wread()
Temp1 = 1wread()
For I = 1 To 2
Table(i) = 1wread(2)
Next
1wreset
' Display temperature
Lcd " Temp: "
Shift Temp2 , Right , 3
Lcd Temp1
Lcd "."
Tempfix = Temp2 * 3125
If Temp2 > 32 Then
Lcd "0"
Lcd Tempfix
Else
Lcd Tempfix
End If
' Change line
Thirdline
' Display current measurements
Lcd " Drain: "
' Here I multiply current readings with 66.7
' This number represent an equalation based on the
' sense resistor. Please refer to the datasheet for more info.
Table(2) = Table(2) * 66.7
Lcd Table(2)
Lcd " mA "
' Change line
Fourthline
' Display voltage measurements
Lcd " Voltage: "
Lcd Table(1)
Lcd " mV "
Home
Lowerline

Loop ' Loop

End 'end program

 

And the results of the program. A image can be very rewarding:

DS2438_LCD

Note that in the picture voltage is at 4.35V. I was just too lasy to fix this..... sorry...

 

Ok, by now you should know how to operate the DS2438. Here is the schematic suggested by me for the device.For Rsense refer to the datasheet. The bigger the value, the less current can be measured, but the higher the sensitivity is. Enjoy:

Schematics

 

Hope, you have understand the basics of the DS2438Z IC for more informations and functions refer to the darasheet. It would also be very nice to hear from you. IMPORTANT: I'm NOT an engineer, just a high school student, so my help is strictly limited. E-mail at: tricky_nekro@hotmail.com but please don't expect I'll build or test anything for you. I can only answear to some basics!!!