Autor Tema: Como mido un potenciometro con pic basic  (Leído 7191 veces)

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

Desconectado chumilo20

  • PIC10
  • *
  • Mensajes: 3
Como mido un potenciometro con pic basic
« en: 10 de Noviembre de 2009, 19:20:38 »
BUEN@S DIAS/TARDES/NOCHES

NECESITO UNA AYUDITA PARA HACER UNA CONVERCION UTILIZANDO EL PIC 16F877... TENGO Q TRABAJAR CON UN POTENCIOMETRO DE 10K COMO ENTRADA ANALOGA Y NECESITO VISUALISAR EN EL LCD LOS OHMIOS  DEL POTENCIOMETRO MI PREGUNTA ES COMO HACER ESO NO TENGO NI IDEA..

ESTA ES LA CONFIGURACION Q POSEO




DEFINE OSC 4              'se define el oscilador

GOSUB confi_lcd
GOSUB variables
pause 1000

goto inicio

confi_lcd:
DEFINE LCD_DREG PORTD    'declara el puerto a utilizar para el lcd
DEFINE LCD_DBIT 4        'bit menos significativo del bus de datos
DEFINE LCD_RSREG PORTD   'define el bit para el rs del lcd
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTD    'define el bit par el E del lcd
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4        'define de cuantos bits es el lcd
DEFINE LCD_LINES 2       'define de cuantas lineas es el lcd
DEFINE LCD_COMANNDUS 2000
DEFINE LCD_DATAUS 50

return

variables:
'SUBE VAR PORTB.0
'BAJA VAR PORTB.1
'CONTEO VAR BYTE
A VAR PORTB.5
B VAR PORTB.4
LED1 VAR PORTB.6
LED2 VAR PORTB.7
 
TRISB =%00110011
B0 VAR BYTE
B1 VAR BYTE


DEFINE ADC_BITS 8  ' se configura el adc de 8bits de resolucion
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 500
trisa.0 = 1         'porta 0 como entrada
adcon0 = 65         ' adcon0 y adcon1 configurados para q sea con referencia y entradas analogicas
adcon1 = 1
PORTB = 0

px var Byte         'se declara la variable a utilizar

canal_0 var porta.0 '  CANAL AL PIN

return

inicio:
TRISD = 0
PORTB = 0
PAUSE 200

'CONTEO = 10

LCDOUT $FE,1," Conversor " 'se escribe el letrero de bienvenida en la primera linea
LCDOUT $FE,$C1,"ERIC SUESCUN" 'se escribe el letrero de bienvenida   en la segunda linea
PAUSE 3000

LCDOUT $FE,1
for b0 = 0 to 14
  LOOKUP B0,["   Conversor  "],B1
  LCDOUT $FE,$0C,B1
  PAUSE 300
NEXT


LCDOUT $FE, $C0
FOR B0 = 207 TO 192 STEP -1
  'LCDOUT $FE, 1
  LCDOUT $FE,B0,"  ERIC SUESCUN  "
  PAUSE 200
NEXT

PAUSE 3000

aqui:
'IF PORTB.0 = 0 THEN SUBIR
'IF PORTB.1 = 0 THEN BAJAR
'IF PX  =< CONTEO THEN LOW PORTB.3


IF A = 0 THEN
HIGH LED1
ELSE
LOW LED1
ENDIF
IF B = 0  THEN  
HIGH LED2
ELSE
LOW LED2
ENDIF

PORTB.2 = 0  
ADCIN 0, px  'LEE Y GUARDA EL LO DL CANAL 0 EN LA VARIABLE px
'LcdLine2Clear 'se limpia la linea 2 dl lcd
pause 10
                              
LCDOUT $FE,1,$C2 ,"Comversor"'
LCDOUT $FE,$C1,"Resis:",dec px," Ohm "  'se imprime el valor de la temperatura
pause 20
 
 PAUSE 200
goto aqui


GOSUB AQUI


END

CUAL QUIER AYUDA SE LES AGRADECE :)
« Última modificación: 10 de Noviembre de 2009, 22:22:34 por chumilo20 »

Desconectado septiembre_negro

  • PIC18
  • ****
  • Mensajes: 310
Re: AYUDA URGENTE!!!!! CON PICBASIC
« Respuesta #1 en: 10 de Noviembre de 2009, 19:58:20 »

Desconectado chumilo20

  • PIC10
  • *
  • Mensajes: 3
Re: AYUDA URGENTE!!!!! CON PICBASIC
« Respuesta #2 en: 10 de Noviembre de 2009, 20:49:02 »
gracias men pero lo q necesito es como aplicarlo en la rutina :lol:  :)

Desconectado RALF2

  • Moderador Local
  • PIC24H
  • *****
  • Mensajes: 2062
Re: AYUDA URGENTE!!!!! CON PICBASIC
« Respuesta #3 en: 10 de Noviembre de 2009, 21:04:47 »
Que tal amigos!
chumilo20 el pic basic pro trae una instruccion que te puede salvar la vida  :D
Se llama POT y la puedes ver en la pagina 118 de este manual

Espero que te sirva  :mrgreen:

Saludos

Desconectado chumilo20

  • PIC10
  • *
  • Mensajes: 3
Re: AYUDA URGENTE!!!!! CON PICBASIC
« Respuesta #4 en: 10 de Noviembre de 2009, 21:57:10 »
RALF me podrias dar un ejemplo de como aplicarlo a esta rutina y en q parte lo agregaria.
de ante mano muchas gracias.

Desconectado RALF2

  • Moderador Local
  • PIC24H
  • *****
  • Mensajes: 2062
Re: Como mido un potenciometro con pic basic
« Respuesta #5 en: 11 de Noviembre de 2009, 16:38:58 »
Buenas!
Chumilo de momento no trabajo con el pic basic pro y estoy muy corto de tiempo porque tengo examenes en la universidad  :shock:
Te recomiendo que busques en el foro por el uso de la instruccion pot que de seguro alguien ya la a utilizado antes.

Saludos

Desconectado MGLSOFT

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 7918
Re: Como mido un potenciometro con pic basic
« Respuesta #6 en: 11 de Noviembre de 2009, 16:57:08 »
Parece que no lees donde te dicen...

En el mismo manual hay un ejemplo:

Citar
5.58. POT
POT Pin,Scale,Var
Reads a potentiometer (or some other resistive device) on Pin. Pin may be a constant, 0 - 15, or a variable that contains a number 0 - 15 (e.g. B0) or a pin name (e.g. PORTA.0).
The resistance is measured by timing the discharge of a capacitor through the resistor (typically 5K to 50K). Scale is used to adjust for varying RC constants. For larger RC constants, Scale should be set low (a minimum value of one). For smaller RC constants, Scale should be set to its maximum value (255). If Scale is set correctly, Var should be zero near minimum resistance and 255 near maximum resistance.
Unfortunately, Scale must be determined experimentally. To do so, set the device under measure to maximum resistance and read it with Scale set to 127. Adjust Scale until the Pot command returns 254. If 255, decrease the scale. If 253 or lower, increase the scale. (Note: This is similar to the process performed by the Alt-P option of the BS1 environment).

Use the following code to automate the process. Make sure that you set the pot to maximum resistance.

Código: FreeBasic
  1. B0 Var Byte
  2. scale Var Byte
  3. For scale = 1 To 255
  4. POT 0,scale,B0
  5. If (B0 > 253) Then calibrated
  6. Next scale
  7. Serout 2,0,["Increase R or C.",10,13]
  8. Stop
  9. calibrated:
  10. Serout 2,0,["Scale= ",#scale,10,13]
Todos los dias aprendo algo nuevo, el ultimo día de mi vida aprenderé a morir....
Mi Abuelo.

Desconectado Marioguillote

  • Moderador Local
  • PIC24H
  • *****
  • Mensajes: 1926
    • Servisystem
Re: Como mido un potenciometro con pic basic
« Respuesta #7 en: 11 de Noviembre de 2009, 18:33:18 »
Syntax

Variable = POT Pin, Scale
 
Overview

Read a potentiometer, thermistor, photocell, or other variable resistance.
 
Operators
Variable is a user defined variable of type bit, byte, byte array, word, word array, dword or float.
Pin is a Port.Pin constant that specifies the I/O pin to use.
Scale is a constant, variable, or expression, used to scale the instruction's internal 16-bit result. The 16- bit reading is multiplied by (scale/ 256), so a scale value of 128 would reduce the range by approximately 50%, a scale of 64 would reduce to 25%, and so on.

Example

 DIM VAR1 as BYTE
Loop:
 VAR1 = POT PORTB.0 , 100   ' Read potentiometer on pin 0 of PORTB.
 PRINT @VAR1 , " "          ' Display the potentiometer reading
 GOTO Loop                  ' Repeat the process.
 
Notes

Internally, the Pot instruction calculates a 16-bit value, which is scaled down to an 8-bit value. The amount by which the internal value must be scaled varies with the size of the resistor being used. The pin specified by Pot must be connected to one side of a resistor, whose other side is connected through a capacitor to ground. A resistance measurement is taken by timing how long it takes to discharge the capacitor through the resistor. The value of scale must be determined by experimentation, however, this is easily accomplished as follows: -
 
Set the device under measure, the pot in this instance, to maximum resistance and read it with scale set to 255. The value returned in VAR1 can now be used as scale: -
 
 VAR1 = POT PORTB.0 , 255

Desconectado septiembre_negro

  • PIC18
  • ****
  • Mensajes: 310
Re: Como mido un potenciometro con pic basic
« Respuesta #8 en: 11 de Noviembre de 2009, 19:25:52 »
Citar
NECESITO UNA AYUDITA PARA HACER UNA CONVERCION UTILIZANDO EL PIC 16F877... TENGO Q TRABAJAR CON UN
POTENCIOMETRO DE 10K COMO ENTRADA ANALOGA Y NECESITO VISUALISAR EN EL LCD LOS OHMIOS  DEL POTENCIOMETRO MI PREGUNTA ES COMO HACER ESO NO TENGO NI IDEA..

Pot asta donde entiendo mide el tiempo en que se descarga un capacitor, pot según la posición del potenciometro entrega un valor que va de 0 a 255.
Esto sirve para conocer cual es el valor en ohms del mismo????