Welcome! Log In Create A New Profile

Advanced

MiXley: Teacup on a ATmega32U4

Posted by Michielh 
MiXley: Teacup on a ATmega32U4
May 02, 2011 09:18AM
Hi all,

I am currently working on a port from the Teacup firmware to make it work on a ATmega32U4. The mean reason for this chip is that is is much cheaper than a AT90USB1287. The main problem is that it has much fewer IO's. This ofcourse can be fixed using port expansion through Shift registers and multiplexing.
As you can see in the Scheme, the thermistors are multiplexed into the analog input, the endstops are inputted by a shift register, and the heaters, enables and directions are all output through a double 8 bit shift register. All fun, but this the first 'big' embedded project for me. Let's make this work.

For starters let me thank Triffid for supplying me with some help and information.

I've started with remapping the IO's of the SR's to 2 global variables.
/* 
 * Special non real pins 
 * DIO70-DIO77 are the SR input pins
 * DIO80-DIO95 are the SR output pins
 */

extern volatile uint8_t sr_in_buf, dummy8;
extern volatile uint16_t sr_out_buf, dummy16;

#define DIO70_PIN       SRIN0		//D0
#define DIO70_RPORT     sr_in_buf
#define DIO70_WPORT     sr_in_buf
#define DIO70_DDR       &dummy8

etc.

then, in config.c i've changed the pins to the following:
#define	X_STEP_PIN					DIO44 //PF4 (STEP0)
#define	X_DIR_PIN					DIO85 //SR OUT 1 Qf (DIR0)
#define	X_MIN_PIN					DIO77 //SR IN D7 (ENDSTOP0)
#define	X_MAX_PIN					DIO73 //SR IN D3 (ENDSTOP1)
#define	X_ENABLE_PIN					DIO86 //SR OUT 1 Qg (ENABLE0)
//#define	X_INVERT_DIR
//#define	X_INVERT_MIN
//#define	X_INVERT_MAX
//#define	X_INVERT_ENABLE

#define	Y_STEP_PIN					DIO45 //PF5 (STEP1)
#define	Y_DIR_PIN					DIO83 //SR OUT 1 Qd (DIR1)
#define	Y_MIN_PIN					DIO72 //SR IN D2 (ENDSTOP2)
#define	Y_MAX_PIN					DIO70 //SR IN D0 (ENDSTOP3)
#define	Y_ENABLE_PIN					DIO84 //SR OUT 1 Qe (ENABLE1)
//#define	Y_INVERT_DIR
//#define	Y_INVERT_MIN
//#define	Y_INVERT_MAX
//#define	Y_INVERT_ENABLE

#define	Z_STEP_PIN					DIO46 //PF5 (STEP2)
#define	Z_DIR_PIN					DIO81 //SR OUT 1 Qb (DIR2)
#define	Z_MIN_PIN					DIO74 //SR IN D4 (ENDSTOP4)
#define	Z_MAX_PIN					DIO75 //SR IN D5 (ENDSTOP5)
#define	Z_ENABLE_PIN					DIO82 //SR OUT 1 Qc (ENABLE2)
//#define	Z_INVERT_DIR
//#define	Z_INVERT_MIN
//#define	Z_INVERT_MAX
//#define	Z_INVERT_ENABLE

#define	E_STEP_PIN					DIO22 //PC6 (STEP3)
#define	E_DIR_PIN					DIO92 //SR OUT 2 Qe (DIR3)
#define E_ENABLE_PIN					DIO80 //SR OUT 1 Qa (ENABLE3)
//#define	E_INVERT_DIR

#define	PS_ON_PIN						DIO38 //PE6 (SWITCH_POWER)

oh yeah, i've changed this in arduino_32u4.h, the SPI pins were still correct from the AT90USB copy.

#define	DEBUG_LED		DIO15 /* led1 on B7 */

Now the basics are done, we still need to write and read the actual SR. I can do this every 10ms by adding a small piece of code to the 10ms clock function:

for(bit=0;bit<16;bit++){
		WRITE(DIO34, 0); // shift clock pin to 0
		WRITE(DIO23, (sr_out_buff</Michielh
Attachments:
open | download - Mendel.png (47.4 KB)
Re: MiXley: Teacup on a ATmega32U4
May 02, 2011 11:18AM
Might be much easier to use Klimentkip/Sprinter as a base to port. That code doest use timers for the step timing and would remove some of the issues with interrupt race conditions.
Re: MiXley: Teacup on a ATmega32U4
May 02, 2011 12:21PM
jv4779 Wrote:
-------------------------------------------------------
> Might be much easier to use Klimentkip/Sprinter as
> a base to port. That code doest use timers for
> the step timing and would remove some of the
> issues with interrupt race conditions.


True, I have considered using Sprinter firmware, but the Teacup has the option to use dedicated USB (virtual serial port), and thats just what i need since the ATmega32u4 doesn't have a serial port. Pretty much like the AT90USB.
Re: MiXley: Teacup on a ATmega32U4
May 02, 2011 09:06PM
Michielh Wrote:
-------------------------------------------------------
> True, I have considered using Sprinter firmware,
> but the Teacup has the option to use dedicated USB
> (virtual serial port), and thats just what i need
> since the ATmega32u4 doesn't have a serial port.
> Pretty much like the AT90USB.

Teacup's usb support was provided by Ben Jackson with little to no alteration of the primary codebase. I'm sure you could pull the lufa_serial directory and LUFA submodule into sprinter just as easily if you wanted.


-----------------------------------------------
Wooden Mendel
Teacup Firmware
Re: MiXley: Teacup on a ATmega32U4
May 03, 2011 10:34AM
Triffid_Hunter Wrote:
-------------------------------------------------------
> Michielh Wrote:
> --------------------------------------------------
> -----
> > True, I have considered using Sprinter
> firmware,
> > but the Teacup has the option to use dedicated
> USB
> > (virtual serial port), and thats just what i
> need
> > since the ATmega32u4 doesn't have a serial
> port.
> > Pretty much like the AT90USB.
>
> Teacup's usb support was provided by Ben Jackson
> with little to no alteration of the primary
> codebase. I'm sure you could pull the lufa_serial
> directory and LUFA submodule into sprinter just as
> easily if you wanted.

This is true, but at this point, its very hard to customize the Sprinter firmware. I want to get this to work first. Then improve on it.


/Michielh
Sorry, only registered users may post in this forum.

Click here to login