Saturday, June 21, 2014

pic16f628 and USART via a max232 chip

Max232 chip and associated capacitors.  3.5mm jack on the right.

While I was thinking out pennybot I was wondering how I could get more debug information out as the single blinking led I have currently isn’t much.  I remembered that the pic16f628 had usart onboard so a read up on it.  Only two pins were needed with a max232 chip to handle the voltage pumping to a RS232 connection. Sounded pretty easy.

However before this point I needed a usb to serial dongle and a serial terminal program for my Mac.  I already had a usb/serial adapter based on the pl2302 chip, a cheap ebay purchase.  I searched around and found the necessary drivers for Mac so the pl2302 would be detected.  Google is your friend for that.  For a terminal program some people suggested using the ‘script’ command but that didn’t work very well.  I then tried CoolTerm which was great and I fully recommend it.

For the max232 chip (and associated capacitors) I knew that I would want to use it both on my breadboard and possibly on future pic projects.  A standalone board was the best option.  I had a 4 pin (5v, GND, RX, TX) male header to connect the board to a breadboard or circuit and a stereo 3.5mm socket to connect the serial cable to.  The serial cable was a recycle job were I got an existing 9 pin cable, cut off one end and wired up RX, TX and GND to a 3.5mm male stereo plug.  It’s smaller than a full 9pin shell and is quite robust.  Now I will be reserving the USART pins on pic projects in future and having a 4 pin female header so I plug in my max232 board when needed.

Sunday, November 24, 2013

Pennybot full pictures

I forgot to show off some full pictures of pennybot almost complete.  I still have the front and rear shields to make for the chassis.  Also I'm thinking of moving the single rear IR detector to be at the front centre.  After that it will be programming tuning.



Monday, October 7, 2013

IR top board

















Top board

The IR board consisted of five IR detectors (and 0.1uF capacitors) and five accompanying IR leds.  There was also the PWM booster transistors and variable resistors to control the range of the IR leds.  I needed to be careful to try and avoid the PWM lines and the IR detector cabling from interfering with each other.  Otherwise the 38khz on the PWM wires could cause the IR detectors to falsely trigger.  So all the cabling was kept apart or if the wires had to cross then I tried to do so at right angles to reduce EMF.

Once all the parts were soldered up I did detection tests by measuring the voltage on the signal pin of the IR detector.  I found that to get the range I wanted I was almost at minimum resistor value of the IR led variable resistor circuit.  Instead of 100 ohms and a 1K variable resistor I probably should have gone of the absolute safe minimum of 50 ohms and a 500 ohm variable resistor.  However what I have worked ok.

Initially I was driving 3 IR leds off one transistor for the right side/left side / rear leds.  However I wasn't getting any signal from two of the IR leds.  It seems with the resistor value so low the voltage drop across the 3 leds was more than 5V.  The first led in series worked, but the second and third leds didn't.  I worked this out by measuring the frequency on the led pins and finding only the first led was at 38khz.  The others were zero.  However there was still voltage on each pin.  Odd.  So I added a third transistor of the rear IR led.  This means I have three transistor / resistor circuits for the leds.  One for the front two leds, one of the two side leds, one for the single rear led.  Perhaps I might add a second rear led, but space is very tight on the rear of the board.

With the IR detectors the two side detectors were up high and peering over the wheels.  Originally the front IR detectors were on top of the board looking down.  However due to the height of the front board this left a blind spot right at the front of pennybot.  Not the place you want a blind spot.  So I desoldered the front IR leds and detectors and put them under the board to get them lower.

Tuesday, September 3, 2013

Motor drive tests with SN754410


With the pic and SN 754410 ready to go it was time for a motor drive test.  But first the motors needed to be fixed up.  I did the standard practice of soldering 0.1uF capacitors from each motor terminal to the motor body and another capacitor across the motor terminals.  Then the wires from each terminal were twisted together and terminated in a 2 pin female header.

For the drive test I modified my full pennybot code and did a simple forward/back/left/right test.  Worked well but forward/back were backwards.  A quick modification in the code fixed that.  Also my dual colour leds were not symmetrical.  On forward one led was green, the other red.  So I flipped around one the leds and fixed that.  Probably could have worked that one out when initially soldering but I knew that I might get it wrong regardless so it was quicker to just do and fix if needed.

The drive test also showed one motor was slightly faster than the other.  Over a number of iterations pennybot was slowly turning around on it's starting position.  Nothing to fix there but it's good to be aware.

Now was time for the push test against Dumbbot, my first sumo bot which has only edge avoidance, no detection of opponents.  Both bots weighted in at 320gm.  Head to head pennybot couldn't move a stationary Dumbbot at all.  Those Tamiya rubber tyres Dumbbot hava obviously grip very well.  Dumbbot however with a much more geared down drive train and rubber tyres can push pennybot no worries at all.  Those skinny tyres Pennybot has just don't have the grip.  I can see why people buy the super sticky version of the tyres.  Hopefully at full 500gm weight things will be different.  As far as speed goes Pennybot approx. three times faster than Dumbbot.  So a design battle of strength vs speed will be had…once Pennybot has some eyes.

Finally since dumb is a rude word for 5 year olds Dumbbot is now know as Slowbot.  Soviet revisionism at it's best.

Sunday, August 25, 2013

Main board with PIC 16F628















PIC 16F628 on the left, SN754410 on the right, LP2950 top right, ICSP top left, line sensor header bottom left, motor header bottom right

The main board of pennybot would consist of the following:

* PIC 16F628 microcontroller
* SN 754410 motor driver
* 5V power supply based around a LP2950
* connector pins for the motors, line sensor board, batteries, ICSP and IR sensor board

Lots to do and board space was limited so planning was needed.  A couple of hours shuffling components around and I had what I thought was a layout that would work.  Starting with the easy bits all the headers and IC chip sockets were soldered in first.  With that taking a couple of hours I started to remember how long it takes to put freeform circuit boards together from scratch.

The power supply was next.  This was also a major deviation from my original design.  Due to space and layout I moved the cutout switch in the circuit and deleted the filtering capacitor on the raw power line.  I also made some brain errors and kept making circuit hookups that meant the cutout switch didn't break the circuit.  Don't solder when tired!  I also had a false error in that when the cutoff switch was activated, I was still getting 5V.  However this was because at that stage I had lots of capacitors and no components to use up the stored charge.  The circuit was being cut but with nothing consuming power it takes awhile (minutes) for 5V to dissipate.  Always have at least a single led to drain out power.

Then it was a slow and steady task of connecting up everything else as per the schematic.  I did the Pic first so I could test the ICSP and make sure that was working before going further.  Whenever I'm wiring things up I like to do a small amount, test for short circuits, test functionality and then go onto the next item.  Trying to troubleshoot an entire board with everything soldered is just a recipe for tears.

For the connector to the IR board I used a 8 pin female header.  This header would double as the mounting socket too.  For the connection to power I decided to solder on the wires to the main board directly, rather than use a removable cable.  The connector would be on the chassis in the form of a female header recessed flush into the base plate.  To strengthen the connection I glued with two part epoxy the power wires on the main board.  I also epoxied the right angle header pins used for the motor and line sensor connections.  Anything that would be frequently connected and disconnected needed some extra support.  

For the most part things went well.  Another change that was made was the pull up resistor on pin RA4.  Originally this was 4.7K but that made the dual colour led very dim (with the red barely visible).  I dropped this to 1K.  I had never done this part of the design on the breadboard as I had used the dual colour leds as motor substitutes.  Always breadboard exactly what you are going to wire up.

Sunday, August 18, 2013

Line sensor board













Line sensor board

Now with a good and hopefully final chassis design it was time to pick up the soldering iron and start making things.  The first of the three boards to tackle was the line sensor board.  It would need to be very narrow to fit between the batteries and the front scoop.  The total parts list is small comprising of two leds, two IR phototransistors, 4 resistors and a 4 pin connector.  The four pin connector would be used for 5V power, ground and the two test point voltages from the sensors.  These voltages would be around 4V on the black surface and under 0.1V on the gloss white surface of the sumo ring edge.

For the four pin header instead of my usual molex connectors I used a standard right angle connector and the new headers I had recently purchased from Little Bird Electronics.  These headers are smaller than the molex ones but don't have a guide slot so can be inserted either way (and also the wrong way).

Once everything was soldered I drilled two holes mounting holes and tapped threads into the chassis.  All this drilling and tapping makes for a much better result but adds to the time.  Once a hole and drilled and tapped, then the bolt has to be cut to size as it can't come past the other side of the chassis base plate.  Much trial and error and test fits and cutting involved.  With the holes ready I used nylon spacers between the board and the chassis to get the position I wanted.

Lastly I made a 4 wire cable to connect to the main board.  Originally I started crimping a ribbon cable but then thought I was sure I already had a cable with a header on it in my salvage box.  Sure enough I did although the four header socket only had three wires.  Still saved some time and crimp pins.

After doing continuity test and shorts circuit tests I wired up the board to my bread board circuit and it worked fine.  Well it did until a further integration test showed the board and thus the sensors were too close to the ground.  The sensor voltages were only differing from 0.3V to 0.1v between the black surface and the white edge.  At the distance to the ground (under 3mm) even the flat black of the sumo ring was being detected.  This was solved by cutting the nylon spacers in half and reattaching the board.  With about 5mm distance between the board and the ring I was getting the behaviour and voltage differences  I wanted.  Next was onto the real work, the main board.

Wednesday, August 14, 2013

Pennybot chassis part 3













A chassis remade sans wheels

With the programming and breadboard design done, and the schematic finished it was time to start working on a board layout.  Not long into this process I worked out the chassis I had wasn't ideal.  It was only 8cm wide but 10cm long.  I didn't have room for a decent front scoop and the line sensors would be a very tight fit.  I was using a Tamiya base plate and I considered that I could simply rotate the board and easily make pennybot wider (out to 9.6cm) without having to change any of the holes I had drilled in the motor brackets which I really didn't want to have to make again.  Also the five AA batteries could now be mounted across the width of the chassis instead of along it so I would have more space at the front/rear and the centre of gravity would be all along the wheel axles.  I decided to cut down the motor brackets too so that they would only be the length of the motors themselves.  All this took a few hours on a Saturday.  The result was a wider pennybot with a better battery placement, but I had swapped one set of issues for another.  The Tamiya board is only 6cm wide, thus with the motors brackets and batteries there wasn't very much room (ie free 3mm holes in the board) on the front or rear to attach sensors, circuit boards, etc.  I could buy a bigger Tamiya board but had just done an order to Little Bird electronics and didn't want to pay postage again.  With a big sigh it was time to make a new chassis (number three) from scratch.

For my new chassis I wanted to make sure I remembered to do some key points.  I can get lost in problem fixing and forget the wider implications of design choices (and regret them later).  For all the mounting holes rather than drill straight through I would drill and tap 3mm threads.  This way I wouldn't need any bolts and wouldn't need space for the nuts.  That did mean I would have to cut down every bolt to size.  Bless the dremel.  I also wanted the base plate to be as big as I needed it.  Ie 10cm long and approx 8cm wide as the wheels and axles shafts would take the width to 10cm.  Looking through the scrap box I found an old plastic electronics project box which I never got round to using.  The box was curved on each side so cutting one half in the middle would give me a pre made scoop.  Also the dimensions fitted.  Some quick hacksaw and dremel work and I had a new base plate.  I put the axle shafts at the midway point and drilled and tapped the mounting holes.  I wasn't sure if the tapped screw holes into the plastic would be strong enough but they held.  Then the 5 AA batteries were placed underneath and things were looking good.


















Batteries and sneak peak at the sensor board

Next up would be the front line sensor board.