Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:03 17 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PWM question

Author Message
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2934
Posted: 02:42pm 11 Feb 2016
Copy link to clipboard 
Print this post

I have a scenario where I'm using a 28pin MicroMite (MMBasic v5.1) to control a robot buggy driven by two motors. Simply using PWM 1A and 1B to control the speed of the motors via a dedicated motor-driver chip.

Because I am using the inbuilt PWM commands, once the values are set, the motors continue to spin until I send the PWM STOP command. In practice, if the robot is moving quickly, then issuing a STOP command results in a sudden 'jolt' as the robot instantly stops. So I added a gradual decrease of PWM values to all my subroutines to bring the robot to a 'gentler' stop. All this is working great. (I also implemented a gradual increase in PWM when the robot starts to move).

As previously stated, all this is working really well whilst the program is running; but if I then stop the program (with Ctrl-C), the robot will continue moving until I issue the PWM STOP command (or enter the editor, in which case MMBasic terminates PWM automatically).

So adding a MM.Prompt sub to automatically issue the PWM STOP command prevented the robot from 'running away' and out of sight! BUT the robot will suddenly stop with a horrible 'jolt' which is not at all desirable.

So my thoughts now are to understand the current values that the PWM is running at so that I can then decrease from these values to a gradual 'standstill'. Sounds simple but two hours later . . . . .

Does anyone know if there is a way of determining the two following things directly from MMBasic:
1> to know if PWM is currently set (or stopped)
2> if it is set, to 'read' what the current value is

I know I could do this with a couple of variables which are 'updated' whenever I renew the PWM values, but is there a way to interrogate MMBasic somehow (such as a 'PEEK')?

Thanks,
WW
 
skylight
Newbie

Joined: 10/01/2016
Location: United Kingdom
Posts: 23
Posted: 08:15pm 11 Feb 2016
Copy link to clipboard 
Print this post

As a noob to the Micromites I probably shouldn't try to give any advice but wondered if your Ramp down subroutine could be incorporated into the MM.Prompt sub somehow?
I have an activity bot that has the ramp up and down routines programmed into eeprom from a previously run calibration program but the bot also uses encoders on the wheels to work out the speed/direction they are travelling, not much use to you I know and not what you are asking but perhaps it means you may have to resort to external circuitry to achieve this?Edited by skylight 2016-02-13
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2934
Posted: 09:59pm 11 Feb 2016
Copy link to clipboard 
Print this post

@skylight

Yes, that is what I am wanting to do; but I wish to start the 'Ramp Down' from the current value.

If the buggy is already slowing down when I 'Ctrl-C' the program, I don't want the robot 'ramp-down to start from 'max' value as this will result in the robot speeding up first (hope you follow me).

Knowing the current values would make this task easy.

Sleeping on the issue last night, I think I will have to use two variables (one for each motor value. Was trying to avoid yet more variables in the program though . . .

WW
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2949
Posted: 03:23am 12 Feb 2016
Copy link to clipboard 
Print this post

GDay Phil,

Can you disable CTRL-C and then in your code check for a CHR$(3) and then run your PWM down to zero and exit the program gracefully?

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
f1fco

Senior Member

Joined: 18/03/2012
Location: France
Posts: 155
Posted: 04:53am 12 Feb 2016
Copy link to clipboard 
Print this post

hello WW,
perharps the solution is in the word "progressivity"
if you want jump between 2 values of speed of your robot (v1 : actual value and v2 : future value), use :
FOR value=v1 TO v2 'or v2 to v1 ... if v2<v1
PWM 1, value
PAUSE x 'to adjust...
NEXT value

to stop the motor, you can use a duty cycle of 0

I am in the act to build a "rover" with 4 wheels (and 4 motors) (front left, front right, rear left and rear right)
on the "base station", I use a joystick and a Micromite
I send by radio (UHF on 433 MHz), the value of the jostick :
0 to 1000 for front/rear and 0/1000 to left/right
a value near of 500 is immobility
0 is full rear (or full left) and 1000 is full front (or full right)

my rover is like this
https://www.sparkfun.com/products/10336
and motor controller RS011MC
http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_2150539_-1

each motor need 2 informations : direction and value of PWM
I can calculate these from the value 0 to 1000

I am working on this project
I can post when it was OK

Pierre, from Nimes, south of France
73s de F1FCO
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025