Controlling servo motor with PIC16F877A (Assembly Language)

Author
jasonheng
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2006/12/24 01:42:58
  • Location: 0
  • Status: offline
2006/12/24 01:54:20 (permalink)
0

Controlling servo motor with PIC16F877A (Assembly Language)

Good day, people!
 
i am using PIC16F877A for my final year project. part of the system requires controlling servo motor.
 
i am having trouble controlling the servo motor. Firstly i tried running it CLOCKWISE with 2.0ms pulse width; it works. Then i tried running it ANTI-CLOCKWISE with 1.0ms pulse; it worked perfectly as well.
 
the problem is when i tried to do this;
running it anti-clockwise around 2 seconds, then STOP for 2 seconds. Then continue running again. so it is basically on and off. But it just continue running anti clockwise.


LIST  P=16F877a, W=-302
  #include <p16f877a.inc>
  __CONFIG 0x3D72 ; XT MODE,WDT OFF, BOREN
  
BANK_0  EQU  0x00
BANK_1  EQU  0x80
BANK_2  EQU  0x100
BANK_3  EQU  0x180
COUNT1  EQU  0x20
COUNT2  EQU  0x40
COUNT3  EQU  0x60                               
 
   ORG  0x00
            
   MOVLW B'11111110'
   BANKSEL BANK_1
   MOVWF TRISB
   BANKSEL BANK_0  
 
Start     
Anti       MOVLW   B'11111111'         
            MOVWF   PORTB     
            CALL       Delay1 
            CALL       Delay1                          
            CALL       Delay1
            CALL       Delay1
            MOVLW    B'00000000'                          
            MOVWF   PORTB  
            CALL       Delay1
            CALL       Delay1
            CALL       Delay1
            CALL       Delay1 
            DECFSZ   COUNT1,F
            GOTO      Anti
            CALL       Delay2
            CALL       Delay3
  
                  
Pause    MOVLW    B'11111111'         
            MOVWF    PORTB     
            CALL       Delay1
            CALL       Delay1                          
            CALL       Delay1 
            CALL       Delay1
            CALL       Delay1
            CALL       Delay1
            MOVLW   B'00000000'                          
            MOVWF   PORTB  
            CALL       Delay1
            CALL       Delay1
            CALL       Delay1 
            CALL       Delay1
            CALL       Delay1
            CALL       Delay1
 
            DECFSZ   COUNT1,F
            GOTO      Pause
            CALL       Delay2
            CALL       Delay4
            GOTO      Start
 
Delay4            
   MOVLW 0x20
   MOVWF COUNT3

Loop4
   DECFSZ COUNT3,F 
   GOTO Pause
   RETURN
 
Delay3            
   MOVLW 0x20
   MOVWF COUNT3

Loop3
   DECFSZ COUNT3,F 
   GOTO Clockwise
   RETURN
 
Delay2            
   MOVLW 0xF9
   MOVWF COUNT2

Loop2
   DECFSZ COUNT2,F 
   GOTO Loop2
   RETURN

Delay1             
   MOVLW 0xF9
   MOVWF COUNT1

Loop1
   DECFSZ COUNT1,F
   GOTO Loop1
   RETURN 
 
   END

 
can someone please help me point out the error? thanks!
#1

3 Replies Related Threads

    assaad
    Super Member
    • Total Posts : 2504
    • Reward points : 0
    • Joined: 2006/03/27 22:51:42
    • Location: Turkey
    • Status: offline
    RE: Controlling servo motor with PIC16F877A (Assembly Language) 2006/12/24 02:43:36 (permalink)
    0
    ORIGINAL: jasonheng

    G
    LIST  P=16F877a, W=-302
     #include <p16f877a.inc>
     __CONFIG 0x3D72 ; XT MODE,WDT OFF, BOREN
     
    BANK_0  EQU  0x00
    BANK_1  EQU  0x80
    BANK_2  EQU  0x100
    BANK_3  EQU  0x180
    COUNT1  EQU  0x20
    COUNT2  EQU  0x40
    COUNT3  EQU  0x60                               

      ORG  0x00
               
      MOVLW B'11111110'
      BANKSEL BANK_1
      MOVWF TRISB
      BANKSEL BANK_0  

    Start     
    Anti       MOVLW   B'11111111'         
               MOVWF   PORTB     
               CALL       Delay1 
               CALL       Delay1                          
               CALL       Delay1
               CALL       Delay1
               MOVLW    B'00000000'                          
               MOVWF   PORTB  
               CALL       Delay1
               CALL       Delay1
               CALL       Delay1
               CALL       Delay1 
               DECFSZ   COUNT1,F
               GOTO      Anti
               CALL       Delay2
               CALL       Delay3
     
                     
    Pause    MOVLW    B'11111111'         
               MOVWF    PORTB     
               CALL       Delay1
               CALL       Delay1                          
               CALL       Delay1 
               CALL       Delay1
               CALL       Delay1
               CALL       Delay1
               MOVLW   B'00000000'                          
               MOVWF   PORTB  
               CALL       Delay1
               CALL       Delay1
               CALL       Delay1 
               CALL       Delay1
               CALL       Delay1
               CALL       Delay1

               DECFSZ   COUNT1,F
               GOTO      Pause
               CALL       Delay2
               CALL       Delay4
               GOTO      Start

    Delay4            
      MOVLW 0x20
      MOVWF COUNT3

    Loop4
      DECFSZ COUNT3,F 
      GOTO Pause
      RETURN

    Delay3            
      MOVLW 0x20
      MOVWF COUNT3

    Loop3
      DECFSZ COUNT3,F 
      GOTO Clockwise
      RETURN


     
    I am in hurry , so sorry for this fast post.
    but you have problem with banking ,  
     
    BANK_0  EQU  0x00!!!!
    and GOTO Clockwise, I dont see any Clockwise in your code!

    S. ASSAAD
    #2
    DarioG
    Scheisse Menschen
    • Total Posts : 52257
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: hi there
    • Status: offline
    RE: Controlling servo motor with PIC16F877A (Assembly Language) 2006/12/24 03:14:20 (permalink)
    0
    ORIGINAL: assaad
    [...]but you have problem with banking ,  

    BANK_0  EQU  0x00!!!!
    and GOTO Clockwise, I dont see any Clockwise in your code!


    No, well, why? It should work, it's just a cumbersome way to use Banksel, since there's no need to define such "BANK_0" things: just do "BANKSEL TRISB" or "BANKSEL COUNT1"
    The OP problem should be somewhere else.

    Dario Greggio
    --
    Wouldn't it be wonderful, if you lost one son for every promise you don't keep?
    #3
    assaad
    Super Member
    • Total Posts : 2504
    • Reward points : 0
    • Joined: 2006/03/27 22:51:42
    • Location: Turkey
    • Status: offline
    RE: Controlling servo motor with PIC16F877A (Assembly Language) 2006/12/25 13:26:14 (permalink)
    0
    YES DARIOG , you are right, no problem with that.
    sorry about that post , because I was inhurry!
    :)

    S. ASSAAD
    #4
    Jump to:
    © 2017 APG vNext Commercial Version 4.5