Problemas con el adc del 16f88

|-
adc con 16f88

Buenos dias señores.Aqui mi problema.El codigo es de un variador de velocidad dc simple.Detecta el cruce por cero de la onda ac 220/50hz activa la interrupcion y de acuerdo a las entradas de pedido(pote)y realimentacion(real)incrementa o baja la velocidad.Hasta ahi todo bien, pero al agragarle el adcin 4 para saber un determinado nivel se me incrementa la velocidad al aumentar dicha entrada!El aumento es leve (unos pocos volts en la salida)pero no deberia suceder, y luego de haber cambiado todas las configuraciones posibles recurro por una ayuda, sera posible?
Trabajo con PSI en basic

Código:
Define CONF_WORD = 0x0f4a
Define CONF_WORD_2 = 0x3ffc

\'ESTO ES PARA REALIMENTACION POR ARMADURA



AllDigital
TRISA = %00010011
TRISB = %00000001
ANSEL = %00010011
\'ADCON1 = 0
CMCON = 0
CCP1CON = 0
INTCON.4 = 1  \'hab int externa
OPTION.6 = 1  \'por flanco de subida
INTCON.1 = 0  \'limpio la int externa
Define CLOCK_FREQUENCY = 20
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
INTCON.7 = 1
INTCON.6 = 1
PIR1.1 = 0  \'limpio el overflow
PIE1.1 = 1  \'hab int tmr2
T2CON = %01100010
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
Dim pote As Byte
Dim aviso As Byte
Dim real As Byte
Symbol disparo = RB1
Dim salida As Byte
salida = 0
CVRCON = 0
Define ADC_CLOCK = 1
Define ADC_SAMPLEUS = 1
Dim maxima As Byte
Dim minima As Byte
Symbol rojo = RB4
Symbol verde = RB5
\'voy a trabajar al reves de modo que 25  el maxima vel y 250 min
\'porque el tmr2 va de cero a la cifra
Dim a As Byte
Dim b As Byte
Dim ce As Byte
Dim de As Byte
a = 75  \'50
b = 50  \'20
ce = 25  \'10
de = 12  \'5



maxima = 250
minima = 20

Dim dif As Byte  \'diferencia entre pot y real
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
inicio:
If aviso > 127 Then
High rojo
Else
Low rojo
Endif
Goto inicio


End                                               
On Interrupt
Save System
If PIR1.1 = 1 Then Goto final  \'si interr por tmr2
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
\'ESTO ES LO QUE HAGO CUANDO CRUZA POR CERO
If INTCON.1 = 1 Then  \'cruzo por el cero
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
\'cargo los valores
Low disparo  \'apago el disparo justo antes de llegar al cero
Adcin 4, aviso
Adcin 0, pote

Adcin 1, real



Endif
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'

\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
\'aca establezco a donde voy
If pote > real Then Goto subir
If real > pote Then Goto bajar
If real = pote Then Goto igual
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
igual:
salida = salida
Goto comparar
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
subir:

dif = pote - real  \'me fijo a que disttanciaesta
If dif > 100 Then
salida = salida + a
Goto comparar
Endif
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
If dif > 80 Then
salida = salida + b
Goto comparar
Endif
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
If dif > 60 Then
salida = salida + ce
Goto comparar
Endif
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
If dif > 40 Then
salida = salida + de
Goto comparar
Endif
If dif <= 40 Then
salida = salida + 1
Goto comparar
Endif
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'

\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
bajar:
dif = real - pote
If dif > 100 Then
salida = salida - a  \'10  \'25 es 1 ms
Goto comparar
Endif
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'

If dif > 80 Then
salida = salida - b  \'5
Goto comparar
Endif
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
If dif > 60 Then
salida = salida - ce  \'3
Goto comparar
Endif
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
If dif > 40 Then
salida = salida - de  \'2
Goto comparar
Endif
If dif <= 40 Then  \'20
salida = salida - 1
Goto comparar
Endif









comparar:
If salida >= maxima Then salida = maxima  \'maxima vel ojo que cuento al reves
If salida <= minima Then salida = minima  \'min vel
\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'

\'disparo el timer2
PR2 = 255 - salida

T2CON.2 = 1  \'disparo el t2
INTCON.1 = 0  \'limpio el flag de int externa

\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'
\'ACA CUANDO INTERRUMPE POR TMR2
final:
If PIR1.1 = 1 Then
High disparo


T2CON.2 = 0  \'lo apago 
PIR1.1 = 0  \'limpio el flag del tmr2
Endif
terminar:
Resume                                            
End ...
 
Última edición por un moderador:
Atrás
Arriba