Autor Tema: Control de grados servo mediante un boton  (Leído 1466 veces)

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

Desconectado cristianpalta1

  • PIC10
  • *
  • Mensajes: 5
Control de grados servo mediante un boton
« en: 18 de Marzo de 2016, 21:36:26 »
Muy buenas hace mucho publique en el foro sobre los servos gracias a killer me puse a leer y utilice timer en el contro de los servos ahora mi pregunta eh podido hacer que mande un pulso constantemente. Pero no me detecta el pulso mandado. Alguna ayuda muchas gracias.
Adjunto Codigo:
Código: CSS
  1. #use standard_io(D)
  2. #use standard_io(A)
  3. #use standard_io(B)
  4.  
  5. #define Servomotor PIN_D0
  6. #define In1 PIN_A0
  7. #define In2 PIN_A1
  8.  
  9. #define LCD_RS    PIN_B0
  10. #define LCD_E     PIN_B2 //Inicializo mi LCD
  11. #define LCD_DB4   PIN_B4
  12. #define LCD_DB5   PIN_B5
  13. #define LCD_DB6   PIN_B6
  14. #define LCD_DB7   PIN_B7
  15.  
  16. #include <lcd1.c>
  17.  
  18. const int Pi=31; // const = Los datos son de solo lectura, se puede colocar los datos en la memoria para ahorrar espacio "Pulsoinicial"
  19. const int Pm=93; // "Pulsomedio"
  20. const int Pu=155; // "Pulsoultimo"
  21. const int C=30; // Por que 1seg equivalen a 30 RTCC(desbordamiento por timer) Prescale1:16
  22.  
  23. int Bt0 = 0, Bs= 0;  //Bandera t0/s; t0 -> timer0 ; s-> servo
  24. int Kt0 = 0; //Contador timer0
  25. int servo = Pu;
  26. char Bt;
  27.  
  28. void lcd ()
  29. {
  30.   printf(lcd_putc,"\f Posicion servo  \n Servo = %u",servo);
  31.   delay_ms(200);
  32. }
  33.  
  34. void posicion_servo()
  35. {
  36.  switch (Bt)
  37.  {
  38.  case 'D':
  39.    if(++servo > Pu)
  40.     {
  41.      servo = Pu;
  42.     }
  43.    break;
  44.  case 'I':
  45.    if(--servo < Pi)
  46.    {
  47.     servo = Pi;
  48.    }
  49.    break;
  50.  }
  51. }
  52.  
  53. #int_Timer0
  54. Timer0_pulso()
  55. {
  56.  Kt0++;
  57.  if (Kt0 == 4)
  58.  {
  59.   set_timer0(C); //inicializo timer
  60.  }
  61.  if (Kt0 == 5)
  62.  {
  63.   Bt0 = 1;
  64.   Kt0 = 0;
  65.  }
  66. }
  67.  
  68. void main()
  69. {
  70.  int ValorT0;
  71.  lcd_init();
  72.  setup_timer_0(RTCC_INTERNAL | RTCC_DIV_16 );
  73.  enable_interrupts(GLOBAL);
  74.  enable_interrupts(INT_TIMER0);
  75.  lcd();
  76.  set_timer0(0);
  77.  set_tris_a(0xFF);
  78.  
  79.  do
  80.  {
  81.   //Disparo el pulso para PWM
  82.   if(Bt0 ==1)
  83.   {
  84.    Bt0 =0;                  
  85.    output_high(Servomotor);
  86.    Bs = 1;
  87.    }
  88.    // Controlo eL ancho de pulso PWM
  89.    if(Bs=1)
  90.    {
  91.     ValorT0 = get_TIMER0(); // Asigno a ValorT0 el valor del timer0
  92.     if(ValorT0 > servo) // timer0 > 0.5ms
  93.     {
  94.      Bs=0;
  95.      output_low(Servomotor);
  96.     }
  97.    }
  98.    //Control con los pulsadores In1
  99.    if(In1 == 1)
  100.    {
  101.     Bt = 'D'; //Derecha
  102.     posicion_servo();
  103.    }
  104.    if(In2 == 1)
  105.    {
  106.     Bt = 'I'; //Izquierda
  107.     posicion_servo();
  108.    }
  109.  }while(true);
  110. }