Gracias por las respuestas, aún no he terminado de documentar el proyecto. La parte que me genera error es dónde mando a llamar una parte de Código en lenguaje ensamblador, ASM-ENDASM y adjunto en mejor calidad los errores de compilación. agradezco su asesoria
@ DEVICE PIC16F877 , protect_on
' *************** Puerto A ***************
'TRISA.0 = 1 ' VELOCIDAD REF
'TRISA.1 = 1 ' LARGO REF
TRISA.2 = 0 ' INICIO
'TRISA.3 = 1 ' ANALOGO
TRISA.4 = 0 ' ARRANQUE
TRISA.5 = 0 ' DISCO
' *************** Puerto B ***************
TRISB.0 = 1 ' DENTRO
TRISB.1 = 1 ' Manual / Automatico
TRISB.2 = 1 ' ARRNQUE MAN
TRISB.3 = 1 ' PARO
TRISB.4 = 1 ' ARRANQUE AUTO
TRISB.5 = 1 ' PE
TRISB.6 = 0 ' DISCOS
TRISB.7 = 0 ' PRINCIPAL
' *************** Puerto C ***************
TRISC.0 = 1 '
TRISC.1 = 0 '
TRISC.2 = 0 '
TRISC.3 = 1 '
TRISC.4 = 1 '
TRISC.5 = 1 '
TRISC.6 = 1 '
TRISC.7 = 1 '
' *************** Puerto D ***************
TRISD.0 = 0 '
TRISD.1 = 0 '
TRISD.2 = 0 '
TRISD.3 = 0 '
TRISD.4 = 1 '
TRISD.5 = 1 '
TRISD.6 = 1 '
TRISD.7 = 1 '
' *************** Puerto E ***************
TRISE.0 = 0 ' LED FASE
TRISE.1 = 1 '
TRISE.2 = 0 ' OK INICIO
' *****************************************************
' Definicion de Variables
S_EnvoOk VAR PORTA.2
S_ArrBA VAR PORTA.4
S_NeuDisc VAR PORTA.5
E_ESR VAR PORTB.5
S_Run_Inv_Disc VAR PORTB.6
S_Run_Inv_Main VAR PORTB.7
E_FPapel VAR PORTC.3
E_FMordaza VAR PORTC.4
S_LedFMordaza VAR PORTD.0
S_LedAde VAR PORTD.1
S_LedAtras VAR PORTD.2
S_LedFPapel VAR PORTD.3
S_LedFase VAR PORTE.0
S_LedPicOk VAR PORTE.2
E_PB_Inicio VAR Bit
E_Inv_Main_Ok VAR Bit
E_Sel_Man_Auto VAR Bit
E_PB_Jog VAR Bit
E_Inv_Disc_Ok VAR Bit
E_Enable_Inicio VAR Bit
E_SelCtrlReg VAR Bit
E_PB_Arranque VAR Bit
E_PB_Paro VAR Bit
E_PPM VAR Byte
E_Largo VAR Byte
E_FC_Inicio VAR Bit
E_FC_MaxVel VAR Bit
E_FC_IncVel VAR Bit
E_FC_DecVel VAR Bit
E_FC_MinVel VAR Bit
Set_Largo VAR Word
Run VAR Bit
Acc VAR Bit
DAcc VAR Bit
TimeAcc VAR Byte
S_Ref_PPM VAR Word
S_Ref_Largo VAR Word
AccPPM VAR Word
DAccPPM VAR Word
BitDAccPPM VAR DAccPPM.15
Gain VAR Byte
GainP VAR Word
Bandera1 VAR Bit
BJog VAR Bit
BanES VAR Byte 'Paro de Emergencia
VerError VAR Byte
Base VAR Word
B VAR Word
Err1 VAR Word
Err2 VAR Word
Error VAR Word
GP VAR Word
Pol VAR Bit
FacGP VAR Word
BanJog VAR Bit
BanInicio VAR Bit
BanInicio_Mor VAR Bit
BanInicio_Pap VAR Bit
BanRampa VAR Bit
BanIni VAR Bit
BanIntLk VAR Bit
BanSReg VAR Bit
Entry_PPM VAR Byte
BanParo VAR Bit
RunBA VAR Bit
BanArrBA VAR Byte
AuxFMordaza VAR Bit
BanAlim VAR Bit
'********* TEST ***************
' update VAR Bit
'********************************
ADCON1 = 4 ' Define Entradas Analogas PortA 0, 1, 3
T2CON = %00000100 ' Timer 2 Encendido y Prescala = 1
CCP1CON = %00001100 ' Define El Puerto C.1 como modo PWM
CCP2CON = %00001100 ' Define El Puerto C.2 como modo PWM
OPTION_REG = $d1 '
CLEAR
Low S_ArrBA
Low S_NeuDisc
Entry_PPM = 0
BanIntLk = 0
Low S_NeuDisc
Low S_ArrBA
BanIni = 0
BanInicio = 0
BanInicio_Mor = 0
BanInicio_Pap = 0
BanRampa = 0
BJog = 0
BanIni = 0
BanSReg = 0
RunBA = 0
BanArrBA = 0
AuxFMordaza = 0
BanAlim = 0
E_PPM = 0
E_PB_Arranque = 0
E_PB_Paro = 0
S_Ref_PPM = 1
S_Ref_Largo = 0
BanES = 0
Low S_Run_Inv_Main
Low S_Run_Inv_Disc
Run = 0
' update = 1
Gain = 0
VerError = 0
Bandera1 = 1
Error = 0
Base = 1
GP = 0
GainP = 1
CCPR2L= 0 'VELOCIDAD
CCPR1L = 0 'LARGO
E_FC_MinVel = 0
E_PB_Inicio = 0
BanParo = 0
BanJog = 0
Low S_EnvoOk
Low S_LedAde
Low S_LedAtras
Low S_LedFase
' Lcdout $fe, 1
' Lcdout dec3 S_Ref_PPM, " ", dec4 Error, " ", dec4 GP, " ",dec1 Pol
' Lcdout $fe, $C0
' Lcdout dec3 E_Largo, " ", dec5 Set_Largo, " ", dec5 GainP
Goto Inicio
' *********** Rutina de Contador *********
Cuenta:
PAUSEUS 5
Return
' *********** Rutina de convercion Analogo a Digital de In PotrA.0 *********
LeePPM:
ADCON0 = $41
Gosub AnaDig
Entry_PPM = ADRESH
If Entry_PPM < 5 then
Entry_PPM = 5
ENDIF
' E_PPM = ADRESH
' If E_PPM < 5 then
' E_PPM = 5
' ENDIF
Return
' *********** Rutina de convercion Analogo a Digital de In PotrA.1 *********
LeeLargo:
ADCON0 = $49
Gosub AnaDig
E_Largo = ADRESH
If E_Largo < 94 then
E_Largo = 94
ENDIF
If E_Largo > 233 then
E_Largo = 233
ENDIF
Return
' *********** Rutina para leer encender la convercion A/D ************
AnaDig:
Pauseus 50 ' CONFIG CANAL
ADCON0.2 = 1 ' CONVERSION
Pauseus 50 '
Return
' *********** Rutina para leer Entradas ************
LeeInputs:
E_SelCTrlReg = PortB.0
E_Sel_Man_Auto = PortB.1
E_PB_Jog = PortB.2
E_PB_Paro = PortB.3
E_PB_Arranque = PortB.4
E_FC_Inicio = PortC.0
E_FC_MaxVel = PortC.5
E_FC_IncVel = PortC.6
E_FC_DecVel = PortC.7
E_FC_MinVel = PortD.4
E_PB_Inicio = PortD.5
E_Inv_Disc_Ok = PortD.6
E_Inv_Main_Ok = PortD.7
E_Enable_Inicio = PortE.1
Return
'****************** Interrupt T0 *******************************
disable '
Time:
TimeAcc = TimeAcc + 1
INTCON.2 = 0
Resume
enable
' *************** Rutina de Arranque **********
ArrInv:
Pause 200
High S_Run_Inv_Main
High S_Run_Inv_Disc
High S_EnvoOk
Return
' *************** Rutina de Paro**********
ParoInv:
Low S_Run_Inv_Main
Low S_Run_Inv_Disc
Low S_EnvoOk
Return
' *************** Programa Inicial **************
Inicio:
Gosub LeeInputs
If E_ESR = 0 Or E_Inv_Main_Ok = 0 Or E_Inv_Disc_Ok = 0 Then
CLEAR
Low S_ArrBA
Low S_NeuDisc
Entry_PPM = 0
BanIntLk = 0
BanIni = 0
BanInicio = 0
BanInicio_Mor = 0
BanInicio_Pap = 0
BanRampa = 0
BanJog = 0
BJog = 0
BanSreg = 0
RunBA = 0
BanArrBA = 0
AuxFMordaza = 0
BanAlim = 0
E_PPM = 0
E_PB_Arranque = 0
E_PB_Paro = 0
S_Ref_PPM = 1
S_Ref_Largo = 0
BanES = 0
Low S_Run_Inv_Main
Low S_Run_Inv_Disc
Run = 0
' update = 1
Gain = 0
VerError = 0
Bandera1 = 1
Error = 0
Base = 1
GP = 0
GainP = 1
CCPR2L= 0
CCPR1L = 0
E_FC_MaxVel = 1
E_FC_MinVel = 0
E_PB_Inicio = 0
BanParo = 0
Low S_LedAde
Low S_LedAtras
Low S_LedFase
Low S_EnvoOk
Goto Ref
Else
' High S_EnvoOk
EndIf
' If E_Sel_Man_Auto = 0 Then Man
' If E_Sel_Man_Auto = 1 Then Auto
'Man:
If BanJog = 1 && BJog = 1 Then
Gosub ParoInv
Low S_NeuDisc
BanJog = 0
BJog = 0
EndIf
If E_PB_Jog = 1 && BanJog = 0 && Run = 0 then
GP = 0
E_PPM = 43
If BJog = 0 then
S_Ref_PPM = 1
High S_NeuDisc
Gosub ArrInv
EndIf
BJog = 1
Goto Rampa1
EndIf
If E_PB_Jog = 0 && BJog = 1 then
E_PPM = 0
GP = 0
S_Ref_PPM = 1
BanJog = 1
Goto Rampa1
EndIf
'Auto:
If E_Sel_Man_Auto = 0 && E_PB_Arranque = 1 && BJog = 0 && Run = 0 && E_PB_Paro = 1 && E_ESR = 1 Then
BanParo = 1
Run = 1
Pause 5
High S_NeuDisc
Gosub ArrInv
EndIf
If E_PB_Paro = 0 Or E_ESR = 0 Then
BanInicio = 0
BanIni = 0
BanInicio_Mor = 0
BanInicio_Pap = 0
BanRampa = 0
Run = 0
Low S_ArrBA
RunBA = 0
BanArrBA = 0
AuxFMordaza = 0
BanAlim = 0
EndIf
iF Run = 0 && S_Ref_PPM > 5 then Rampa
If Run = 0 && BanParo = 1 Then
Low S_LedAde
Low S_LedAtras
Low S_LedFase
BanSReg = 0
Gosub ParoInv
Pause 200
Low S_NeuDisc
BanParo = 0
EndIf
If Run = 0 Then Inicio
If E_SelCTrlReg = 0 Then
Error = 0
Low S_LedAde
Low S_LedAtras
Low S_LedFase
Bandera1 = 0
VerError = 0
Goto Rampa
EndIf
IF E_PB_Inicio = 1 Then
BanSReg = 1
RunBA = 1
EndIf
If BanSReg = 1 then SinIniReg
'**************************************************
If Run = 1 && BanInicio = 0 Then
S_Ref_PPM = 43
S_Ref_Largo = 43
BanInicio = 1
BanIni = 1
Goto Ref
EndIf
If E_FC_Inicio = 0 && S_Run_Inv_Main = 1 && BanInicio_Mor = 0 && Run = 1 Then
S_Ref_PPM = 1
BanInicio_Mor = 1
Goto Ref
EndIf
If E_FPapel = 0 && S_Run_Inv_Disc = 1 && BanInicio_Pap = 0 && Run = 1 && BanInicio_Mor = 1 Then
S_Ref_Largo = 0
BanInicio_Pap = 1
Goto Ref
EndIf
If BanInicio_Mor = 1 && BanInicio_Pap = 1 then
BanIni = 0
RunBA = 1
EndIf
If BanIni = 1 then Ref
SinIniReg:
If E_FMordaza = 0 && BanArrBA < 10 && AuxFMordaza = 0 && RunBA = 1 && BanAlim = 0 Then
BanArrBA = BanArrBA + 1
AuxFMordaza = 1
EndIf
If E_FMordaza = 1 && AuxFMordaza = 1 Then
AuxFMordaza = 0
EndIf
If RunBA = 1 && Run = 1 && BanArrBA >= 10 then
High S_ArrBA
BanAlim = 1
EndIf
If S_Ref_PPM < 5 && BanRampa = 0 Then
BanRampa = 1
S_Ref_PPM = 5
S_Ref_Largo = 5
Goto Rampa
EndIf
'********************************
Base = 20
If E_FMordaza = 0 And Bandera1 = 1 then
Bandera1 = 0
VerError = 1
Error = 0
Pol = 1
ENDIF
If E_FPapel = 0 And Bandera1 = 1 then
Bandera1 = 0
VerError = 2
Error = 0
Pol = 0
ENDIF
If VerError > 0 then
B = 0
Err1 = 0
Err2 = 0
ASM
Suma CALL _Cuenta
INC _ON
CJNE _ON,#70,Sigue
INC _Err1
CLR _ON
CJNE _Err1,#100,Sigue
INC _Err2
CLR _Err1
CJAE _Err2,#1,ErrFin
Sigue CJNE _VerError,#1,CHPap
JNB PORTC.3,ErrFin
CHPap CJNE _VerError,#2,CHErr
JNB PORTC.4,ErrFin
ChErr GOTO Suma
ErrFin
ENDASM
Error = (Err2 * 100) + Err1
If Error >= 3 & Pol = 1 Then
High S_LedAde
Else
Low S_LedAde
EndIf
If Error >= 3 & Pol = 0 Then
High S_LedAtras
Else
Low S_LedAtras
EndIf
If Error < 3 Then
High S_LedFase
Else
Low S_LedFase
EndIf
' ********* Definicion de Polaridad **********
VerError = 0
EndIf
If E_FMordaza = 1 And E_FPapel = 1 And VerError = 0 Then
Bandera1 = 1
ENDIF
Rampa:
BanSReg = 1
Gosub LeePPM
'*******************************
If E_FC_MaxVel = 1 && E_FC_IncVel = 1 && E_FC_DecVel = 1 && E_FC_MinVel = 1 Then
E_PPM = Entry_PPM / 2
EndIf
If E_FC_MaxVel = 0 && E_FC_IncVel = 1 && E_FC_DecVel = 1 && E_FC_MinVel = 1 Then
E_PPM = (Entry_PPM * 11) /10
EndIf
If E_FC_MaxVel = 0 && E_FC_IncVel = 0 && E_FC_DecVel = 1 && E_FC_MinVel = 1 Then
E_PPM = Entry_PPM
EndIf
If E_FC_MaxVel = 0 && E_FC_IncVel = 0 && E_FC_DecVel = 0 && E_FC_MinVel = 1 Then
E_PPM = (Entry_PPM * 10) / 11
EndIf
If E_FC_MaxVel = 0 && E_FC_IncVel = 0 && E_FC_DecVel = 0 && E_FC_MinVel = 0 Then
E_PPM = (Entry_PPM * 3) /2
EndIf
If E_PPM > 255 Then
E_PPM = 255
EndIf
' ******************************
If Run = 0 Then
E_PPM = 5
EndIf
Rampa1:
Gosub LeeLargo
AccPPM = S_Ref_PPM + 1
DAccPPM = S_Ref_PPM - 1
If BitDAccPPM = 1 then
DAccPPM = 0
EndIF
If E_PPM > AccPPM Then
Acc = 1
DAcc = 0
INTCON = $a0
On Interrupt Goto Time
EndIf
If E_PPM < DAccPPM Then
Acc = 0
DAcc = 1
INTCON = $a0
On Interrupt Goto Time
EndIf
If Acc = 0 && DAcc = 0 Then
INTCON.2 = 0
INTCON = $80
TimeAcc = 0
EndIf
'******** Rampa de Aceleracion ***************
If Acc = 1 && TimeAcc >= 7 Then
If S_Ref_PPM >= E_PPM then
S_Ref_PPM = E_PPM
Acc = 0
EndIf
If S_Ref_PPM = E_PPM then FinAcc
S_Ref_PPM = S_Ref_PPM + 1
FinAcc:
TimeAcc = 0
EndIf
'******** Rampa de Desaceleracion ***************
If DAcc = 1 && TimeAcc >= 7 Then
If S_Ref_PPM = 0 then
DAcc = 0
endif
If S_Ref_PPM <= E_PPM AND Run = 1 then
S_Ref_PPM = E_PPM
DAcc = 0
endif
S_Ref_PPM = S_Ref_PPM - 1
FinDAcc:
TimeAcc =0
Endif
'*************************************************
Set_Largo = E_Largo * S_Ref_PPM
GainP = Set_Largo / 233
If Error >= 18 && Pol = 1 Then
S_Ref_Largo = GainP + 3
EndIf
If Error >= 12 && Error < 18 && Pol = 1 Then
S_Ref_Largo = GainP + 2
EndIf
If Error >= 3 && Error < 12 && Pol = 1 Then
S_Ref_Largo = GainP + 1
EndIf
If Error >= 18 && Pol = 0 Then
S_Ref_Largo = GainP - 3
EndIf
If Error >= 12 && Error < 18 && Pol = 0 Then
S_Ref_Largo = GainP - 2
EndIf
If Error >= 3 && Error < 12 && Pol = 0 Then
S_Ref_Largo = GainP - 1
EndIf
If Error < 3 Then
S_Ref_Largo = GainP
EndIf
' ************** Referencia a Inversores *********************
Ref:
PR2 = 255 ' PR2 nos da la frecuencia del PWM 4 kHz
CCPR2L= S_Ref_PPM ' Salida de Referencia Paquetes por Minuto
CCPR1L = S_Ref_Largo ' Salida de Referencia de Largo de Paquete
Fin:
Goto Inicio
'********************** Fin de Programa ************************