Control motors and servos at the same time

luger

Member
Hi,
I am a new member of this forum and I want to learn something to program and control Picaxe.
Sorry for my english :)

I have a 40X2 and I want to control two DC motors and three servos at the same time.
Question:
Which pins should I connect motors and servos to?
I created two program codes - one for motor control, the other for servo. Separately they work well, but when combined into one - servo ok, but the motor cannot be controlled (PWM).
Where is the error?

Connected pins:

motor - pin C.1 and B. 5 (driver L239D)
servo - pin B.1 or B.3 or B.6

external voltage sources, ground is common

thank you very much
 

luger

Member
For the administrator:
I'm not a robot! :)

login confirmation not delivered (not even in spam)

is my log active? what is wrong ?

Thank you
 

Goeytex

Senior Member
Welcome.

Perhaps describe your application a bit better. What is it? The more folks know about what you are trying to accomplish the better the help will be.

Unfortunately per Manual 2 ( Servo) page 220 under Information:

"Servo cannot be used at the same time as timer or pwmout/hpwm as they share a common
internal timer resource
."


This does not necessarily mean that it cannot be done with a Picaxe. There may be possible alternative methods or workarounds depending upon your application requirements.
 
Last edited:

luger

Member
Sorry, I was wrong in expressing and describing the problem.
The Picaxe 40X2 has two internal timers. Or not?

Step by step:
Code 1:
1. the sensor switch on
2. the servo is running
3. servo stop

Code 2:
1. switch another sensor
2. DC motor running (PWM)
3. motor stop

The two codes run independently of each other and run OK.
Once I put them in one integrated code program, the servo runs, but the motor cannot be controlled via PWM
 

Goeytex

Senior Member
That is exactly will happen if you use "servo" and "hpwm" in one integrated code program, as they share the same timer. Each time servo is called it will change the settings for HPWM. Therefore they cannot run concurrently. One or both will fail. This is not a PIC limitation but a limitation of Picaxe Basic. Picaxe Basic does not give the user direct access to the timers or CCP modules, like for example, the same PIC (18F45K22) compiled with XC8.

Again, post your Picaxe BASIC source code for better help.
 

luger

Member
ok I understand.
so the correct way to run the code:
Motor run, motor stop, servo run, servo stop etc..

I will end the motor control with the command, for example - low C.1 and low B.5

How do I properly end the servo command so that the timer allows the (PWM) motor to be controlled again?
example:
servo B.1, 0 ?

I'm a beginner but I'm trying :)
 

erco

Senior Member
You can do servos and motor on/off/reverse (no speed control, no PWM) simultaneously, using mosfets, H-bridges, or relays.
 

luger

Member
I use h-bridge L239D.
The servo works fine, but the motor cannot be controlled or stopped.
As soon as I delete the code for the servo, the motor runs fine. I return the code for the servo and the motor cannot be controlled or stopped again.
Mystery :)
 

Flenser

Senior Member
As soon as I delete the code for the servo, the motor runs fine. I return the code for the servo and the motor cannot be controlled or stopped again.
Mystery
You will need to post your whole BAS program for the forum members to investigate your mystery.
 

Bill.b

Senior Member
The code sample below can be used to operate a servo in place of the servo command.
Code:
Symbol SERVOH           = b.0        'Head servo     
Symbol SERVOLeft      = 150        'Servo Left preset
Symbol SERVORight     = 450        'Servo Right preset
Symbol SERVOCent      = 280        'Servo Center preset
     
     for b1 = 1 to 20             'set servo to center position
        pulsout servoH,SERVOCent
    pause 20
    next b1
I use the L298 H bridge to drive the motor of my robot car, in both forward and revers direction with PWM speed control
The A,B and the C,D input are for the FWD / REV inputs and the EN1 and EN2 for PWM speed control.

Bill
 

Attachments

Top