584,879 active members*
5,186 visitors online*
Register for free
Login
IndustryArena Forum > OpenSource CNC Design Center > Open Source Controller Boards > L297/L298 Bipolar Driver Circuit with Limit Detection
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2011
    Posts
    4

    Post L297/L298 Bipolar Driver Circuit with Limit Detection

    I originally posted this on DesignSpark to give something back for the great, free PCB design app they have provided, figured it's more likely to be useful here, in the CNC community.

    Incidently, I have also designed/built a similar circuit using the Allegro A397X chips, written my own Arduino library for a G-Code interpreter and designed my own app for parsing/transmitting the G-Code to the Arduino (with real-time display of the CNC output) - If you're *really* kind, I *might* post these at a later date

    Dragonlaird

    ===[SNIP]===
    I am building myself a CNC machine based on a programmable Arduino UNO to act as the G-Code interface between the PC and the CNC. I needed to drive the stepper motors and found plenty of ready-made boards I could buy to do the job.
    My first problem was the usual budget constraints - I have been building the CNC for several months, buying parts each month to spread the cost but I couldn't really justify to "she who must be obeyed" that the expense of 3 motor drivers was a necessity. So building the circuits myself was the only way I could break down the cost and come in cheaper than the ready-made boards I had seen.
    The second problem was that my Arduino pins are nearly all in use just controlling the stepper motors and other parts that I've planned/designed into the CNC (such as an optional/exchangeable 3D print head, controlling the main PSU on/off etc). I didn't really have the pins I needed to detect if the CNC had reached its limits (X, Y and Z).
    So I designed this circuit to allow the stepper motors themselves to stop if they reached their limits. At the time I was also considering sacrificing the ENABLE pins of the Arduino/Steppers too, so the circuit enables the stepper motors by default.
    I ordered the PCBs from the US Dorkbot PCB manufacture service at a cost of $5 per square inch, for that you get 3 copies of your PCB - perfect for me as I had 3 motors to drive.
    I had already built a prototype using stripboard and it seemed to work fine but was a little on the large size (about twice as big as the PCBs I had designed) so I was eager to see if my PCB version would work as well as the prototype.
    I built and tested the first board - it worked perfectly. The L298 chip reached about 60 degrees C without any heatsinking, well within the design tolerance, and the rest of the board stayed nice and cool.
    Since it worked so well, I decided I would share the circuit for others to build the boards for their own use.

    The board provides several inputs/outputs and options:
    2 power inputs:
    5V for the circuitry and 5-36V for driving the steppers themselves, although I just used the same 5V supply for both inputs on mine which worked fine for me as my stepper motors were only rated at 3V.
    Enable: (optional)
    Allows you to enable/disable the stepper motor.
    Direction:
    Clockwise or counter-clockwise stepping of your motor
    Step:
    Steps the motor once, toggle this line for repeated stepping of the motor in the given direction.
    Limit Clockwise: (optional)
    Stops the motor from turning clockwise, useful for when a limit switch has been reached. Pulling the limit pin low forces the motor to stop responding to any further step requests in the clockwise direction. The circuit does provide a 0V pin next to the limit pin to just connect a switch.
    Limit Counter-Clockwise: (optional)
    Same as above for the reverse direction
    Step Size:
    Allows full or half-step modes to be used by simply changing a jumper position
    Control Mode:
    Uses a jumper to select between using the inhibit or output methods for control limiting.
    Sync Clock:
    A jumper selects between internal and external Sync options. In External mode it provides a pin for connecting the external sync. I just use the internal clock since the timing of my motor steps isn't that critical and it's all controlled by the Arduino anyway.
    Motor Out:
    4 pins to connect your stepper motor. Remember, this circuit is designed for bipolar steppers only. You need to read the spec on your motors to determine the correct wiring of your motor fly leads.
    Current Limit:
    A trimmer resistor for altering the output current driving the stepper motors. Note: this trimmer works in reverse to what you might expect, clockwise rotation actually LOWERS the output current.

    If you have problems with your motor appearing jittery when no step/dir signal is applied, you plobably need to tweak the current limit trimmer. If the stepper seems to respond to step/dir but doesn't appear to step in the same direction for each successive step request, you probably have the stepper motor wired wrong.
    This circuit is provided as-is, with no warranty or fit-for purpose statement. This circuit works fine for me but use it at your own risk.
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2010
    Posts
    0
    very interesting
    I have a UNO based gcode interpreter

    be very keen to see how you've done yours
    (you show me yours - I'll show you mine...!)

    I tried to open the .sch file - I guess it isn't EAGLE compatible (well being DesignSpark I guess I'm not surprised!)

    I've often wondered if it's better to go with a microstepping controller or just full step with an H bridge - what's your take on the difference?

    thanks for sharing

  3. #3
    Join Date
    Jun 2011
    Posts
    4
    Quote Originally Posted by mmcp42 View Post
    very interesting
    I have a UNO based gcode interpreter

    be very keen to see how you've done yours
    (you show me yours - I'll show you mine...!)
    Send me your email address and I'll email a copy - I've avoided using interrupts and PWM as they have limitations, mine still needs optimising to reduce the size of the code but at 16.5K in size, I'm not too worried at this stage - Provides support for most commonly used G and M codes (plus variable feedrates etc) but doesn't have inertial compensation yet for direction changes but since my CNC is designed around accuracy rather than speed, that's not an issue for me yet.

    Quote Originally Posted by mmcp42 View Post
    I tried to open the .sch file - I guess it isn't EAGLE compatible (well being DesignSpark I guess I'm not surprised!)
    I should have explained the files are DesignSpark format not eagle etc - My bad... Since DesignSpark is free, it's not a problem for people to download it to open/edit the files if required. I generally don't like the image/PDF files people upload since most PCB fabricators can't use them and besides, someone may improve on my circuit further...

    Quote Originally Posted by mmcp42 View Post
    I've often wondered if it's better to go with a microstepping controller or just full step with an H bridge - what's your take on the difference?
    I considered this point at length when designing my own CNC - Being a bit of a perfectionist, I designed my second circuit (the A397X design I mentioned) to improve on accuracy even further - It was only afterwards I worked out that controlling the CNC to within 0.0003125 of a millimetre was becoming a bit anal - Since cars passing by the house or some whale belching on the other side of the world was likely to introduce a vibration greater than that, I decided that the extreme accuracy provided by microstepping was not required if the physical design of the CNC provided smaller movement anyway.

    My CNC is using an M6 (1mm pitch) stainless steel threaded bar for all axis. Thus, a 200-step motor provides 1/200th of a millimetre in full-step mode, even better in half-step mode - so realistically, why would I need greater accuracy than that? That's equivalent to about 1 thou of an inch - If I need greater accuracy for milling wood/plastic etc (bear in mind this is for a hobbyist - not commercial production) then I would need to consider temperature controlled environments, vibration dampening, precision made materials etc - I little bit overboard methinks. Using the 1/16th microstepping capability of the Allegro would means working in fractions of a thou, I suspect the tolerances for milling bits alone exceed that.

    If I had used a larger pitch for my drive threads, then perhaps microstepping would be needed but since my CNC is moving very slowly with the smaller threaded bar, it moves slower which means virtually no inertia, smaller (cheaper) motors can be used and the only difference between my CNC and some of the more common DIY CNC designs out there, mine is cheaper and slower - the output is still the same.

    Quote Originally Posted by mmcp42 View Post
    thanks for sharing
    You're most welcome - Fingers crossed I can help some others get into this when their main stumbling block is cost (i.e. "she who holds the purse strings" has to be convinced it's affordable)

    Dragonlaird

  4. #4
    Join Date
    Aug 2011
    Posts
    0

    Smile Cheaper CNC Machine

    I believe that is every mans most challenging part when creating a CNC Machine.
    Quote "She who holds the purse string"

    LOL, Very well said.

  5. #5
    Join Date
    Apr 2015
    Posts
    4

    Re: L297/L298 Bipolar Driver Circuit with Limit Detection

    Could you please send me the g code interpreter because i'm writing mine and i have some difficulties.Thank you

  6. #6
    Join Date
    Jun 2011
    Posts
    4

    Re: L297/L298 Bipolar Driver Circuit with Limit Detection

    Quote Originally Posted by kelectroman View Post
    Could you please send me the g code interpreter because i'm writing mine and i have some difficulties.Thank you
    Since I first started writing this, many groups have developed CNC designs for the hobbyist, some providing free downloads to their own G-Code interpreter/sender code or the pre-compiled HEX file to flash an Arduino with. I can't comment on their features or how well they perform as I've never tried them myself but a quick search I found 3 that seem fairly common:

    Arduino GCode Interpreter - RepRapWiki

    https://github.com/OttoHermansson/GcodeSender/downloads

    Grbl - ShapeOko

    I believe the latter link is still being actively developed and I'm sure others out there can provide feedback on suitability etc.

    I'm happy to provide a copy of my own source code if there is enough interest, in original code format rather than HEX so that others can develop it further - I wrote it a long time ago and apart from using it to watch motors spin on my test rig, I never really did much with it, although with the warmer weather allowing me to get back outside into my cold workshop recently, my interest has been revived and I am currently working with a friend to produce a large-scale project that will re-use much of what was developed here.

    It's worth pointing out that the stepper driver circuit I designed has long since been superseded by other designs and now I can't design/build a circuit cheaper than boards like the Pololu drivers, which for a few Dollars/Pounds/Euros, is very cheap and comes pre-built to handle most hobbyist steppers.
    Do not upset a dragon - For thou art crunchy and taste good with ketchup.

  7. #7
    Join Date
    Apr 2015
    Posts
    4

    Re: L297/L298 Bipolar Driver Circuit with Limit Detection

    Thank you very much for your reply!Yes i have seen them but i'm trying to write my own g-code interpreter and understanding 100% the way they work.It would be great if you could send me yours in order to take an idea. It sounds very interesting the project you are talking about . There are too many stepper tiny drivers with microstepping (some of them can handle up to 2-2.5Amps!!!) such us pololu,stepstick,easydriver etc. on ebay that costs 1-2$ that it dosent worth to design and construct your own.I designed the classic l297/l298 drivers just for learning new stuff

  8. #8
    Join Date
    Jun 2011
    Posts
    4

    Re: L297/L298 Bipolar Driver Circuit with Limit Detection

    Having hunted around, most Stepper Driver firmware available for the Arduino seems to be pre-compiled into Hex format. Not a great way for people to collaborate on an Open Source platform. I wonder why there isn't much actual code available.

    Anyway, I've attached my own source code (updated for the Uno R3) for people to download and tweak - I suppose I could/should put in in Git - I may do that. You're welcome to use it and modify the code as long as it is only for personal use and the copyright notices remain intact in the header of the files. The code has quite a few comments to help explain what it is (meant to be) doing.

    The PIN-Out settings are in the file "Settings.h". The main control for stepping the motors (ControlLoop()) is in the file "Stepper.h". The main routine (ReadSerial()) for buffering the received commands (via USB) is in Buffer.h and both these routines are called via the main loop in the file drStepperController.ino.

    Enjoy!
    Attached Files Attached Files
    Do not upset a dragon - For thou art crunchy and taste good with ketchup.

  9. #9
    Join Date
    Apr 2015
    Posts
    4

    Re: L297/L298 Bipolar Driver Circuit with Limit Detection

    Yes that exactly was my problem that i couldn't find a source code in order to study this and take an idea of the correct way of coding! Thank you very much for your help i really appreciate it and its for my own use just to study the way that arduino interpreters a g-code into movements and try to make my own for my homemade pcb cnc.
    P.S I haven't already studied it in depth but for sure i can tell that you have done great job!
    Thank you very much for your help and i think that this zip will help a lot of people!

  10. #10
    Join Date
    Apr 2015
    Posts
    4

    Re: L297/L298 Bipolar Driver Circuit with Limit Detection

    I'm trying to use your firmware but it dosen't react.I send some basic g-commands from the serial monitor but nothing hapend .I connected my step and dir pins correct but i cant find whats wrong! Could you please help me?
    Thank you!

Similar Threads

  1. L297-L298 Bipolar Stepper Driver Vero Layout
    By OvaR8ed in forum Open Source Controller Boards
    Replies: 4
    Last Post: 02-18-2013, 12:56 PM
  2. L298, L297 Stepper Driver
    By abbe in forum Open Source Controller Boards
    Replies: 23
    Last Post: 07-01-2012, 04:25 PM
  3. Problems with L298 and L297 circuit
    By mojalovaa in forum Stepper Motors / Drives
    Replies: 1
    Last Post: 01-12-2012, 08:37 PM
  4. L297 bipolar using mosfets instead of L298?
    By nullbert in forum Open Source Controller Boards
    Replies: 7
    Last Post: 10-14-2010, 09:52 PM
  5. l298 l297 driver 2A with stepper 3A help
    By chawkiz in forum OpenSource Software
    Replies: 4
    Last Post: 06-05-2009, 03:09 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •