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 : Best way to drive a small motor?
Author | Message | ||||
Plasmamac Guru Joined: 31/01/2019 Location: GermanyPosts: 554 |
Hi , At the moment i use a L298n bridge to drive a small motor with < 12v and max 1 A. To turn on i use setpin;. But i need a softstart and softstoo . Maybe with PWM . But how to use it ? Any ideas? Thx Rpi pico , last beta Edited 2023-07-27 09:55 by Plasmamac Plasma |
||||
Bill.b Senior Member Joined: 25/06/2011 Location: AustraliaPosts: 226 |
Hi plasma I have used the LM298N to control motors on a robot car using a picaxe. connecting the EN inputs to the PWM output enables speed control. By using a loop in the program to increase the PWM output you can simulate soft start of the motors. Bill In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Yes, PWM is how you do it. Here is an example code from an experiment I was doing: SetPin GP2,PWM 'PWM 1A SetPin GP3,PWM 'PWM 1B MRPM=65 RDLY=25 For X=0 To MRPM PWM 1,10000,X,0 Pause RDLY Next X Pause 5000 For X=MRPM To 0 Step -1 PWM 1,10000,X,0 Pause RDLY Next X Pause 3000 For X=0 To MRPM PWM 1,10000,0,X Pause RDLY Next X Pause 5000 For X=MRPM To 0 Step -1 PWM 1,10000,0,X Pause RDLY Next X This code ramps the motor up to whatever you set the MRPM variable to, and then pauses for five seconds, then ramps the motor back down again to stop. It pauses three more seconds, then does the same ramp-up/ramp-down in reverse. Change the value of RDLY(ramp delay) to alter how fast or slow the motor ramps up and down. You need two PWM pins for full control of forward and reverse. That example code should get you going, and you can expand on it from there. Edited 2023-07-27 14:29 by Grogster Smoke makes things work. When the smoke gets out, it stops! |
||||
Plasmamac Guru Joined: 31/01/2019 Location: GermanyPosts: 554 |
Thx a lot for the infos ! Plasma |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
Hi Plasma, Bill's circuit is identical to your setup (as I read from post #1). He uses a single PWM, and independent GPIO lines for the direction of the motor. Grogsters program uses the one PWM for direction forward (or left), and the other for direction backward (or right). He uses a different motor driver chip, or he connects both PWM's to the 2 direction pins on the L298, and keeps the enable static active. Volhout Edited 2023-07-27 22:04 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Yes, forgot to mention - I use a different PWM motor controller, but I HAVE seen controllers, that only have ONE PWM input, and a DIR input.(direction) Pull it high, the motor will go in one direction, pull it low, it goes the other. I used these driver modules because I happened to have some in my collection. You probably don't need anything quite that grunty though. Smoke makes things work. When the smoke gets out, it stops! |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
The L298 is very inefficient and loves converting your available power into heat because it has a high voltage drop (2-3V at 1A). If the motor will never have its direction changed unless it's stopped then the best way to get a direction change is with a suitable DPCO relay, then a simple mosfet driver from PWM will be fine for the speed. Everything will run cool and efficiently. When you want to change direction, ramp the speed down to zero and flip the relay over then ramp up again. If you don't do it this way then you could destroy the mosfet. If you use separate forward and reverse SPCO relays then you can arrange them such that the motor is short-circuited with power off (or both relays energised). This gives a rapid stop, which can be very useful. Edited 2023-07-28 16:37 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Bill.b Senior Member Joined: 25/06/2011 Location: AustraliaPosts: 226 |
As Mick suggested, If motor direction is required use a relay and a Mosfet to power the motor. Bill In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
Print this page |