Bilgi Paylaşıldığında güzeldir

18 Mart 2013 Pazartesi

16F628A İle Hız Ayarlı Ekranlı Step Motor Devresi






Hex Kodu Açılımı



Proteus ve Hex Download



Program kodu :
'****************************************************************
'*  Name    : Step_Motor_Kontrol.BAS                            *
'*  Author  : [Mucit]                                      *
'*  Notice  : Rev 1.5                                           *
'*          :                                                   *
'*  Date    : 17.09.2012                                        *
'*  Version : 1.0                                               *
'*  Notes   : www.arectron.com                                  *
'*          :                                                   *
'****************************************************************
'---------------------------Device Configuration--------------------------------
DEFINE OSC 4

@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF

TRISA=%00111111
TRISB=$00
PORTA=$00
PORTB=$00

CMCON=7

'------------------------------LCD_Configuration--------------------------------
DEFINE LCD_DREG   PORTB
DEFINE LCD_DBIT   4
DEFINE LCD_RSREG  PORTB
DEFINE LCD_RSBIT  1
DEFINE LCD_EREG   PORTB
DEFINE LCD_EBIT   2
DEFINE LCD_LINES  2
DEFINE LCD_BITS   4
'-----------------------------PWM Configuration---------------------------------    
T2CON = %00000110
PR2=249	                   ;Default PWM frequency (250Hz)
DEFINE CCP1_REG   PORTB
DEFINE CCP1_BIT   3
'----------------------input and output configuration---------------------------
symbol  Mot_Start= PORTA.0
SYMBOL  Mot_Stop = PORTA.1
symbol  UP       = PORTA.2
SYMBOL  DOWN     = PORTA.3
symbol  Mot_Drec = PORTA.4
symbol  SET      = PORTA.5
symbol  Mot_CCW  = PORTA.6
SYMBOL  Mot_Mod  = PORTB.0
sYMBOL  Mot_Enb  = PORTA.7
'-------------------------Variables and Constants-------------------------------
PWM_Duty         con 50          ;Value for Duty
MAX_FREQ         CON 17          ;249=500Hz - 18=3333Hz 
PWM_Freq         var word        ;PWM Frequency
Calc_Duty        var WORD        ;Calculated Value of Duty 
Motor_RPM        var word        ;Value of MotorRPM
Set_Motor_RPM    var word        ;Soft Start Speed Value
Btn_Syc          var WORD        ;
Max_RPM          var word        ;     
Min_RPM          VAR WORD        ;
Mot_Num_Step     var word        ;A round number of steps the motor
Mot_Step_Ang     var byte        ;Motor step angle
Mot_Old_Freq     var byte        ;
Soft_Start_Stage var byte        ;
Index            VAR BYTE
Char             var byte
i                var byte
Char_Adres       var byte
LCD_Adres        var byte        ;LCD adres
LCD_LINE         VAR BYTE
Temp             var BYTE        ;
Driving_Mode     var BIT         ;Motor Driving Mode, 0=Half, 1=Full
PWM_Status       var BIT         ;1=PWM Enable, 0=PWM Disable 
Step_Select      var bit

  READ $0,Mot_Step_Ang
  Read $2,Set_Motor_Rpm.LOWBYTE
  READ $3,SET_MOTOR_RPM.HIGHBYTE
  If Set_Motor_Rpm>1100 then Set_Motor_rpm=0
  read $4,Soft_Start_Stage:IF Soft_Start_Stage>10 then Soft_Start_Stage=1
  IF MOT_STEP_ANG<>18 AND Mot_Step_Ang<>75 then Mot_Step_Ang=18

PAUSE 200
GOSUB LCD_CLEAR
GOSUB LOADING
Load_Prog:
  GOSUB LCD_CLEAR
  PWM_STATUS=0:BTN_SYC=0
  read $1,Driving_Mode:If Driving_Mode>1 then Driving_Mode=0
  LCD_LINE=$C0:gosub Mot_Mod_Write
  lcdout $FE,$C5,dec1 MOT_STEP_ANG DIG 1,",", DEC1 MOT_STEP_ANG DIG 0  
Main:

  IF UP=0 THEN 
       IF PWM_STATUS=0 THEN 
         GOSUB PWM_ON
         GOSUB PWM_DUTY_UPDATE
         GOTO JUMP
       ENDIF
    PR2=PR2-1
    IF PR2100 THEN 
        btn_SYC=100
        PR2=PR2-1
        IF PR2100 THEN
        BTN_SYC=100
        PR2=PR2+1
        IF PR2>249 THEN 
        PR2=249:gosub PWM_OFF
        ENDIF
        GOSUB PWM_DUTY_Update
        GOSUB Mot_RPM_Calc
      ENDIF
    WEND
    IF PR2>249 THEN 
    PR2=249:gosub PWM_OFF
    ENDIF
    BTN_SYC=0
    GOSUB PWM_DUTY_UPDATE
  endif

  JUMP:WHILE UP=0 OR DOWN=0:PAUSE 1:WEND
  
  gOSUB Mot_RPM_Calc
  
  IF PWM_Status=1 then  
    IF Mot_Drec=0 THEN 
      GOSUB Motor_Direction
    endIF
  
    If Mot_Stop=0 tHEN
      GOSUB Motor_Stop
    ENDIF
    ELSE
    IF Mot_Start=0 then 
      GOSUB PWM_ON
      GOSUB Motor_Start
    endIF
  endIF
  
  IF SET=0 THEN
    gosub PWM_OFF 
    WHILE SET=0 
      Btn_SYC=Btn_SYC+1
      PAUSE 5
      IF btn_SYC>400 THEN 
        btn_SYC=0
        GOSUB PWM_OFF
        GOTO STEP_MOD
      endIF
    WEND
    btn_syc=0
    GOTO SET_MENU
  ENDIF
  
GOTO Main

Mot_Mod_Write:

  IF Driving_Mode=1 then 
    FOR i=0 TO 3
      iNDEX=52+i
      GOSUB SET_CHAR
      LCD_ADRES=LCD_LINE+i
      GOSUB LCD_WRITE
    NEXT
    Mot_Mod=0
    ELSE
    FOR i=0 TO 3
      iNDEX=48+i
      GOSUB SET_CHAR
      LCD_ADRES=LCD_LINE+i
      GOSUB LCD_WRITE
    NEXT
    Mot_Mod=1
  endif
return

PWM_Duty_UpDate:                  ;Updated Value of Duty Section
   Calc_Duty=(PR2+1)*pwm_Duty/25
   CCP1CON.4=Calc_Duty.0
   CCP1CON.5=Calc_Duty.1
   CCPR1L=Calc_Duty>>2
return

Mot_RPM_Calc:

IF PWM_Status=1 then
  PWM_Freq=62500/(PR2+1)
else
  PWM_Freq=0
enDIF

IF Mot_Step_Ang=18 then  ; 1.8 Degree Motor(200Step/tour-Full) 
  Motor_RPM=(PWM_fREQ*3)/10   ;Mot RPM= Pwm frequency*(60/200)
  IF Driving_Mode=0 THEN mOTOR_rpm=mOTOR_RPM/2    
ENDIF
IF mOT_STEP_ANG=75 THEN   ; 7.5 Degree Motor(48Step/tour-Full)  
  MOTOR_RPM=((pwm_fREQ*12)/10)+((PWM_Freq*5)/100);Mot RPM= Pwm frequency*(60/48)
  IF Driving_Mode=0 THEN mOTOR_rpm=MOTOR_RPM/2
ENDIF   

IF PWM_STATUS=1 THEN  
  LCD_Adres=$80:Gosub LCD_Write_RPM 
  ELSE
  char_adres=56
  lcd_line=$80
  gosub LCD_Send_Char
ENDIF

return

Motor_Direction:

    Mot_Old_Freq=PR2
    for PR2=Mot_Old_Freq to 248  '250 Hz
      GOSUB PWM_Duty_Update
      Gosub Mot_RPM_Calc
      LCD_Adres=$80:Gosub LCD_Write_RPM
      pause 10
    next
    Mot_Enb=0
    pause 100
    Mot_CCW= 1 ^ Mot_CCW
    Mot_Enb=1
    for PR2=249 to (Mot_Old_freq+1) step -1
      GOSUB PWM_Duty_Update
      Gosub Mot_RPM_Calc
      LCD_Adres=$80:Gosub LCD_Write_RPM
      pause (SOFT_START_STAGE*10)
    NEXT

return 

Motor_Start: 
WHILE MOTOR_RPM"
    gosub LCD_WRITE
    MOT_CCW=1:MOT_ENB=1 
    HIGH PORTB.3
    PAUSEUS 500
    LOW PORTB.3
    WHILE UP=0
      Btn_SYC=Btn_SYC+1
      PAUSE 5
      IF btn_SYC>150 THEN 
        btn_SYC=150 
        TOGGLE PORTB.3
        PAUSEUS 400
      endIF
    wend
    BTN_SYC=0
    PORTB.3=0
    MOT_ENB=0
    CHAR="-":GOSUB LCD_WRITE
  endif
  
  IF DOWN=0 THEN 
    lcd_adres=$C5:CHAR="<"
    GOSUB LCD_WRITE
    MOT_CCW=0:MOT_ENB=1
    HIGH PORTB.3
    PAUSEUS 500
    LOW PORTB.3
    WHILE DOWN=0
      Btn_SYC=Btn_SYC+1
      PAUSE 5
      IF btn_SYC>150 THEN 
        btn_SYC=150 
        TOGGLE PORTB.3
        PAUSEUS 400
      endIF
    wend
    BTN_SYC=0
    PORTB.3=0
    MOT_ENB=0
    CHAR="-":GOSUB LCD_WRITE
  endif
  
  IF Mot_DREC=0 then 
    Driving_Mode=1-Driving_Mode
    while Mot_DREC=0:wend
  ENDIF
  
  gosub Mot_Mod_Write
  
  IF SET=0 THEN 
    WHILE SET=0:WEND
    GOTO LOAD_PROG
  ENDIF
  
goto Step_Mod_1

SET_MENU:
TEMP=0
  READ $0,Mot_Step_Ang
  read $1,Driving_Mode:If Driving_Mode>1 then Driving_Mode=0
  Read $2,Set_Motor_Rpm.LOWBYTE
  READ $3,SET_MOTOR_RPM.HIGHBYTE
  If Set_Motor_Rpm>4300 then Set_Motor_rpm=0
  read $4,Soft_Start_Stage:IF Soft_Start_Stage>10 then Soft_Start_Stage=1
  IF MOT_STEP_ANG<>18 AND Mot_Step_Ang<>75 then Mot_Step_Ang=18
  GOSUB LCD_CLEAR
    char_adres=0
    lcd_line=$80
    gosub LCD_Send_Char  
;    lcdout $FE,$80,"Step Ang"
MENU:
SELECT CASE TEMP
  CASE 0  ;Motor Step Ang
      
      IF UP=0 OR DOWN=0 THEN 
        STEP_SELECT= 1 ^ STEP_SELECT
        WHILE UP=0 OR DOWN=0:PAUSE 1:WEND
        IF STEP_SELECT=1 THEN
          MOT_STEP_ANG=75
        ELSE
          MOT_STEP_ANG=18
        ENDIF
      ENDIF
      
        LCDOUT $FE,$C1,">",dec1 MOT_STEP_ANG DIG 1,",", DEC1 MOT_STEP_ANG DIG 0
      
      IF SET=0 THEN 
        TEMP=1
        WHILE SET=0:PAUSE 1:WEND
        GOSUB LCD_CLEAR
        char_adres=8
        lcd_line=$80
        gosub LCD_Send_Char
        INDEX=64:GOSUB SET_CHAR
        LCD_ADRES=$C1:GOSUB LCD_WRITE
        LCD_LINE=$C2
      ENDIF
      
  CASE 1   ;Motor Driving Mod
  
    IF UP=0 OR DOWN=0 THEN
      DRIVING_MODE=1 ^ dRIVING_MODE
      WHILE UP=0 OR DOWN=0:PAUSE 1:WEND
    ENDIF
    
    GOSUB MOT_mOD_WRITE
    
    IF SET=0 THEN 
        TEMP=2
        WHILE SET=0:PAUSE 1:WEND
        IF Mot_Step_Ang=18 THEN
          IF Driving_Mode=1 then 
           Min_RPM=75:Max_RPM=1000
          ELSE
           Min_rpm=37:max_rpm=500
          endif
        ELSE
          IF Driving_Mode=1 then 
           Min_RPM=312:Max_RPM=3300
          ELSE
           Min_rpm=156:max_rpm=1650
          endif
        endif
          IF SET_MOTOR_RPMMAX_RPM THEN SET_MOTOR_RPM=MIN_RPM
          GOSUB LCD_CLEAR
          char_adres=16
          lcd_line=$80
          gosub LCD_Send_Char
    ENDIF 
    
  CASE 2 ;Soft Start RPM
  
  Motor_RPM=Set_Motor_RPM
  LCD_Adres=$C0:Gosub lcd_Write_RPM
  
  IF UP=0 THEN 
    Set_Motor_RPM=Set_Motor_RPM+1
    IF SET_Motor_RPM=>Max_RPM then 
      SET_MOTOR_RPM=MAX_RPM
      GOTO EXITIF
    ENDIF
      WHILE UP=0
        BTN_SYC=BTN_SYC+1
        PAUSE 5
          IF BTN_SYC=>100 THEN
            BTN_SYC=100
            SET_MOTOR_RPM=SET_MOTOR_RPM+1
            IF SET_Motor_RPM=>Max_RPM then 
              SET_MOTOR_RPM=MAX_RPM
              GOTO EXITIF
            ENDIF
            Motor_RPM=Set_Motor_RPM
            LCD_Adres=$C0:Gosub LCD_Write_rpm
            PAUSE 10
          ENDIF
      WEND
      BTN_SYC=0
  ENDIF 
  
  IF DOWN=0 THEN 
    Set_Motor_RPM=Set_Motor_RPM-1
    IF SET_Motor_RPM<=Min_Rpm Then 
      SET_MOTOR_RPM=MIN_RPM 
      GOTO EXITIF
    ENDIF
      WHILE DOWN=0
        BTN_SYC=BTN_SYC+1
        PAUSE 5
          IF BTN_SYC=>100 THEN
            BTN_SYC=100
            SET_MOTOR_RPM=SET_MOTOR_RPM-1
            IF SET_Motor_RPM<=Min_Rpm Then
              SET_MOTOR_RPM=MIN_RPM 
              GOTO EXITIF
            ENDIF
            Motor_RPM=Set_Motor_RPM
            LCD_Adres=$C0:Gosub LCD_Write_RPM
            PAUSE 10
          ENDIF
      WEND
      BTN_SYC=0
  ENDIF 
  EXITIF:
  
    IF SET=0 THEN 
        TEMP=3:Motor_RPM=0
        WHILE SET=0:PAUSE 1:WEND
        GOSUB LCD_CLEAR
        char_adres=16
        lcd_line=$80
        gosub LCD_Send_Char
    ENDIF 
  
  CASE 3
    
    lcdout $FE,$C0,"Acc=",dec2 Soft_Start_Stage
    
    IF UP=0 THEN 
      Soft_Start_Stage=Soft_Start_Stage+1
      IF SOFT_START_STAGE>10 THEN SOFT_START_STAGE=10
      WHILE UP=0:WEND
    ENDIF 
    
    IF DOWN=0 THEN 
      Soft_Start_Stage=Soft_Start_Stage-1
      IF SOFT_START_STAGE=0 THEN SOFT_START_STAGE=1
      WHILE DOWN=0:WEND
    ENDIF
    
    IF SET=0 THEN 
      GOTO Save_the_Settings
    endIF 
      
END SELECT
GOTO MENU  
  
Save_the_Settings:
  WRITE $0,Mot_Step_ang:pause 10
  WRITE $1,DRIVING_MODE:PAUSE 10
  WRITE $2,Set_Motor_RPM.LOWBYTE:pause 10
  WRITE $3,SET_MOTOR_RPM.HIGHBYTE:PAUSE 10
  WRITE $4,Soft_Start_Stage:pause 10
  WHILE SET=0:WEND
goto LOAD_PROG

PWM_ON:         ;PWM ON..
  CCP1CON.2=1
  CCP1CON.3=1 
  Mot_ENB=1
  PWM_Status=1
RETURN

PWM_OFF:        ;PWM OFF
  CCP1CON.2=0
  CCP1CON.3=0
  MOT_ENB=0
  PWM_Status=0
  PR2=249
  GOSUB PWM_Duty_Update 
RETURN

LOADING:
CHAR="*"
FOR i=0 TO 7
  LCD_ADRES=$80+i
  GOSUB LCD_WRITE
  PAUSE 100
NEXT
FOR i=0 TO 7
  LCD_ADRES=$C0+i
  GOSUB LCD_WRITE
  PAUSE 100
NEXT

FOR i=0 to 7
  INDEX=32+i
  GOSUB SET_CHAR
  LCD_ADRES=$80+i
  GOSUB LCD_WRITE
  PAUSE 100
next

FOR i=0 TO 7
  iNDEX=40+i
  GOSUB SET_CHAR
  LCD_ADRES=$C0+i
  GOSUB LCD_WRITE
  PAUSE 100
NEXT
PAUSE 1500
RETURN

LCD_CLEAR:
  LCDOUT $FE,1
RETURN

LCD_SEND_CHAR:
  FOR i=0 TO 7
    iNDEX=cHAR_Adres+i
    GOSUB SET_CHAR
    LCD_ADRES=LCD_Line+i
    GOSUB LCD_WRITE
  NEXT
RETURN

Set_Char: ;Reading Character
   lookup INDEX,["Step_AngDriv_ModSoftStrtStep_Modwww.arectron.comHalfFullRPM=---->"],CHAR
return
   ;Start Adres
   ;Step_Ang=0
   ;Driv_Mod=8
   ;SoftStrt=16
   ;Step_Mod=24
   ;www.arectron.com=32
   ;Half=48, Full=52
   ;RPM=----=56,>=64
   ;Acc= =65
LCD_Write:
  LCDOUT $FE,LCD_Adres,CHAR
return

LCD_Write_RPM:
    LCDOUT $FE,LCD_Adres,"RPM=",dec4 Motor_RPM
return

end



2 yorum:

Unknown dedi ki...

merhaba
öncelikle güzel paylaşımlarınız için teşekkürler.
size bir şey soracaktı. Elimde bir step motor sürücü devresi var yani çalıştırdım. fakat isis dosyasını kaybettim. Fakat diğer dosyaları bulunuyor.
dosyaların uzantıları da şöyle
STEPMTR.brd
Stp_mtr2.hex

Eyyup KÜÇÜKASLAN dedi ki...

devreyi yeniden çizmen gerek hex dosyası işine yarar