Autor Tema: Programar Pic 16f877 con PT 100  (Leído 5909 veces)

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

Desconectado enricar883

  • PIC10
  • *
  • Mensajes: 18
Programar Pic 16f877 con PT 100
« en: 31 de Mayo de 2006, 15:09:23 »
Hola a todos,

Me he propuesto programar un pic 16f877 con una pantalla LCD de 2x16 e incroporarle un sensor PT 100 para que me mida la temperatura de la tuberia que tengo en casa.

Para comenzar no tengo mucha ida de electronica, pero si de programacion.

El PT 100 da como señal 100 ohmios cuando esta a cero grados y mide desde -199 a 199 grados centigrados, pero no se como conectarlo al pic.

A ver si me podeis ayudar.

Yo programo con PBP.

Gracias

Desconectado navaismo

  • Jubilado Todopic
  • PIC24H
  • ****
  • Mensajes: 1973
Re: Programar Pic 16f877 con PT 100
« Respuesta #1 en: 31 de Mayo de 2006, 17:35:29 »
Mira aki hice un prog hace rato con las rutinas de punto flotante de k baje de jimbots si no mal recuerdo y un lm35dz conectado al F877

Código: FreeBasic
  1. '****************************************************************
  2.     '*  Name    : termo.pbp                                         *
  3.     '*  Author  : Max. E. Reyes Vera Juarez                         *
  4.     '*  Notice  : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] *
  5.     '*          : All Rights Reserved                               *
  6.     '*  Date    : 07/12/2005                                        *
  7.     '*  Version : 1.0                                               *
  8.     '*  Notes   :                                                   *
  9.     '*          :                                                   *
  10.     '****************************************************************
  11.  
  12. include "fp20.bas"          ' INCLUIR RUTINA DE PUNTO FLOATANTE
  13.  
  14. Define  __16F877    1       ' DEFINICION DE MCU
  15.  
  16. Define  LCD_DREG        PORTD
  17. Define  LCD_DBIT        4
  18. Define  LCD_RSREG       PORTA   ' DEFINICION DE LOS REGISTROS DEL LCD
  19. Define  LCD_RSBIT       2
  20. Define  LCD_EREG        PORTA
  21. Define  LCD_EBIT        5
  22.  
  23. Define  ADC_CLOCK          3    ' PONIENDO EN 3 EL RELOJ DE LA FUENTE
  24. Define  ADC_BITS          10    ' NUMERO DE BITS DEL RESULTADO
  25. Define  ADC_SAMPLEUS  15        ' SETEO DEL TIEMPO DE MEDICION
  26.  
  27.  
  28.   TRISA  = 11           ' PUERTO A 3 ENTRADAS Y 3 SALIDAS                                                          
  29.   TRISB  = 127
  30.   ADCON1 = 142              ' PUERTO A COMO ADC Y JUSTIFICACION A LA DERECHA
  31.  
  32.   OPTION_REG.7 = 0      ' HABILITAR PULL-UPS
  33.    
  34.    
  35.   Low PORTA.4               ' APAGO LINEA DEL LCD R/W (W)
  36.   Pause 500                     ' PAUSA PARA LCD
  37.    
  38.    
  39. sensor       var word   ' VARIABLE PARA GUARDAR EL VALOR DE ADC  
  40. fpplaces     var byte   ' USADO PARA DEFINIR LA POSICION DEL PUNTO  
  41. ahold        var word   ' REQUERIDO POR FPDISPLAYR
  42. bhold        var word   ' REQUERIDO POR FPDISPLAYR
  43. resulthold   VAR word   ' VARIABLE PARA REALIZAR OPERACIONES CON FP
  44.  
  45. TERMO VAR PORTA.0
  46.  
  47. PROG1 VAR PORTB.0       ' ALIAS PIN RB0
  48. PROG2 VAR PORTB.1       ' ALIAS PIN RB1
  49. PROG3 VAR PORTB.2       ' ALIAS PIN RB2
  50. PROG4 VAR PORTB.3       ' ALIAS PIN RB3
  51. HTEMP VAR PORTB.4       ' ALIAS PIN RB4
  52. LTEMP VAR PORTB.5       ' ALIAS PIN RB5
  53. EXIT  VAR PORTB.6       ' ALIAS PIN RB6
  54.  
  55.  
  56. INIT:             'inicio de la rutina principal
  57.  
  58.  lcdout $fe,1, " TEMPERATURA DE:"                    'mostramos mensaje en la primer linea del LCD
  59.  LCDOUT $FE,$C0                                            'nos pasamos a la segunda linea del LCD
  60.  
  61.  
  62.  ADCIN  TERMO, sensor                                   ' Adquirimos el valor del ADC en RA0 y se guarda en variable sensor
  63.  
  64.  
  65.  
  66.  resulthold=(sensor*104)
  67.  
  68.  aint=resulthold
  69.  gosub itofa
  70.  
  71.  bint=213
  72.  gosub itofb
  73.  gosub fpdiv
  74.  
  75.  fpplaces=2: gosub fpdisplayr  
  76.  pause 50
  77.  
  78.  
  79.  
  80. goto init
  81.  
  82.  
  83.  
  84. ' LA RUTINA FPDISPLAYR VERIFICA EL NUMERO DE LUGARES, LUEGO AÑADE EL VALOR
  85. ' APROPIADO PARA EL REDONDEO. PARA SALVAR ESPACIO EN LA RAM, LOS VALORES SON
  86. ' DIFICILES DE CODIFICAR EN FORMATO DE PUNTO FLOTANTE
  87.  
  88.  
  89. fpdisplayr: If fpplaces=0 Then                  ' Set floating point barg to 0.5
  90.                                 bexp = $7E
  91.                                 bargb0 = $00
  92.                                 bargb1 = $01
  93.                         Endif
  94.                         If fpplaces=1 Then                      ' Set floating point barg to 0.05
  95.                                 bexp = $7A
  96.                                 bargb0 = $4C
  97.                                 bargb1 = $CD
  98.                         Endif
  99.                         If fpplaces=2 Then                      ' Set floating point barg to 0.005
  100.                                 bexp = $77
  101.                                 bargb0 = $23
  102.                                 bargb1 = $D8
  103.                         Endif
  104.                         If fpplaces=3 Then                      ' Set floating point barg to 0.0005
  105.                                 bexp = $74
  106.                                 bargb0 = $03
  107.                                 bargb1 = $13
  108.                         Endif
  109.                         If fpplaces=4 Then                      ' Set floating point barg to 0.00005
  110.                                 bexp = $70
  111.                                 bargb0 = $51
  112.                                 bargb1 = $B7
  113.                         Endif
  114.  
  115.                         If aargb0.7 Then                        ' Check the floating point sign bit
  116.                                 Gosub fpsub                             ' If negative, subtract barg from aarg
  117.                         Else
  118.                                 Gosub fpadd                             ' If positive, add barg to aarg
  119.                         Endif
  120.  
  121.  
  122. ' The fpdisplay routine outputs the signed value of aarg in decimal floating point format. It
  123. ' can display an absolute value of 32767, and decimals to 4 places. The number of decimal
  124. ' places should be stored in fpplaces before calling the routine. The routine reads the
  125. ' floating point value of aarg. This value should NOT be converted to an integer before
  126. ' calling fpdisplay. The integer conversion will be perfomed as part of this routine, and
  127. ' aint will be returned to the calling program just as from the itofa routine.
  128.  
  129. fpdisplay:      bexp = aexp                                     ' Store the FP value of aarg to the barg variables
  130.                         bargb0 = aargb0
  131.                         bargb1 = aargb1
  132.  
  133.                         Gosub ftoia                                     ' Convert aarg to integer
  134.                         ahold = aint                            ' Save this value for the final display
  135.                        
  136.                         Gosub itofa                                     ' Convert integer back to float
  137.  
  138.                         Swap aexp,bexp                          ' Swap the FP values of aarg and barg before subtraction
  139.                         Swap aargb0,bargb0
  140.                         Swap aargb1,bargb1
  141.  
  142.                         Gosub fpsub                                     ' Subtract the integer portion from the full number
  143.  
  144.  
  145.                         bint = 10                                       ' Make bint = 10 E fpplaces
  146.                         If fpplaces=2 Then
  147.                                 bint = 100
  148.                         Endif
  149.                         If fpplaces=3 Then
  150.                                 bint = 1000
  151.                         Endif
  152.                         If fpplaces=4 Then
  153.                                 bint = 10000
  154.                         Endif
  155.  
  156.                         bhold = bint                            ' Save the integer value of bint for zeros loop
  157.  
  158.                         Gosub itofb                                     ' Convert bint to integer prior to FP multiply
  159.                         Gosub fpmul                                     ' Multiply the decimal portion x 10 E fpplaces
  160.  
  161.                         Gosub ftoia                                     ' Convert result to aint integer
  162.  
  163.  
  164.                         If (ahold.15) OR (aint.15) Then         ' Check for negative integer or decimal
  165.                                 Lcdout "-"                              ' Display minus
  166.  
  167. '                               Serout2 spin,sbaud,["-"]        ' Use for 2400 bps serial output
  168.                         Endif
  169.  
  170.                         Lcdout "    ", dec abs ahold            ' Display integer portion
  171.  
  172. '                       Serout2 spin,sbaud,[dec abs ahold]      ' Use for 2400 bps serial output
  173.  
  174.                         If fpplaces > 0 Then                                   
  175.                                 Lcdout "."
  176. '                               Serout2 spin,sbaud,["."]        ' Use for 2400 bps serial output
  177.  
  178.  zeros:                 bhold = bhold / 10                                                              ' Set bhold to be next place to right
  179.                                 If (abs aint < bhold) AND (bhold > 1) Then              ' Check for leading zero in decimal
  180.                                         Lcdout "0"                                                                      ' Display leading zero
  181. '                                       Serout2 spin,sbaud,["0"]                                        ' Use for 2400 bps serial output
  182.                                         Goto zeros                                                                      ' loop to check for another zero
  183.                                 Endif
  184.        
  185.                                 Lcdout dec abs aint             ' Display the rest of the decimal portion
  186.                 lcdout " ßC" ' muestra ºC
  187. '                               Serout2 spin,sbaud,[dec abs aint]       ' Use for 2400 bps serial output
  188.  
  189.                         Endif
  190.  
  191.                         aint = ahold                            ' Restore the original value of aint
  192.  
  193.                         Return

como veras solo adapte mi rutina a la de punto flotante en funcion de 104 pork era la temperatura que me interesaba. te adjunto el manual del lm35


« Última modificación: 30 de Junio de 2007, 11:25:58 por navaismo »
"Mi tercer deseo, que otra cosa podría ser, poner un final a todo el sufrimiento, que sólo con mi propia extinción el planeta podrá ser aliviado. Pobre de mí, Si tuviera tres deseos hoy, la elección no sería dificil para mí, Sólo tres deseos serían suficientes, No tendría uso para más."

"He sido un hombre que busca y aun lo sigo siendo, pero ya no busco en las estrellas y en los libros, sino en las enseñanzas de mi sangre."

Desconectado navaismo

  • Jubilado Todopic
  • PIC24H
  • ****
  • Mensajes: 1973
Re: Programar Pic 16f877 con PT 100
« Respuesta #2 en: 31 de Mayo de 2006, 17:36:42 »
va no se pork no adjunto siempre tengo problemas con eso
"Mi tercer deseo, que otra cosa podría ser, poner un final a todo el sufrimiento, que sólo con mi propia extinción el planeta podrá ser aliviado. Pobre de mí, Si tuviera tres deseos hoy, la elección no sería dificil para mí, Sólo tres deseos serían suficientes, No tendría uso para más."

"He sido un hombre que busca y aun lo sigo siendo, pero ya no busco en las estrellas y en los libros, sino en las enseñanzas de mi sangre."

Desconectado navaismo

  • Jubilado Todopic
  • PIC24H
  • ****
  • Mensajes: 1973
Re: Programar Pic 16f877 con PT 100
« Respuesta #3 en: 31 de Mayo de 2006, 17:40:59 »
a ver dicen k la tercera es la vencida.....

vi el pt100 y por la imagen tiene una salida tipo coaxial o algo asi lo unico seria encontrar un hembra ( para esa conexion) y ver si cambia los ohms y de ahi conectarlo al pic directo al adc(PORTA)
« Última modificación: 31 de Mayo de 2006, 17:46:01 por navaismo »
"Mi tercer deseo, que otra cosa podría ser, poner un final a todo el sufrimiento, que sólo con mi propia extinción el planeta podrá ser aliviado. Pobre de mí, Si tuviera tres deseos hoy, la elección no sería dificil para mí, Sólo tres deseos serían suficientes, No tendría uso para más."

"He sido un hombre que busca y aun lo sigo siendo, pero ya no busco en las estrellas y en los libros, sino en las enseñanzas de mi sangre."

Desconectado enricar883

  • PIC10
  • *
  • Mensajes: 18
Re: Programar Pic 16f877 con PT 100
« Respuesta #4 en: 01 de Junio de 2006, 15:00:08 »
Gracias,

lo utilizare como muestra.

Saludos