[telescoperos] Re: Codigo Fuente Driver Motor de Paso

  • From: "Miranda Osvaldo" <omiranda@xxxxxxxxxxxx>
  • To: <telescoperos@xxxxxxxxxxxxx>
  • Date: Fri, 17 Aug 2007 09:18:02 -0400

Estimado Señor, yo venía feliz, anoche logré mover los motores con un Pic 
16F628 , pero lo hice con pulsos cuadrados, mi circuito es bien sencillo, 
consiste en cuatro botoneras conectadas al puerto de entrada del Pic, luego un 
arreglo darlington uln2803, para alimentar los motores.

 

Hoy me encuentro con esta maravilla, que genial,  no se nada del tema PWM, asi 
que voy a investigar un poco para ponerme al día.

 

Muchisimas Gracias.

 

________________________________

De: telescoperos-bounce@xxxxxxxxxxxxx 
[mailto:telescoperos-bounce@xxxxxxxxxxxxx] En nombre de aneves
Enviado el: Jueves, 16 de Agosto de 2007 22:36
Para: telescoperos@xxxxxxxxxxxxx
Asunto: [telescoperos] Codigo Fuente Driver Motor de Paso

 


Hola,

Por suerte encontre facilmente los fuentes del driver para motores de paso. 
Falta la descripcion del circuito. 

Saludos,

Alfredo

;**********************************************************

;Equatorial Plataform driver

;Copyright (C) 2003, Alfredo Rainho Neves

;All rights reserved

;**********************************************************

list p=16F876

__config H'FB41' ;XT

include "p16f876.inc"

; Channel bits

I1B equ 0

I0B equ 1

PHASEB equ 2

I1A equ 3

I0A equ 4

PHASEA equ 5

TIMERA equ CCPR2L

TIMERB equ CCPR1L

;Port B bits

led1 equ 7

led2 equ 6

RevBtn equ 1

;

MinDuty equ 7

MaxDuty equ 64+MinDuty

;

W_TEMP equ 20h

STATUS_TEMP equ 21h

PCLATH_TEMP equ 22h

delaymscount1 equ 23h

delaymscount2 equ 24h

rate equ 25h

count equ 26h

step equ 27h

temp equ 28h

radix dec

; Start at the reset vector

org 0x0000 

goto Start

org 0x0004

Interrrupt:

movwf W_TEMP

swapf STATUS,W

clrf STATUS

movwf STATUS_TEMP

movf PCLATH,W

movwf PCLATH_TEMP

clrf PCLATH

; 

bcf PIR1,TMR1IF

bsf PORTB,led1

bcf PORTB,led2

clrw

call delayms

bcf PORTB,led1

bsf PORTB,led2

; 

movf PCLATH_TEMP,W

movwf PCLATH

swapf STATUS_TEMP,W

movwf STATUS

swapf W_TEMP,F

swapf W_TEMP,W

retfie

Start:

clrwdt

BANKSEL INTCON

clrf INTCON ;Disable interrupts and clear T0IF

; Initialize porta as digital output port

clrf PORTA

BANKSEL ADCON1

movlw 6

movwf ADCON1

BANKSEL TRISA

clrf TRISA

; 

clrf PORTB ;Clear PORTB

clrf PORTC ;Clear PORTC

BANKSEL TRISB

movlw B'00000011' ;Two lower bits are input

movwf TRISB ;PORTB all outputs

BANKSEL OPTION_REG

bcf OPTION_REG,NOT_RBPU

;Set up PWMs

BANKSEL CCP1CON

clrf CCP1CON ;CCP Module if off

clrf CCP2CON

; Set the pwm period. Since we want a minimum duty cycle this values is

; calculated as 64 + the minimum duty cycle of 4 

; 

movlw 64 ;PWM period

addlw MinDuty 

BANKSEL PR2

movwf PR2 ;Timer 2 prescale

BANKSEL CCPR1L

movlw 0x10 ;Set up duty cycle at 50%

movwf CCPR1L

movlw 2 ;Set up duty cycle at 50%

movwf CCPR2L

BANKSEL TRISC

clrf TRISC

BANKSEL PIE1

clrf PIE1

movlw B'000' ; 1 / 1 

BANKSEL T2CON

movwf T2CON ;Set Up for 19khz

movlw 0x0c ;Enable PWM

BANKSEL CCP1CON

movwf CCP1CON

movwf CCP2CON 

BANKSEL T2CON

bsf T2CON,TMR2ON ;Timer 2 starts

; 

; Initialize timer1

BANKSEL T1CON

clrf TMR1H

clrf TMR1L

movlw 0x31 ;Enable timer, prescaler / 8

movwf T1CON

BANKSEL PIE1

bsf PIE1,TMR1IE ;Enable timer 1 interrupt

; 

BANKSEL 0

movlw 0xc0

; movwf INTCON ;Ebable the interrupts 

;*********************************************************************

; Drives the stepper motor in sideral rate till the rewind button is

; pressed.

;********************************************************************

Main:

movlw 0x80 ;Toggle the led

movwf PORTB

call Rewind

movlw 0x40 ;Toggle the led

movwf PORTB

clrf step

call SetMinCurrent 

NextStep:

call SingleStep ;Step 

movlw 130 ;Delay between steps

call delay10us

incf step,F ;Increment the step count

movf step,W

andlw 0x7f 

movwf step

; 

goto NextStep 

;**********************************************************************

;Drive the motor in reverse at maxium speed and current

;********************************************************************** 

Rewind:

movlw MaxDuty

movwf TIMERA

movwf TIMERB

DoRewind: 

movlw 0

call FullStep

movlw B'000100'

call FullStep

movlw B'100100'

call FullStep

movlw B'100000'

call FullStep

btfsc PORTB,RevBtn ;Check if rewind button pressed

goto DoRewind

; Move foward until siwtch opens

MoveFwd:

movlw B'100000'

call FullStep

movlw B'100100'

call FullStep

movlw B'000100'

call FullStep

movlw 0

call FullStep

btfss PORTB,RevBtn ;Check if rewind button pressed

goto MoveFwd

call SetMinCurrent

return 

;

FullStep:

movwf PORTA

movlw 2

call delayms

return

SingleStep:

movlw HIGH getcos

movwf PCLATH

movf step,W

call getcos

addlw MinDuty

movwf temp

btfss temp,7

goto dostep1

bsf PORTA,PHASEA

andlw 0x7f

goto dostep2

dostep1:

bcf PORTA,PHASEA 

dostep2: 

movwf TIMERA

;

movlw HIGH getsin

movwf PCLATH

movf step,W

call getsin

addlw MinDuty

movwf temp

btfss temp,7

goto dostep3

bsf PORTA,PHASEB

andlw 0x7f

goto dostep4

dostep3:

bcf PORTA,PHASEB

dostep4: 

movwf TIMERB

;

return

;

SetMaxCurrent:

bcf PORTA,I0A

bcf PORTA,I1A

bcf PORTA,I0B

bcf PORTA,I1B

return

SetMinCurrent:

bsf PORTA,I0A

bcf PORTA,I1A

bsf PORTA,I0B

bcf PORTA,I1B

return

delayms:

;return

movwf delaymscount1

delayloop1: 

movlw 100

movwf delaymscount2

delayloop2:

nop ;Loop delays 10us

nop

nop

nop

nop

nop

nop

decfsz delaymscount2,1

goto delayloop2

decfsz delaymscount1,1

goto delayloop1

return

delay10us:

;return

movwf delaymscount1

delayloop3:

nop ;Loop delays 10us

nop

nop

nop

nop

nop

nop

decfsz delaymscount1,1

goto delayloop3

return

;*********************************************************************

; Sin and cos tables

;*********************************************************************

org 0x400

getsin:

addwf PCL,F

retlw 0x00

retlw 0x03

retlw 0x06

retlw 0x09

retlw 0x0c

retlw 0x10

retlw 0x13

retlw 0x16

retlw 0x18

retlw 0x1b

retlw 0x1e

retlw 0x21

retlw 0x24

retlw 0x26

retlw 0x29

retlw 0x2b

retlw 0x2d

retlw 0x2f

retlw 0x31

retlw 0x33

retlw 0x35

retlw 0x37

retlw 0x38

retlw 0x3a

retlw 0x3b

retlw 0x3c

retlw 0x3d

retlw 0x3e

retlw 0x3f

retlw 0x3f

retlw 0x40

retlw 0x40

retlw 0x40

retlw 0x40

retlw 0x40

retlw 0x3f

retlw 0x3f

retlw 0x3e

retlw 0x3d

retlw 0x3c

retlw 0x3b

retlw 0x3a

retlw 0x38

retlw 0x37

retlw 0x35

retlw 0x33

retlw 0x31

retlw 0x2f

retlw 0x2d

retlw 0x2b

retlw 0x29

retlw 0x26

retlw 0x24

retlw 0x21

retlw 0x1e

retlw 0x1b

retlw 0x18

retlw 0x16

retlw 0x13

retlw 0x10

retlw 0x0c

retlw 0x09

retlw 0x06

retlw 0x03

retlw 0x00

retlw 0x83

retlw 0x86

retlw 0x89

retlw 0x8c

retlw 0x90

retlw 0x93

retlw 0x96

retlw 0x98

retlw 0x9b

retlw 0x9e

retlw 0xa1

retlw 0xa4

retlw 0xa6

retlw 0xa9

retlw 0xab

retlw 0xad

retlw 0xaf

retlw 0xb1

retlw 0xb3

retlw 0xb5

retlw 0xb7

retlw 0xb8

retlw 0xba

retlw 0xbb

retlw 0xbc

retlw 0xbd

retlw 0xbe

retlw 0xbf

retlw 0xbf

retlw 0xc0

retlw 0xc0

retlw 0xc0

retlw 0xc0

retlw 0xc0

retlw 0xbf

retlw 0xbf

retlw 0xbe

retlw 0xbd

retlw 0xbc

retlw 0xbb

retlw 0xba

retlw 0xb8

retlw 0xb7

retlw 0xb5

retlw 0xb3

retlw 0xb1

retlw 0xaf

retlw 0xad

retlw 0xab

retlw 0xa9

retlw 0xa6

retlw 0xa4

retlw 0xa1

retlw 0x9e

retlw 0x9b

retlw 0x98

retlw 0x96

retlw 0x93

retlw 0x90

retlw 0x8c

retlw 0x89

retlw 0x86

retlw 0x83

org 0x500

getcos:

addwf PCL,F 

retlw 0x40

retlw 0x40

retlw 0x40

retlw 0x3f

retlw 0x3f

retlw 0x3e

retlw 0x3d

retlw 0x3c

retlw 0x3b

retlw 0x3a

retlw 0x38

retlw 0x37

retlw 0x35

retlw 0x33

retlw 0x31

retlw 0x2f

retlw 0x2d

retlw 0x2b

retlw 0x29

retlw 0x26

retlw 0x24

retlw 0x21

retlw 0x1e

retlw 0x1b

retlw 0x18

retlw 0x16

retlw 0x13

retlw 0x10

retlw 0x0c

retlw 0x09

retlw 0x06

retlw 0x03

retlw 0x00

retlw 0x83

retlw 0x86

retlw 0x89

retlw 0x8c

retlw 0x90

retlw 0x93

retlw 0x96

retlw 0x98

retlw 0x9b

retlw 0x9e

retlw 0xa1

retlw 0xa4

retlw 0xa6

retlw 0xa9

retlw 0xab

retlw 0xad

retlw 0xaf

retlw 0xb1

retlw 0xb3

retlw 0xb5

retlw 0xb7

retlw 0xb8

retlw 0xba

retlw 0xbb

retlw 0xbc

retlw 0xbd

retlw 0xbe

retlw 0xbf

retlw 0xbf

retlw 0xc0

retlw 0xc0

retlw 0xc0

retlw 0xc0

retlw 0xc0

retlw 0xbf

retlw 0xbf

retlw 0xbe

retlw 0xbd

retlw 0xbc

retlw 0xbb

retlw 0xba

retlw 0xb8

retlw 0xb7

retlw 0xb5

retlw 0xb3

retlw 0xb1

retlw 0xaf

retlw 0xad

retlw 0xab

retlw 0xa9

retlw 0xa6

retlw 0xa4

retlw 0xa1

retlw 0x9e

retlw 0x9b

retlw 0x98

retlw 0x96

retlw 0x93

retlw 0x90

retlw 0x8c

retlw 0x89

retlw 0x86

retlw 0x83

retlw 0x80

retlw 0x03

retlw 0x06

retlw 0x09

retlw 0x0c

retlw 0x10

retlw 0x13

retlw 0x16

retlw 0x18

retlw 0x1b

retlw 0x1e

retlw 0x21

retlw 0x24

retlw 0x26

retlw 0x29

retlw 0x2b

retlw 0x2d

retlw 0x2f

retlw 0x31

retlw 0x33

retlw 0x35

retlw 0x37

retlw 0x38

retlw 0x3a

retlw 0x3b

retlw 0x3c

retlw 0x3d

retlw 0x3e

retlw 0x3f

retlw 0x3f

retlw 0x40

retlw 0x40

end

 

Other related posts: