. .

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. Ok thanks.

    how long is a piece of string?
    That’s easy it's double half it's length.

    I am just installing the MPLAB as I type.

    I will keep my eyes open for a promo.

  2. Here you go:

    It was designed around a 16C84 to drive a L6219 bipolar driver, but since it uses a step table, all you need to do is change the bits to suit your output.

    You'll have to change the CPU type etc. to suit whatever PIC you use.

    Ignore / delete the limit switch code.

    Code:
    ;****************************************
    ;             PIC Header
    ;****************************************
    ;(c) 1994 - 2008 W.K.Todd Electronics
    ;
    ;DATE:23/08/2008 (initialised 27/09/1998)
    ;FILE:STEPPER.ASM  -  L6219 STEPPER DRIVER
    ;VERSION:1.10    - interrupt driven
    ;
    ; Target processor = 16C84 (eeprom PIC)
    ; Assembler = MPASM
    ;
        LIST P=16C84
        #INCLUDE P16C84.INC
    
    ;EQUATES    
    STPCNT        EQU    0x0C    ;STEP COUNTER
    FLAGS        EQU    0x0D    ;VARIOUS FLAG BITS
    TIMER        EQU    0x0E    ;GP TIMER USED TO SLOW LOOP
    
    ;interrupt service temps
    STATUS_TEMP    EQU    0X2E
    W_TEMP        EQU    0X2F
    
    
    ;BIT ADDRESSES
    DEBN        EQU    0x00    ;DEBOUNCE FLAG
    CLKIN        EQU    0X00    ;CLK INPUT
    DIRIN        EQU    0x01    ;DIRECTION INPUT
    XLIM        EQU    0x00    ;LIMIT SWITCH INPUTS
    YLIM        EQU    0x01    ;
    ZLIM        EQU    0x02    ;
    LIMIT        EQU    0x03    ;LIMIT OUTPUT (ACTIVE HIGH)
    BYPSWT        EQU    0X04    ;LIMIT BYPASS SWITCH
    
    ;
    
        ORG    0x000    
        GOTO    START        ;RESET VECTOR
        NOP
        NOP    
        NOP
    ;INTERRUPT VECTORS TO HERE
    ;
    PUSH    MOVWF     W_TEMP         ; Copy W to TEMP register,
        SWAPF     STATUS, W     ; Swap status to be saved into W
        MOVWF     STATUS_TEMP     ; Save status to STATUS_TEMP register
    ; Interrupt Service Routine
        ;test interrupt type
        BTFSS    INTCON,INTF    ;test int0 flag
        goto    POPW
        
        bcf    INTCON,INTF    ;clr flag
        BTFSC    PORTB,DIRIN    ;TEST DIRECTION
        GOTO    CLKWIZ        
        ;DO ANTI CLK TURN
        DECF    STPCNT,W    ;DECR AND FETCH STEP COUNT
        ANDLW    0x07        ;MODULO 7
        MOVWF    STPCNT        ;SAVE
        CALL    STPTAB        ;GET PHASE VALUES
        MOVWF    PORTB
        GOTO    POPW        ;AND FINISH
    
    ;DO CLOCKWISE TURN
    CLKWIZ    INCF    STPCNT,W    ;INCR AND FETCH STEP COUNT
        ANDLW    0x07        ;MODULO 7
        MOVWF    STPCNT        ;SAVE
        CALL    STPTAB        ;GET PHASE VALUES
        MOVWF    PORTB
    
    
    POPW     SWAPF     STATUS_TEMP, W     ; Swap nibbles in STATUS_TEMP register
                    ; and place result into W
        MOVWF     STATUS        ; Move W into STATUS register
                    ; (sets bank to original state)
        SWAPF     W_TEMP, F     ; Swap nibbles in W_TEMP and place result in W_TEMP
        SWAPF     W_TEMP, W     ; Swap nibbles in W_TEMP
        RETFIE
    ;
    ; TABLES
    ;Bits/function
    ;7   6   5   4   3   2   1   0
    ;Io1 I11 PH1 I12 I02 PH2 DIR STEP
    STPTAB    ADDWF    PCL,f
    
    ;2/3 current, half step table
    ;    RETLW    0xC8    ;STEP0
    ;    RETLW    0x88    ;1
    ;    RETLW    0x9C    ;2
    ;    RETLW    0x8C    ;3
    ;    RETLW    0xEC    ;4
    ;    RETLW    0xAC    ;5
    ;    RETLW    0xB8    ;6
    ;    RETLW    0xA8    ;7    
    
    ;full current, half step table
        RETLW    0xC0    ;STEP0
        RETLW    0x00    ;1
        RETLW    0x1C    ;2
        RETLW    0x04    ;3
        RETLW    0xE4    ;4
        RETLW    0x24    ;5
        RETLW    0x38    ;6
        RETLW    0x20    ;7
    
    
    ;
    ; START OF PROGRAM
    ;
    START    BSF    STATUS,RP0 ;select bank 1
    
        MOVLW    0x03    ;RB0 +1 TO INPUT
        MOVWF    TRISB
        MOVLW    0x17    ;RA0,1,2,4 TO INPUT
        MOVWF    TRISA
        MOVLW    0XCF
        MOVWF    OPTION_REG    ;set up interrupt
        BCF    STATUS,RP0
        
        MOVLW    0X90
        MOVWF    INTCON    ;enable int0
        CLRF    STPCNT
        CLRF    FLAGS
    
    ;MAIN LOOP    
    MAINLP
    
    ;TEST LIMIT SWITCHES
    TLBPS    BTFSS    PORTA,BYPSWT        ;TEST LIMIT BYPASS
        GOTO    BYPASS
        MOVF    PORTA,W        ;GET LIMIT SWITCHES
        ANDLW    0x07
        BTFSS    STATUS,Z
        BSF    PORTA,LIMIT    ;SET LIMIT IF X,Y OR ZLIM IS HIGH
        BTFSC    STATUS,Z
    BYPASS    BCF    PORTA,LIMIT    ;CLEAR LIMIT OUTPUT IF SWITCHES ARE ALL LOW
        GOTO    MAINLP        ;LOOP BACK    
    
    
        END

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. NEW MEMBER: Newbe on the site
    By Phillou in forum New Member Introductions
    Replies: 0
    Last Post: 14-03-2014, 05:54 PM
  2. NEW MEMBER: Newbe in France
    By dudz in forum New Member Introductions
    Replies: 1
    Last Post: 17-10-2012, 06:46 PM
  3. NEW MEMBER: Newbe
    By THE PHOENIX in forum New Member Introductions
    Replies: 2
    Last Post: 03-12-2010, 07:20 PM
  4. NEW MEMBER: Hi from newbe
    By croy in forum New Member Introductions
    Replies: 2
    Last Post: 28-01-2010, 09:22 PM
  5. NEW MEMBER: Newbe
    By cncezee in forum New Member Introductions
    Replies: 3
    Last Post: 29-08-2009, 07:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

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