Making a pwm almost endless loop
Ady111
Posts: 15
Hello, i have some questions about a project that i build. I have to control using pwm signal 5 motors.
First is a brushless motor that has ESC, so i need a PWM to set it's speed. This motor should run from the start to the finish of the prcess with constant speed, so it needs a permanent signal, but constant.
There are 2 more little brushed motors controlled by transistors, therefore i need PWM signal to control their speed. This motors should run only in specific situations(sensor activation), and should run independently.
And finaly 2 servo motors. For this i need PWM signal to set their angle. This should run independently and only in some cases.(when a sensor is activated).
When a third sensor is activated the brushless motor should stop(finish of the process).
My concern is about generating the PWM for the brushless motor, beacause it has to run all the time until one sensor is active, but in this time i have to make some monitoring process of the sensors and comands for the other motors and i'm afraid it will stop when i make the interogations.
Is there a way to set a pin of the bs2 to generate endless PWM signal while i'm using the others to check sensors and generate other PWM signals?
P.S. It's not abslut necessary to stop the brushless motor at the end of the process, i can turn it off manual eventually.
Any sugestion is welcomed. Greetings
First is a brushless motor that has ESC, so i need a PWM to set it's speed. This motor should run from the start to the finish of the prcess with constant speed, so it needs a permanent signal, but constant.
There are 2 more little brushed motors controlled by transistors, therefore i need PWM signal to control their speed. This motors should run only in specific situations(sensor activation), and should run independently.
And finaly 2 servo motors. For this i need PWM signal to set their angle. This should run independently and only in some cases.(when a sensor is activated).
When a third sensor is activated the brushless motor should stop(finish of the process).
My concern is about generating the PWM for the brushless motor, beacause it has to run all the time until one sensor is active, but in this time i have to make some monitoring process of the sensors and comands for the other motors and i'm afraid it will stop when i make the interogations.
Is there a way to set a pin of the bs2 to generate endless PWM signal while i'm using the others to check sensors and generate other PWM signals?
P.S. It's not abslut necessary to stop the brushless motor at the end of the process, i can turn it off manual eventually.
Any sugestion is welcomed. Greetings
Comments
The ServoPAL and the Propeller Servo Controller are external devices that take over the burden of issuing these individual PWM pulses on a regular basis. The Propeller Servo Controller can also be programmed to handle sensors, communications, etc.
Neat item, they pop up on Ebay occasionally as well.
pulseout 13, 450
pause 18
with this 2 comands i manage to send the propper pwm to run the motor. For 450 the motor stops. While running i incrised the number until 670, when i reached the speed that i wanted. Maybe this help you.
I think it should work also with 20 pause.
What you want to do is definitely not a beginner's project and it's probably quite marginal with a Stamp without external hardware. It's not something we can show you how to do in a forum setting. You'd have to become quite good at Stamp programming yourself and use the Robotics with the BoeBot tutorial as a base along with Roaming with the PING))).
pwm=450' stop motor on pin0
servo1=750 'center servo1 on pin1
servo2=750 'center servo2 on pin2
start:
pulsout 0,pwm ' set motor speed
pulsout 1,servo1 ' set servo1 position
pulsout 2,servo2 ' set servo2 position
gosub sensor1
gosub sensor2
gosub sensor3
if sense1=x then pwm=670 else pwm=450 ' change motor speed if sense1=x
if sense2=y then ... ' add your own condition 2
if sense3=z then ... ' add your own condition 3
pause ??? ' adjust this pause value to yield a 20 ms pause including sensor checks and IF checks
goto start
sensor1:
...
return
sensor2
...
return
sensor3
...
return
The loop needs to execute about 50 times per second to keep the servos supplied with a pulse each 20 ms. If your total sensor readings and code take a lot of execution time, longer than 15 ms or so, you may have to get tricky and only read one sensor per loop, and rotate through which sensor gets read. You could do a for/next loop for that. Hope this helps!
Edit: Mike beat me to replying! We're in agreement that it's gonna be close on Stamp capability and you'll have to poll your sensors individually. Give it a whirl and let us know how it goes.
start:
send 3 pulsouts
read sensor 1
If check...
pause n1
send 3 pulsouts
read sensor 2
If check...
pause n2
send 3 pulsouts
read sensor 3
If check...
pause n3
goto start
You could control the pot via the BS2 using the digital pot. http://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/246/Default.aspx?txtSearch=digital+pot
A PWM controller can really open up your BS2 project.
a:pulsout 8,650
pulsout 2,680
pause 20
goto a
Anyway, post you code so we can see what you're trying to do.
PAUSE 2000
FOR i=1 TO 200
PULSOUT 8, 450
PAUSE 10
NEXT
FOR i=1 TO 250
PULSOUT 8, 500
PAUSE 5
NEXT
FOR i=1 TO 250
PULSOUT 8, 550
PAUSE 5
NEXT
FOR i=1 TO 250
PULSOUT 8, 600
PAUSE 5
NEXT
program:
PULSOUT 8, 650
PAUSE 20
GOTO program
with this loop i managed to start the brushless motor in ramp mode and keeping it on the speed i desire. I have to add now the comands for the servos and the brusheds.
The BS2 can handle sensors no problem. You decided to use the STAMP as a PWM controller and that's fine. It does not mean the STAMP can't handle sensors.
Here's a simple example. Do not use this with your motors as it uses the DEBUG command and a 1 second pause. At some point you'll also need to update speed/position values and that takes time as well.
Good luck... I'd pick up a PWM controller.