Autor Tema: Intentando una pata para hexapodo  (Leído 2253 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Intentando una pata para hexapodo
« en: 16 de Octubre de 2012, 18:05:02 »
Hola compañeros haber si podeis echarme una mano, (al cuello no)  :mrgreen:
La idea empezo aqui http://www.todopic.com.ar/foros/index.php?topic=39106.0 en principio tengo resuelto lo de posicionar el servo, adjunto el programa:
Código: [Seleccionar]
;******************************************************************************************************
; FileName:Main.asm
;******************************************************************************************************

;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
list p = PIC16F873A ; Seleccionar procesador.-
#include "P16F873A.inc" ; Incluir archivo P16F873A.inc

;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file.  See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

ERRORLEVEL -302
ERRORLEVEL -305
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; VARIABLES
;------------------------------------------------------------------------------
; CBLOCK 0x20

; ENDC

;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; CONSTANTES
;------------------------------------------------------------------------------
BYTE_HIGH equ 0xFF
BYTE_LOW equ 0x44
BYTE_20ms equ 0x64

;------------------------------------------------------------------------------
#DEFINE SERVO_0 PORTB,0


;------------------------------------------------------------------------------
; RESET VECTOR
;------------------------------------------------------------------------------
RESET            ORG H'00' ; Aqui comienza el micro.-
  GOTO Main ; Salto a Inicio de mi programa.-
ORG H'05' ; Origen del codigo de programa.-

;------------------------------------------------------------------------------
; VECTOR DE INTERRUPCION
;------------------------------------------------------------------------------



;------------------------------------------------------------------------------
; MAIN PROGRAM
;------------------------------------------------------------------------------
Main    ;**** Configuracion de Puertos ****
bsf STATUS, RP0 ; Bank1
clrf PIE1 ; Disable peripheral interrupts
movlw 0x06
movwf ADCON1
clrf TRISB
movlw b'00000110'
movwf OPTION_REG
bcf STATUS, RP0 ; Bank0
clrf T1CON ; Stop Timer1, Internal Clock Source,
clrf INTCON ; Disable interrupts
clrf PORTB
clrf TMR0
clrf TMR1H ; Clear Timer1 High byte register
clrf TMR1L ; Clear Timer1 Low byte register
clrf PIR1 ; Clear peripheral interrupts Flags
movlw 0x30 ; Internal Clock source with 1:8 prescaler
movwf T1CON ; Timer1 is stopped and T1 osc is disabled

OVFL_WAIT
bsf SERVO_0
movlw BYTE_20ms
movwf TMR0
movlw BYTE_HIGH
movwf TMR1H
movlw BYTE_LOW
movwf TMR1L
bsf T1CON, TMR1ON ; Timer1 starts to increment
btfss PIR1, TMR1IF
goto $-1
bcf PIR1, TMR1IF
bcf SERVO_0
btfss INTCON, T0IF
goto $-1
bcf INTCON, T0IF

bsf SERVO_0
movlw BYTE_20ms
movwf TMR0
movlw 0xFF
movwf TMR1H
movlw 0xB9
movwf TMR1L
bsf T1CON, TMR1ON ; Timer1 starts to increment
btfss PIR1, TMR1IF
goto $-1
bcf PIR1, TMR1IF
bcf SERVO_0
btfss INTCON, T0IF
goto $-1
bcf INTCON, T0IF
goto OVFL_WAIT

END ; Fin del codigo.-
El problema me viene cuando quiero mover el servo de una posicion a otra, he intentado poner un delay entre posicion y posicion creyendo que el problema venia de que no le daba tiempo entre movimientos, pero no es la solucion.
Alguien sabe que hago mal.

Gracias!
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado tapi8

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1506
Re: Intentando una pata para hexapodo
« Respuesta #1 en: 17 de Octubre de 2012, 05:56:32 »
Citar
El problema me viene cuando quiero mover el servo de una posicion a otra, he intentado poner un delay entre posicion y posicion creyendo que el problema venia de que no le daba tiempo entre movimientos, pero no es la solucion.
Alguien sabe que hago mal.

Tienes que repetir cada movimiento una serie de veces, 5 o 6 veces, 3 como minimo (depende del servo), tal y como lo haces lo tienes 20ms en una posicion y pasa a la otra esta otros 20ms y vuelve a la anterior, los servos no suelen ser tan rapidos y tus ojos tampoco  :D
aunque cambie no lo veras. Date cuenta que a esa velocidad estara 25 veces en una posicion y otras 25 veces en la otra, todo en un segundo

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Intentando una pata para hexapodo
« Respuesta #2 en: 17 de Octubre de 2012, 07:36:19 »

 :D :D :D
Gracias tapi por aclararme la duda, sabia lo de repetir el movimiento, pero creia que se hacia para darle tiempo al servo a posicionarse en su sitio, y como al probarlo se posicionaba no di importancia a repetir la secuencia.
Voy a probar y a diseñar la pata.

Saludos!
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Intentando una pata para hexapodo
« Respuesta #3 en: 17 de Octubre de 2012, 19:43:45 »
Código: ASM
  1. ;******************************************************************************************************
  2. ; FileName:Main.asm
  3. ;******************************************************************************************************
  4.  
  5. ;------------------------------------------------------------------------------
  6. ; PROCESSOR DECLARATION
  7. ;------------------------------------------------------------------------------
  8.                 list    p = PIC16F873A          ; Seleccionar procesador.-
  9.                 #include        "P16F873A.inc"  ; Incluir archivo P16F873A.inc
  10.  
  11. ;------------------------------------------------------------------------------
  12. ;
  13. ; CONFIGURATION WORD SETUP
  14. ;
  15. ; The 'CONFIG' directive is used to embed the configuration word within the
  16. ; .asm file. The lables following the directive are located in the respective
  17. ; .inc file.  See the data sheet for additional information on configuration
  18. ; word settings.
  19. ;
  20. ;------------------------------------------------------------------------------
  21.                 __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
  22.  
  23.                 ERRORLEVEL      -302
  24.                 ERRORLEVEL      -305
  25. ;------------------------------------------------------------------------------
  26.  
  27. ;------------------------------------------------------------------------------
  28. ; VARIABLES
  29. ;------------------------------------------------------------------------------
  30.                 CBLOCK  0x20
  31.                 Cont_Desbordes
  32.                 ENDC           
  33.  
  34. ;------------------------------------------------------------------------------
  35.  
  36. ;------------------------------------------------------------------------------
  37. ; CONSTANTES
  38. ;------------------------------------------------------------------------------
  39. BYTE_HIGH                       equ                     0xFF
  40. BYTE_LOW                        equ                     0x44
  41. BYTE_20ms                       equ                     0x64
  42.  
  43. ;------------------------------------------------------------------------------
  44. #DEFINE SERVO_0         PORTB,0
  45. #DEFINE SERVO_1         PORTB,1
  46. #DEFINE SERVO_2         PORTB,2
  47.  
  48. ;------------------------------------------------------------------------------
  49. ; RESET VECTOR
  50. ;------------------------------------------------------------------------------
  51. RESET           ORG                     H'00'                           ; Aqui comienza el micro.-
  52.                         GOTO            Main                            ; Salto a Inicio de mi programa.-
  53.                         ORG                     H'05'                           ; Origen del codigo de programa.-
  54.  
  55. ;------------------------------------------------------------------------------
  56. ; VECTOR DE INTERRUPCION
  57. ;------------------------------------------------------------------------------
  58.  
  59.  
  60.                
  61. ;------------------------------------------------------------------------------
  62. ; MAIN PROGRAM
  63. ;------------------------------------------------------------------------------
  64. Main       ;**** Configuracion de Puertos ****
  65.                         bsf                     STATUS, RP0             ; Bank1
  66.                         clrf            PIE1                            ; Disable peripheral interrupts
  67.                         movlw           0x06
  68.                         movwf           ADCON1
  69.                         clrf            TRISB
  70.                         movlw           b'00000110'
  71.                         movwf           OPTION_REG
  72.                         bcf             STATUS, RP0             ; Bank0
  73.                         clrf            T1CON                           ; Stop Timer1, Internal Clock Source,
  74.                         clrf            INTCON                          ; Disable interrupts   
  75.                         clrf            PORTB
  76.                         clrf            TMR0
  77.                         clrf            TMR1H                           ; Clear Timer1 High byte register
  78.                         clrf            TMR1L                           ; Clear Timer1 Low byte register
  79.                         clrf            PIR1                            ; Clear peripheral interrupts Flags
  80.                         movlw           0x30                            ; Internal Clock source with 1:8 prescaler
  81.                         movwf           T1CON                           ; Timer1 is stopped and T1 osc is disabled
  82.  
  83. SERVO_POS_1    
  84.                         nop
  85.                         bsf                     SERVO_0
  86.                         bsf                     SERVO_1
  87.                         bsf                     SERVO_2
  88.                         movlw           BYTE_20ms
  89.                         movwf           TMR0
  90.                         movlw           BYTE_HIGH
  91.                         movwf           TMR1H
  92.                         movlw           BYTE_LOW
  93.                         movwf           TMR1L
  94.                         bsf                     T1CON, TMR1ON           ; Timer1 starts to increment
  95.                         btfss           PIR1, TMR1IF
  96.                         goto            $-1
  97.                         bcf             PIR1, TMR1IF
  98.                         bcf                     SERVO_0
  99.                         bcf                     SERVO_1
  100.                         bcf                     SERVO_2
  101.                         btfss           INTCON, T0IF
  102.                         goto            $-1
  103.                         bcf                     INTCON, T0IF
  104.                         incf            Cont_Desbordes,1        ; Desbordo, contamos los desbordes
  105.                         movlw           .10                                     ; Contando 10 cada movimiento tardara 200ms
  106.                         subwf           Cont_Desbordes,0        ; Cuanto menor sea el numero mas rapido ira el servo
  107.                         btfss           STATUS, Z
  108.                         goto            SERVO_POS_1
  109.                         clrf            Cont_Desbordes 
  110.                        
  111. SERVO_POS_2
  112.                         bcf                     T1CON, TMR1ON
  113.                         bsf                     SERVO_0
  114.                         bsf                     SERVO_1
  115.                         bsf                     SERVO_2
  116.                         movlw           BYTE_20ms
  117.                         movwf           TMR0
  118.                         movlw           0xFF
  119.                         movwf           TMR1H
  120.                         movlw           0xB9
  121.                         movwf           TMR1L
  122.                         bsf                     T1CON, TMR1ON           ; Timer1 starts to increment
  123.                         btfss           PIR1, TMR1IF
  124.                         goto            $-1
  125.                         bcf             PIR1, TMR1IF
  126.                         bcf                     SERVO_0
  127.                         bcf                     SERVO_1
  128.                         bcf                     SERVO_2
  129.                         btfss           INTCON, T0IF
  130.                         goto            $-1
  131.                         bcf                     INTCON, T0IF
  132.                         incf            Cont_Desbordes,1        ; Desbordo, contamos los desbordes
  133.                         movlw           .10                                     ; Contando 10 cada movimiento tardara 200ms
  134.                         subwf           Cont_Desbordes,0        ; Cuanto menor sea el numero mas rapido ira el servo
  135.                         btfss           STATUS, Z
  136.                         goto            SERVO_POS_2
  137.                         clrf            Cont_Desbordes
  138.                         goto            SERVO_POS_1
  139.  
  140.                         END                                                             ; Fin del codigo.-
Os dejo el codigo funcionando de forma correcta, voy a ver si diseño la pata y hago pruebas de peso y esfuerzo para ver hasta donde soportan los servos.

Gracias tapi por estar ahi cuando he necesitado ayuda.

Saludos!
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado tapi8

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1506
Re: Intentando una pata para hexapodo
« Respuesta #4 en: 18 de Octubre de 2012, 05:52:01 »
Me alegro que empiece a ir bien. Si quieres verlo mejor y comprobar los grados para saber si esta bien ponle en vez de 10 que seran solo 200ms, ponle por ejemplo 200 y asi estara 4seg. en cada posicion y lo veras con mas calma y mejor.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re: Intentando una pata para hexapodo
« Respuesta #5 en: 30 de Noviembre de 2012, 19:09:44 »
Sigo liado con los servos, os dejo la controladora por si alguien quiere montarla, me falta la alimentacion la cual se montara en una PCB aparte.

Saludos!
« Última modificación: 30 de Noviembre de 2012, 19:23:06 por Miquel_S »
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.