Go Down

Topic: Arduino chip as Stepper Controller (Read 12 times) previous topic - next topic

kf2qd

To program a chip I use Arduino-0.22 to load the ArduinoISP sketch on my Arduino Uno board. I made a small board that has 2 sockets, a 20 pin that could be used to program 20 and 8 pin chips and a 28 pin socket that I use to program 328's (like the Uno).  Search for Arduino as ISP as there is a lot of info out there that exlains the process and the wiring. My little board has 6 wires between the boards to program the chip and a 120 Ohm resistor between the Reset and +5 on the Arduino Uno. To program an Arduino sketch using the ArduinoISP there is a selection on the ArduinoIDE File menu to write the sketch usin Arduino as ISP.


I use the Arduino-0.22 IDE as there was a change in something in Arduino-1.0 and the ArduinoISP only works at 9600 baud instead of 19200 which causes a problem.

Here's a picture (poor) of my ISP board to use with the Uno.

kf2qd

I got it working -

Figured out what was lacking in my assembly code and now it works.

Code: [Select]

.NoList
.INCLUDE "tn2313Adef.inc" ; Header for ATTINY2313A
.List
; ============================================
;   R E G I S T E R   D E F I N I T I O N S
; ============================================
.DEF Conf = R16 ; Multipurpose register
.DEF StepCt = R17
.DEF StepMask = R18
.DEF Direction = R19
.DEF PortBHold = R20
.DEF PortDHold = R21
.DEF PortDMask8 = R22
.DEF SeqBase = R24
; ============================================
;       S R A M   D E F I N I T I O N S
; ============================================
.DSEG
.ORG  0X0060
; ============================================
;   R E S E T   A N D   I N T   V E C T O R S
; ============================================
.CSEG
.ORG $0000
rjmp Main ; Reset vector
rjmp Step ; Int vector 1
reti ; Int vector 2
reti ; Int vector 3
reti ; Int vector 4
reti ; Int vector 5
reti ; Int vector 6
reti ; Int vector 7
; ============================================
;     I N T E R R U P T   S E R V I C E S
; ============================================
Step:   in  PortDHold,PIND
; look at only PD#, the Direction input
        and PortDHold,PortDMask8
; if PD3 High, Add Direct to StepCt, if PD3 Low Subtract Direction
        breq SinNeg
        add StepCt,Direction
        rjmp Next
SinNeg: sub StepCt,Direction
; limit StepCt to range from 0 to 7 (-1 becomes 7)
Next:   and StepCt,StepMask
; use Z as a pointer to the StepSequence table
        mov ZL,SeqBase
; StepCt is teh offset into the table
add ZL,StepCt
; transfer the next bit pattern from ProgMem to PortBHold, R20
Lpm PortBHold,Z
out PortB,PortBHold
reti
; ============================================
;     M A I N    P R O G R A M    I N I T
; ============================================
Main:
; Init stack
ldi Conf, LOW(RAMEND) ; Init LSB stack
out SPL,Conf
; Init Port A
ldi Conf,0 ; Direction Port A
out DDRA,Conf
; Init Port B
ldi Conf,(1<<DDB0)|(1<<DDB1)|(1<<DDB2)|(1<<DDB3) ; Direction Port B
out DDRB,Conf
; Set ISC00 to 0 and ISC01 to 1, Falling Edge INT0 Interrupt
ldi Conf,(0<<ISC00)|(1<<ISC01)
out MCUCR,Conf
; Set INTO , Bit 6 of GIMSK to Enable INT0
ldi Conf,(1<<int0)
out GIMSK, Conf
; Initialize StepCt, R17
ldi StepCt,0
; Initailize StepMask, R18
ldi StepMask,7
;Initialize Direction, R19
ldi Direction,1
; Initialize SeqBase to point to 8 bit address of StepSeq
ldi SeqBase, StepSeq
add SeqBase,SeqBase
; Initialize PortDMask8, R22, to mask only PD3 of port D
        ldi PortDMask8,8
        ldi ZH,0   
sei
; ============================================
;         P R O G R A M    L O O P
; ============================================
Loop:  rjmp loop ; go back to loop
; bit patterns for output to the Stepper Drive Bits.
StepSeq: .DB 1,3,2,6,4,12,8,9,0,0
; End of source code

jsearles

This was one of the best reads on Arduino stepper logic thata I have seen.  You are to be commended and I thank you very much. 

It's a pity that it seemed to drop so abruptly,

Do you have any final specs on the speed of your assembly code version?


kf2qd

#28
Jun 28, 2012, 09:43 pm Last Edit: Jun 29, 2012, 12:33 am by kf2qd Reason: 1
Got into a few other projects so I have not paid much attention to it for a while. I was able to get hold of a Hardinge UM milling machine and that took some time to get cleaned and moved into my shop. I have a Harbor Freight Mini Mill that I want to convert to CNC along with a 10:1 gearbox that I want to use as an indexer on that mill. Living down here in South Texas my year is backwards from folks that live farther north. Here it get too hot to work in an un-airconditioned garage so most of my projects out there take place from September to May whereas when I lived up in Indiana the projects took place from April to October when it was warm enough to work out in the shop.

I have mounted 2 2313 on a perf board along with the 8 MOSFETs and actually had it running - ~140 rpm using my Arduino as the step generator. As that was written in the Arduino IDE I suspect that I can get quite a bit more speed using MACH3 or GRBL.

What's the timing for 12 instructions and an interrupt on an ATtiny running at 8Mhz? According to how I interpret the info from AVRStudio the interrupt shold process in ~2.25mSec.

flop777


Now i am confused. Do you use the dedicated chip to drive the stepper or the Arduino.
If you use the PC to send Direction and Step commands what does the Arduino do?

yeah very interesting...
i love blogs... :)

Go Up