Explico, realizo la secuencia de trigger escuchar el eco, trigger escuchar el eco, trigger escuchar el eco, y trigger escuchar el eco, y cuando lo ejecuto en algun momento se cuelga o se queda bloqueado.....
El programa:
program sensor
Si manejo uno solo de los sensores anda bien , pero si pongo dos de vez en cuando se queda colgado, intuyo que es dentro de alguno de los whiles!!!!
El programa:
program sensor
Código:
'TRIGGER Y ECHO DE CADA SENSOR
symbol TDI = porta.0 ''TRIGGER
symbol EDI = porta.1 ''ECHO
symbol TDD = porta.2 '' _______________________________
symbol EDD = porta.3 '' [ - E T 5V DI ]
'' [ - E T 5V DD ]
symbol TLI = porta.4 '' [ - E T 5V LI ]
symbol ELI = porta.5 '' [ - E T 5V LD ]
'' [ - E T 5V ATRAS ]
symbol TLD = portc.0 '' [ ]
symbol ELD = portc.1 '' [ ]
'' [ ]
symbol TA = portc.2 '' [ ]
symbol EA = portc.3 ''
'LED DE INDICACION
symbol DI = portb.0
symbol DD = portb.1
symbol LI = portb.2
symbol LD = portb.3
symbol TRASERO = portb.4
symbol ALCANCE = 8000
symbol ALCANCE_useg = 5024
'DECLARACIONES DE VARIABLES
dim duration_us as word
distance as word
length_mm as char[4]
'SETUP DEL PIC
sub procedure InitMain()
OPTION_REG = 0x80 ' Pull-up disabled PORTB
INTCON = 0x00 ' Disable interrupts
adcon1 = $06 'ESTO ES PARA EL 16F873A
''ansel=0
''anselh=0
porta = 0
trisa = %00101010 '' - - E T E T E T
portb = 0
trisb = %00000000
portc=0
trisc= %10001010 '' RX TX - - E T E T
end sub
'MAIN
main:
aaa:
InitMain()
duration_us = 0
distance = 0
DI = 1
DD = 1
LI = 1
LD = 1
TRASERO =1
DELAY_MS(1000)
DI = 0
DD = 0
LI = 0
LD = 0
TRASERO =0
DELAY_MS(1000)
'' goto aaa
volver:
''********************************************************************
TDI = 1 ' Trigger the module for 10usec
delay_us(10)
TDI = 0
while EDI = 0 ' Waiting for the echo
''Si no anda cuando desconectamos el sensor cambiamos trigger con echo en todos los sensores!!! y agregamos la resis de pulldown
nop
wend
TMR1L = 0 ' Clear the TMR1L value
TMR1H = 0 ' Clear the TMR1H value
T1CON = 0x01 ' Enable TMR1
while EDI = 1 ' While echo received, let the TMR1 count
''Lo meto aca dentro para poder terminar antes si no anda el sensor!!!!
''duration_us = TMR1H<<8 + TMR1L ' Retain TMR1 value = ON pulse
nop
wend
T1CON = 0
duration_us = TMR1H<<8 + TMR1L ' Retain TMR1 value = ON pulse
distance = duration_us * 1.716 * 0.927856 ''useg /58 = centimetros
'' Me parece que son 5024useg los 80cm ALCANCE_useg
'' 343.2 m/seg o 34,32cm/seg es la velocidad del sonido, y la distancia sensada es el doble!!!
IF (distance > ALCANCE) THEN
''IF (duration_us > ALCANCE_useg) THEN
DI=0
ELSE
DI=1
END IF
delay_ms(10)
''********************************************************************
''********************************************************************
TDD = 1 ' Trigger the module for 10usec
delay_us(10)
TDD = 0
while EDD = 0 ' Waiting for the echo
nop
wend
TMR1L = 0 ' Clear the TMR1L value
TMR1H = 0 ' Clear the TMR1H value
T1CON = 0x01 ' Enable TMR1
while EDD = 1 ' While echo received, let the TMR1 count
nop
wend
T1CON = 0
duration_us = TMR1H<<8 + TMR1L ' Retain TMR1 value = ON pulse
distance = duration_us * 1.716 * 0.927856
IF (distance > ALCANCE) THEN
'' IF (duration_us > ALCANCE_useg) THEN
DD=0
ELSE
DD=1
END IF
delay_ms(10)
''********************************************************************
GOTO volver
end.
Si manejo uno solo de los sensores anda bien , pero si pongo dos de vez en cuando se queda colgado, intuyo que es dentro de alguno de los whiles!!!!
Última edición por un moderador: