Coding Trouble

lstrike

New Member
I am working on a remote control tank and am having trouble getting the motors to work.

I am using a Picaxe 14M2 to work the motors and I entered these commands to test the motors:

left track moves forwards:
high b.2
low b.3

right track moves forwards:
high b.5
low b.4

left track moves backward:
high b.3
low b.2

right track moves backward:
high b.4
low b.5

The motors work fine when using one at a time, but when I try to make them work together, they don't do anything.

This is a schematic of my project:



This is how my project's code works.
Code:
nomad:
  irin c.2, b0
  select case b0
  case 18
    high b.2
    low b.3
    high b.5
    low b.4
  case 19
    high b.3
    low b.2
    high b.4
    low b.5
  case 16
    high b.2
    low b.3
    high b.4
    low b.5
  case 17
    high b.3
    low b.2
    high b.5
    low b.4
  case 94
    tune c.0,8,($00)
    tune c.0,8,($00)
    tune c.0,8,($00)
  end select
  goto nomad
I can get the infrared sensor on my project to work, but when I try to use the code to move both treads at once, they don't do anything. The remote I'm using can work the piezo buzzer though.

Any help would be appreciated.
 
Last edited by a moderator:

Hemi345

Senior Member
Your schematic isn't showing up. If you're trying to drive the motors directly off the pins of the PICAXE, you're going to have problems since each pin can only source something like 25mA max.

Try putting some sertxd ("") statements in your code so you can watch it through the terminal (F8 key brings up the terminal) to see if the program is hanging up on something or resetting because of power dip. Like at the top of your program, put:
Code:
pause 1000
sertxd ("Program has started",13,10)
and then something like this in each case statement:
Code:
case 18
sertxd ("Running case 18.",13,10)
high b.2
low b.3
high b.5
low b.4
I use this all the time to debug and really helps to see what's happen each step of the way. Then remove them when all is working as expected to optimize the speed of the code.
 

westaust55

Moderator
I have placed your code listing in code tags and also applied some indenting which makes reading the code and flow far easier to read/understand for others trying to help.

We certainly need to see the schematic to understand how the motors are connected.

Please ensure you also indicate the power supply - whether the PICAXE and motors have separate supplies or using a common power source
Motor rating – voltage and current
What decoupling capacitors and/or free-wheeling diodes, etc are provided.
 

lstrike

New Member
nomad circuitboard 2.PNG

In case the schematic doesn't come up again, I am using an L293D in conjunction with the Picaxe 14M2. Four of the Picaxe's output legs go to each of the L293D's inputs, and the motors connect to the L293D's outputs with a 0.1 uF capacitor between the motors. The motors I'm using are the FA-130 type motors that come with the Tamiya Double Gearbox.
 

lstrike

New Member
nomad circuitboard 2.PNG

I am using an L293D in conjunction with the Picaxe 14M2. Four of the Picaxe's output legs go to each of the L293D's inputs, and the motors connect to the L293D's outputs with a 0.1 uF capacitor between the motors. The motors I'm using are the FA-130 type motors that come with the Tamiya Double Gearbox.
 

Ravenous

Member
Are you running it off 5V? That probably means only 3V are getting through to the actual motors. That may not be enough, depends on the motors...
 

Hemi345

Senior Member
I'd add some bulk caps, like 100uF, near the PICAXE power pins and the L293D.

Does the following program make it work?

Code:
#picaxe 14m2
#no_data
main:
    low b.3,b.4
    high b.2,b.5 ;run both tracks forward
    pause 2000
    low b.3,b.4,b.2,b.5  ;stop both tracks
    pause 1000
    goto main
 

westaust55

Moderator
What is the source of the 5 V power supply?
3 x AA batteries or something bigger?

What is the current rating and voltage for the motors? Link to a Datasheet would help.

As already mentioned, due to some volt drop across the L293D the motors will have lower voltage available to them.

I suggest try a 6 Volt supply and then Use a diode and 100 uF electro on PICAXE side of the diode to power the PICAXE and logic supply side of the L293D (pin16). Have the 6V (or higher) direct only to pin 8 on the L293D chip.
That way, any dips in volts when 2 motors try to start should not cause the PICAXE to reset.
 

westaust55

Moderator
Looking at the L293D Datasheet:
http://www.ti.com/lit/ds/symlink/l293d.pdf

It can be seen that at 600 mA (max rated current) the outputs when low are typically 1.2 volts above 0 volts and the output that is high can be 1.4 to 1.8 volts lower than the supply voltage so on 5 volts, as already indicated by Hemi, the motors may be lucky to have around 2.4 volts any maybe less if the battery is a set of low capacity cells.
 

lstrike

New Member
There's something else, if I use more than 6 volts on anything except the motors, such as the Picaxe, I'll destroy it. Could you recommend some form of power regulator so that doesn't happen?
 

BESQUEUT

Senior Member
I am running it off of 3 AA batteries, so 5 volts.
If you are using rechargeable battery, you will get no more than 3,9 V
With three 1,5 V cells, no more than 4,5 V...
Of course, il you use 6V source for the motor, you need a 5V regulator (IE LM7805) for the Picaxe.
 

Technical

Technical Support
Staff member
If the motors run individually then the power supply voltage level is obviously ok, so forget about changing the voltage for now. Your L293D circuit is ok, assuming it is a 'genuine' L293D and not one of the inferior equivalent chips.

What is probably happening is that the PICAXE is resetting when you energise both motors. To test this add these lines to the top of your program

#terminal 4800
pause 1000
sertxd ("reset")

You can then see on the computer screen every time the reset occurs.

This occurs because the motors draw a much larger inrush current as they start. There are various simple tricks to help avoid this:

1) Make sure the gearboxes are well aligned and well greased to reduce friction. Make sure the tracks are not too tight between the drive wheels.
2) Add some larger capacitors (220uF to 1000uF whatever you have) across the power rails.
3) Add a small resistor e.g. 10 or 12 ohms in series with the motor (ie in one of the motor connection wires).
 

westaust55

Moderator
There's something else, if I use more than 6 volts on anything except the motors, such as the Picaxe, I'll destroy it. Could you recommend some form of power regulator so that doesn't happen?
Notwithstanding the advise by Technical, 3 AA cells is at best typically 4.5 volts and 4 x 1.5 volt cells gives 6 volts.
In my earlier post I suggested 6 volts with an isolation diode (eg 1N4001 or similar) which will drop about 0.7 volts thus 5.3 volts to PICAXE and L293D logic. In conjunction with the 100 uF electro I also mentioned (post8) on PICAXE side of the diode this can help prevent resetting of the PICAXE.
 
Top