Autor Tema: funciones setup_comparator y setup_vref ,alguien sabe como funcionan???  (Leído 5539 veces)

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

Desconectado alexlarrain

  • PIC10
  • *
  • Mensajes: 44
hola:
para programar un pic 16f628 necesito que compare un voltaje (que esta configurado)con otro q varia  para encender una ampolleta , para esto necesito ocupar las funciones :

setup_comparator(A0_A2_A1_A2_OUT_ON_A3_A4); esta configura las entradas
 setup_vref(VREF_HIGH|9); esta configura el voltaje a comparar

por lo que he leido ,quiero saber si esta bien lo de las funciones

si alguien me puede explicar mejor...y entender más  para hacer el programa

cualquier comentario o acotacion es bienvenida.

gracias

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18286
    • MicroPIC
Re: funciones setup_comparator y setup_vref ,alguien sabe como funcionan???
« Respuesta #1 en: 10 de Junio de 2007, 02:44:29 »
Según la ayuda de CCS:

setup_vref (mode | value)

mode may be one of the following constants:
- FALSE                 (off)
- VREF_LOW         for VDD*VALUE/24
- VREF_HIGH         for VDD*VALUE/32 + VDD/4
- any may be or'ed with VREF_A2.

value is an int 0-15.
 
Si esto es así, y tu ejemplo decías setup_vref(VREF_HIGH|9); estabas configurando el umbral en
VDD*9/32 + VDD/4
si suponemos que alimentas a 5V tenemos
5*9/32 + 5/4 = 2,66V

Aquí te dejo otro ejemplo, el que viene con CCS
Código: C
  1. /////////////////////////////////////////////////////////////////////////
  2. ////                         EX_COMP.C                               ////
  3. ////                                                                 ////
  4. ////  This example demonstartes the use of the built in comparator.  ////
  5. ////  The program compares the input voltage with the internal       ////
  6. ////  reference voltage.  Turn the POT to change the voltage.        ////
  7. ////                                                                 ////
  8. ////  Configure the CCS prototype card as follows:                   ////
  9. ////     Connect pin A1 to GND.                                      ////
  10. ////     Connect the output of the POT to pin A0.                    ////
  11. ////                                                                 ////
  12. ////  NOTE: Make sure the POT is turned all the way counter clock    ////
  13. ////  wise before starting the program.                              ////
  14. ////                                                                 ////
  15. ////  This example will work with the PCM compiler.  The following   ////
  16. ////  conditional compilation lines are used to include a valid      ////
  17. ////  device for each compiler.  Change the device, clock and RS232  ////
  18. ////  pins for your hardware if needed.                              ////
  19. /////////////////////////////////////////////////////////////////////////
  20. ////        (C) Copyright 1996,2003 Custom Computer Services         ////
  21. //// This source code may only be used by licensed users of the CCS  ////
  22. //// C compiler.  This source code may only be distributed to other  ////
  23. //// licensed users of the CCS C compiler.  No other use,            ////
  24. //// reproduction or distribution is permitted without written       ////
  25. //// permission.  Derivative programs created using this software    ////
  26. //// in object code form are not restricted in any way.              ////
  27. /////////////////////////////////////////////////////////////////////////
  28.  
  29.  
  30. #if defined(__PCM__)
  31. #include <12F675.h>
  32. #fuses HS,WDT,NOPROTECT
  33. #use delay(clock=20000000)
  34. #use rs232(baud=9200, xmit=PIN_A3, rcv=PIN_A4)
  35. #endif
  36.  
  37. short safe_conditions=TRUE;
  38.  
  39. #INT_COMP
  40. void isr()  {
  41.  
  42.    safe_conditions=FALSE;
  43.    printf("WARNING!!  Voltage level is above 3.6 V.   \r\n");
  44. }
  45.  
  46.  
  47. main()   {
  48.  
  49.    printf("\r\nRunning voltage test...\r\n\n");
  50.  
  51.    setup_comparator(A1_VR_OUT_ON_A2);
  52.    setup_vref(VREF_HIGH|15);
  53.    enable_interrupts(INT_COMP);
  54.    enable_interrupts(GLOBAL);
  55.  
  56.  
  57.    while(TRUE)
  58.    {
  59.       if(safe_conditions)
  60.          printf("Voltage level is below 3.6 V.              \r\n");
  61.       safe_conditions=TRUE;
  62.       delay_ms(500);
  63.    }
  64. }

Desconectado alexlarrain

  • PIC10
  • *
  • Mensajes: 44
Re: funciones setup_comparator y setup_vref ,alguien sabe como funcionan???
« Respuesta #2 en: 10 de Junio de 2007, 16:37:25 »
gracias lo estoy revisando ...