Motor speed control program

Discussion in 'Programmer's Corner' started by vishant, Nov 15, 2009.

  1. vishant

    Thread Starter New Member

    Nov 13, 2009
    1
    0
    you have microcontroller based dc motor speed controller assembly program?
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    Welcome to AAC.

    Your post hijacked an old thread - http://forum.allaboutcircuits.com/showthread.php?t=25525 - that was on another topic. It's much smarter to open your own thread so you get the right attention.

    You need to supply more information to us. What hardware have you got to actually run the motor, how do you want to control the speed, and what specific microcontroller do you have in mind?
     
  3. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi vishant,
    Here I present a simple DC motor control circuit with PIC16F877A with program written in assembly language.
    Code ( (Unknown Language)):
    1.  
    2. ; SOURCE CODE FOR DC MOTOR CONTROL WITH PIC16F877A
    3. ; -------------------------------------------------
    4.  
    5. ; PREPARED BY-- SYED TAHMID MAHBUB
    6.  
    7. ; DATED-- 21-04-09  
    8.  
    9. ;---------------------------------------------------------------
    10.  
    11.     TITLE: "DC MOTOR CONTROL WITH PIC 16F877A"  
    12.        
    13.         LIST   P=16F877A
    14.  
    15.        INCLUDE "P16F877A.INC"
    16.  
    17.        __CONFIG    H'3F72'
    18.  
    19.      ; __CONFIG _HS_OSC & _WDG_OFF & _PWRTE_ON & _CP_OFF
    20.  
    21.      ; 10 MHZ EXTERNAL CRYSTAL OSCILLATOR.    
    22.      
    23. ;----------------- PROGRAM START -------------------------------------
    24.  
    25.  
    26.            ORG     0X00          ; RESET VECTOR
    27.            GOTO    INIT
    28.            ORG     0X04          ; INTERRUPT VECTOR
    29.            GOTO    INTR_SVC  
    30.  
    31. ;------------------ INITIAL PROCESS ------------------------------
    32.  
    33. ;-- PORT INITIALIZATION
    34.  
    35. INIT
    36.            BSF      STATUS,RP0    ; CHANGE TO BANK 1
    37.            MOVLW    B'00000001'   ; AN0 TO INPUT MODE
    38.            MOVWF    TRISA         ; SET TRISA REGISTER
    39.            CLRF     TRISC         ; MAKING PORTC ALL OUTPUT
    40.            BCF      STATUS,RP0    ; CHANGE TO BANK0
    41.  
    42.  
    43. ;--- A/D CONVERTER INITIALIZATION
    44.  
    45.            MOVLW    B'10000001'   ; FOSC/32,RA0/AN0,ADON=ON
    46.            MOVWF    ADCON0        ; SET ADCON0 REGISTER
    47.            BSF      STATUS,RP0    ; CHANGE TO BANK 1
    48.            MOVLW    B'00001110'   ; ADFM=0,PCFG=1110
    49.            MOVWF    ADCON1        ; SET ADCON1 REGISTER,IN BANK 1
    50.            BCF      STATUS,RP0    ; FALLING BACK TO BANK 0
    51.  
    52. ;--- PWM  INITIALIZATION
    53.  
    54.            CLRF     TMR2          ; CLEAR TMR2 REGISTER
    55.            CLRF     CCPR1L        ; CLEAR CCPR1L REGISTER
    56.            BSF      STATUS,RP0    ; CHANGE TO BANK 1
    57.            MOVLW    D'255'        ; PERIOD = 1638.4USEC(610 HZ)
    58.            MOVWF    PR2           ; SET PR2 REGISTER,IN BANK 1
    59.            BCF      STATUS,RP0    ; CHANGE TO BANK 0
    60.            MOVLW    B'00000110'   ; PST=1:1,TMR1=ON,PRE=1:16
    61.            MOVWF    T2CON         ; SET T2CON REGISTER
    62.            MOVLW    B'00001100'   ; CCP1XY=0,CCP1M=1100(PWM)
    63.            MOVWF    CCP1CON       ; SET CCP1CON REGISTER
    64.  
    65. ;--- COMPARE MODE INITIALIZATION
    66.  
    67.            CLRF     TMR1H         ; CLEAR TMR1H REGISTER
    68.            CLRF     TMR1L         ; CLEAR TMR1L REGISTER
    69.            MOVLW    0X09          ; H '9C4'=2500
    70.            MOVWF    CCPR2H        ; SET CCPR2H REGISTER
    71.            MOVLW    0XC4          ; 2500 X 0.4 uSEC = 1MSEC
    72.            MOVWF    CCPR2L        ; SET CCPR2L REGISTER
    73.            MOVLW    B'00000001'   ; TMR1= ON
    74.            MOVWF    T1CON         ; SET T1 REGISTER
    75.            MOVLW    B'00001011'   ; SET SPECIAL TRIGGER FOR A/D CONVERSION
    76.            MOVWF    CCP2CON       ; SET CCP2CON REGISTER
    77.  
    78. ;---INTERRUPTION  CONTROL
    79.  
    80.            BSF      STATUS,RP0
    81.            MOVLW    B'00000001'   ; CCP2IE = ENABLE
    82.            MOVWF    PIE2          ; SET PIE2 REGISTER
    83.            BCF      STATUS,RP0
    84.            MOVLW    B'11000000'   ; GIE = ON, PEIE = ON
    85.            MOVWF    INTCON        ; SET INTCON REGISTER
    86.  
    87. WAIT
    88.            GOTO     $             ; WAIT FOR INTERRUPTION
    89.  
    90. ;------------------- INTERRUPTION  PROCESS --------------------------
    91. INTR_SVC
    92.            CLRF     PIR2          ; CLEAR INTERRUPTION FLAG
    93. AD_CHECK  
    94.            BTFSC    ADCON0,GO     ; A/D CONVERT END?
    95.            GOTO     AD_CHECK      ; NO.CHECK AGAIN
    96.            MOVF     ADRESH,W      ; READ ADRESH REGISTER
    97.            MOVWF    CCPR1L       ; RESET DUTY CYCLE OF PWM
    98.            RETFIE
    99.  
    100. ;------------------- END OF INTERRUPTION PROCESS ---------------------
    101.  
    102.            END
    103.  
    104.  
    105. ;--------------------------------------------------------------------
    106. ;                   END OF THE MOTOR CONTROL PROCESS
    107. ;--------------------------------------------------------------------
    108.  
     
Loading...