Code:
<font color="#000000"><b>DEFINE </b>OSC 8
TRISA = %00100000 <font color="#0000FF"><i>' PortA : All outputs except RA.1 for INT_INT
</i></font>TRISB = %01000100 <font color="#0000FF"><i>' PWM1,3,5 outputs,RB2=INT, RB0,2,3: DIO
</i></font>ADCON1 = %00001111 <font color="#0000FF"><i>' Set up ADCON1
</i></font>T1CON = %10000001 <font color="#0000FF"><i>' 16bit, 1:1 ps, 30 mS INT
'T0CON = %11000101 ' On, 8b, PSon, 1:64 : DIDN'T HELP
</i></font>RCON = %00011111 <font color="#0000FF"><i>' NO Priority for interrupts
</i></font>OSCCON = %11111110 <font color="#0000FF"><i>' INTOSC, 8MHz
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
</i></font><b>INCLUDE </b><font color="#FF0000">"DT_INTS-18.bas" </font><font color="#0000FF"><i>' Base Interrupt System
</i></font><b>INCLUDE </b><font color="#FF0000">"ReEnterPBP-18.bas" </font><font color="#0000FF"><i>' Include if using PBP interrupts
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
' Variable definition
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
</i></font>EchoTime <b>VAR WORD
</b>OutPulseCnt <b>VAR BYTE
</b>Gain <b>VAR BYTE
</b>PL1lo <b>CON </b>$A7 <font color="#0000FF"><i>' Preload for TMR1 LO byte, Cycle time
</i></font>PL1hi <b>CON </b>$15 <font color="#0000FF"><i>' Preload TMR1 HI byte ,PL =5543/ 1:1
'***************************************************************************
</i></font><b>ASM
</b><font color="#008000">INT_LIST macro </font><font color="#0000FF"><i>; IntSource, Label, Type, ResetFlag?
</i></font><font color="#008000">INT_Handler INT2_INT, _GetEcho, ASM, yes </font><font color="#0000FF"><i>;straight I/P
</i></font><font color="#008000">INT_Handler TMR0_INT, _BlankGain, ASM, yes
INT_Handler TMR1_INT, _Transmit, ASM, yes
endm
INT_CREATE </font><font color="#0000FF"><i>; Creates the interrupt processor
</i></font><b>ENDASM
</b><font color="#008000">@ INT_ENABLE TMR1_INT </font><font color="#0000FF"><i>; enable Timer 1 to start sonic cycle
'***************************************************************************
</i></font>Mainloop:
<font color="#0000FF"><i>' code here
</i></font><b>GOTO </b>Mainloop
<font color="#0000FF"><i>'*********** Int handlers **************************************************
'---[TMR1 - interrupt handler]-------------------------------
' TMR1 = 16 bit, 1:1, 65535 - 5543(preload) =30 mS cycle, (WORKS WELL)
</i></font>Transmit:
<font color="#008000">@ INT_DISABLE INT_INT </font><font color="#0000FF"><i>; Disable external ints to stop Echo RX
</i></font>TMR1H = PL1hi <font color="#0000FF"><i>'Preload HI byte
</i></font>TMR1L = PL1lo <font color="#0000FF"><i>'Preload LO byte =
</i></font>OutPulseCnt = 0 <font color="#0000FF"><i>'clear everything & start new cycle
</i></font>Gain = 0 <font color="#0000FF"><i>' zero the gain counter
</i></font>PORTA = Gain <font color="#0000FF"><i>' turn off the gain
</i></font><b>ASM
</b><font color="#008000">BSF</font> <font color="#008000">PORTB,0 </font><font color="#0000FF"><i>; pulse out
</i></font><font color="#008000">NOP
NOP
BCF PORTB,0
NOP
NOP
</font><b>ENDASM
</b><font color="#0000FF"><i>'+++++++++++ HERE IS THE ISSUE and different things tried ++++++++++++++++++++
' T0CON = %11000100 ' On, 8b, PSon, 1:32, For Blanking
' TMR0L = 199 ' Blanking delay: .9mS : NOPE
</i></font><font color="#008000">@ INT_ENABLE TMR0_INT </font><font color="#0000FF"><i>; Enable TMR0 to start Blanking/Gain block
' TMR0L = 199 ' Blanking delay: .9mS : WAY OFF!
' T0CON = %11000100 ' On, 8b, PSon, 1:32
</i></font>TMR0L = 40 <font color="#0000FF"><i>' Blanking delay: .9mS : CLOSEST!? WHY???
</i></font>T0CON = %11000010 <font color="#0000FF"><i>' On, 8b, PSon, 1:8
' TMR0L = 40 ' tried loading after T0CON, no dif
</i></font><font color="#008000">@ INT_RETURN
</font><font color="#0000FF"><i>'---[TMR0 - interrupt handler]-------------------------------
' 1 cycle through TMR0 with value loaded at end of transmit (TMR1), (~.9mS)
' then change TMR0 to ~2.74mS increments
</i></font>BlankGain:
OutPulseCnt = OutPulseCnt +1 <font color="#0000FF"><i>'1st pass, TMR0 Blanking set @ end of "TX"
</i></font><b>SELECT CASE </b>OutPulseCnt
<b>CASE </b>1
<font color="#0000FF"><i>' TMR0L = 84 ' PL 2.74mS INT : THIS MESSES IT ALL UP
' T0CON = %11000100 ' On, 8b, PSon, 1:32, for Gain step
</i></font><font color="#008000">@ INT_ENABLE INT2_INT </font><font color="#0000FF"><i>; enable INT2 to catch Echo
</i></font><font color="#008000">@ INT_RETURN </font><font color="#0000FF"><i>; go back for next INT on TMR0
'+++++++++++++END OF SUSPECTED THINGS THAT CAN AFFECT THE ISSUE+++++++++++
</i></font><b>CASE </b>2
<b>GOTO </b>MoreGain <font color="#0000FF"><i>' 2nd pass: Gain inc 1
</i></font><b>CASE </b>3
<b>GOTO </b>MoreGain <font color="#0000FF"><i>' gain inc'd to 2
</i></font><b>CASE </b>4
<b>GOTO </b>MoreGain <font color="#0000FF"><i>' gain inc'd to 3
</i></font><b>CASE </b>5
<b>GOTO </b>MoreGain <font color="#0000FF"><i>' gain inc'd to 4
</i></font><b>CASE </b>6 <font color="#0000FF"><i>'.......
'........
</i></font><b>CASE IS </b>> 14
<b>GOTO </b>EndGain <font color="#0000FF"><i>'
</i></font><b>END SELECT
</b>MoreGain:
Gain = Gain + 2 <font color="#0000FF"><i>' increment gain: RA.0 is I/P, so count x2
</i></font>PORTA = Gain <font color="#0000FF"><i>'sent out RA.1-RA.4 to control gain on amp
</i></font>EndGain:
<font color="#008000">@ INT_DISABLE TMR0_INT </font><font color="#0000FF"><i>; Shut-off Blanking & Gain incr until next cycle
</i></font><font color="#008000">@ INT_RETURN
</font><font color="#0000FF"><i>'---[INT - interrupt handler]-----------------------------------------------
</i></font>GetEcho:
<font color="#0000FF"><i>'@ INT_DISABLE TMR0_INT ; Haven't seen a need for this yet
</i></font>EchoTime.LowByte=TMR1L <font color="#0000FF"><i>' capture the counts
</i></font>EchoTime.HighByte=TMR1H
<font color="#0000FF"><i>'@ INT_ENABLE TMR0_INT ; Re-enable TMR0
</i></font><font color="#008000">@ INT_RETURN
</font><b>END
</b>
Again, thank you for looking at it.
Bookmarks