Let's Make Robots!

Yet another L298 based motor controller

Hi all,

motor controller

















 This came out as a sub project related to my DIY CNC machine "the Beast"  because the outputs of the Arduino would not suffice to control the motors. So I chose to use I2C for this purpose and designed my own little guy.

It is based on L298 and an Attiny 2313 to control it, pretty basic stuff. 

It is designed to be as generic as possible, here are the current features:

- control bipolar motors with full stepping (half stepping is possible but not implemented now due to code size)

- the enable lines are linked to the pwm pins of the chip -> microstepping possible or dc motor control

- the external interrupts  of the attiny are available for usage together with 5v power for end stops or other sensors (not tested yet)

- you can use this guy standalone or controlling other things trough i2c by modifying the software

- power input is stabilized on both 5v and 12v rails 

- it is designed to take 12 v as input you need to adapt  for more

- power led, led on pin PD5 of the AVR for blinky stuff

- reset switch (seems to work fine)

- oh yeah the pcb is single sided and there should be enough place behind the l298 for a radiator.

- i think that's it :)

The software is using a TWI slave library written by a guy over at avrfreaks.net (Don Blake wrote it, here is the original post on avrfreaks.net http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=48395), the rest of the messy code by myself.

Attached you will find the software and the Eagle files, please feel free to add any improvements/optimizations/features.

(Rename  usiTwiSlave.h.c to usiTwiSlave.h, not sure why the site does not allow .h files attachments or archives )  see update below.


On last thing: If any one for what ever reason wants to comercialize  this guy, I agree but I want a share of the profit :D 5% would be nice :D 

Small update: fixed some really  bad spelling




Update - 18-Aug-2009

I have posted the updated code on GitHub here:





Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I have found the code size problem :D It seems that it is a really bad ideea to use varibles to call the avr-libc function _delay_ms().

So I have replaced the variable "delay" in the functions full_step and half_step with a constant and voila code size with everything enbled under 1k :D So now there is a lot of place in there to add new features.

Thanks for sharing your board TinHead. I`m going to try the same I2C driver -> arduino as you have here. I just finished wiring up the first board and it tested great, although I still have to put in the 2313. I will post up later with a video.

When I was looking for some arduino half stepping code I ran across this on instructables. He puts the pins in an array and loops through the array. I wonder if this could be used to fit both full and half stepping into your controller?

Hope it works fine for your project.

I have seen that instructable before, butI cannot apply that code on this one because as I have designed this guy 3 pins of the motor are on PORTB and one on PORTD :( That is so because I wanted to have the enable pins on the PWM capable pins of the attiny.

I'm sure the code size might be solved some how, one thing I suspect is the compiler :/ Also my  C knowledge is limited so if you or someone else here are able to optimize or do it in a better way please do, I would be happy to integrate the code.

As far as I have played with the library it works to receive as a slave, was unable to send anything to the master.

It seems that all this libraries are based on the same Atmel application note and none of them really works. 

This one does at least let you send commands to the slave, I'm sure the answering back can be fixed, jut did not have the time to try. When I'm done with the mechanics for the beast I will concentrate on the software.
Thanks for sharing your code. I tried different librarys for building an I2C slave for an ATmega and tiny controllers, but with no luck. None of them worked. I didn't know the lib you use, so I will give it another attempt. For private use only, so don't expect any profit from me ;-)