Understanding timer issues
Hi all,
trying to understand why this isn't working as it seems it should.
The Transmit: TMR1 Int handler is ~30mS and works fine. At the end of the TMR1 int, TMRO is given settings so that the first cycle through, there should be a ~190uS int cycle. After the first cycle, the TMR is reloaded so that the next passes are ~2.74 mS. For some reason, the two timer loads affect each other and changing one affects both areas in ways that I'm not understanding. I can't get any single point to adjust the two timing areas.
Code:
<font color="#000000"><b>DEFINE </b>OSC 8
<b>DEFINE </b>DEBUG_REG PORTA
<b>DEFINE </b>DEBUG_BIT 0
<b>DEFINE </b>DEBUG_BAUD 2400
<b>DEFINE </b>DEBUG_MODE 0
<b>CLEAR
</b>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>'
</i></font>T1CON = %10000001 <font color="#0000FF"><i>' 16bit, 1:1 ps, 30 mS INT
</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>DEBUG </b><font color="#FF0000">"CSS1330-2inc"</font>,13,10
<font color="#0000FF"><i>'::::::::::::
</i></font><b>INCLUDE </b><font color="#FF0000">"DT_INTS-18.bas" </font><font color="#0000FF"><i>'
</i></font><b>INCLUDE </b><font color="#FF0000">"ReEnterPBP-18.bas" </font><font color="#0000FF"><i>'
'::::::::::::
</i></font>EchoTime <b>VAR WORD
</b>OutPulseCnt <b>VAR BYTE
</b>Gain <b>VAR BYTE
</b>GCA <b>VAR </b>PORTA.1
GCB <b>VAR </b>PORTA.2
GCC <b>VAR </b>PORTA.3
GCD <b>VAR </b>PORTA.4
PulseOut <b>VAR </b>PORTB.0
EchoIn <b>VAR </b>PORTB.2
ledR <b>VAR </b>PORTB.3 <font color="#0000FF"><i>'
</i></font>ledG <b>VAR </b>PORTB.4 <font color="#0000FF"><i>'
</i></font>Prog <b>VAR </b>PORTB.6 <font color="#0000FF"><i>'
</i></font>CntSw <b>VAR WORD
</b>flag <b>VAR BYTE
</b>IncCnt <b>VAR BYTE
</b>MdCnt <b>VAR BYTE
</b>TimOut <b>VAR BYTE
</b>Lock <b>VAR </b>flag.0 <font color="#0000FF"><i>' 1= locked, 0 = unlocked
</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>;
</i></font><b>ENDASM
</b><font color="#008000">@ INT_ENABLE TMR1_INT </font><font color="#0000FF"><i>; enable Timer 1 interrupts
'***************************************************************************
</i></font><b>GOTO </b>Start
<font color="#0000FF"><i>'*** Sub to Select MODE *************************************
</i></font>ModeSelect:
<font color="#0000FF"><i>' first time through, need to unlock. Then can pass to others
</i></font><b>IF </b>MdCnt = 2 <b>THEN </b><font color="#0000FF"><i>'1st check for unlock
</i></font>Lock = 0
<b>ENDIF
IF </b>Lock = 0 <b>THEN
</b>ledG = 1 <font color="#0000FF"><i>'
</i></font><b>ELSE
</b>ledG = 0
<b>GOTO </b>DoneCk
<b>ENDIF
SELECT CASE </b>MdCnt
<b>CASE </b>1
Lock = 1
<b>DEBUG </b><font color="#FF0000">"Case 1"</font>,13,10
<b>GOTO </b>DoneCk
<b>CASE </b>2
Lock = 0
<b>GOTO </b>DoneCk
<b>DEBUG </b><font color="#FF0000">"Case 2"</font>,13,10
<b>CASE </b>3
<b>DEBUG </b><font color="#FF0000">"Case 3"</font>,13,10
<b>CASE IS </b>>3
<b>DEBUG </b><font color="#FF0000">"Case >3"</font>,13,10
Lock = 1
<b>END SELECT
</b>DoneCk:
IncCnt = 0 <font color="#0000FF"><i>' reset MODE counter
</i></font><b>RETURN
</b><font color="#0000FF"><i>'**********************
'* END Subs
'**********************
</i></font>Start:
Lock = 1
Mainloop:
<b>DEBUG </b>#EchoTime,13,10
<font color="#0000FF"><i>'code for menu selection 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
</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 = $15 <font color="#0000FF"><i>'
</i></font>TMR1L = $A7 <font color="#0000FF"><i>'
</i></font>OutPulseCnt = 0 <font color="#0000FF"><i>' start new cycle
</i></font>Gain = 0 <font color="#0000FF"><i>'
</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
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTB,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BSF</font> <font color="#008000">PORTB,0
NOP
NOP
NOP
NOP
NOP
NOP
NOP
BCF PORTB,0
</font><b>ENDASM
</b>T0CON = %11001000 <font color="#0000FF"><i>' On, 8b, PSon, 1:1, For Blanking
</i></font>TMR0L = 70 <font color="#0000FF"><i>' Blanking inhibit 190uS ???
</i></font><font color="#008000">@ INT_ENABLE TMR0_INT </font><font color="#0000FF"><i>; Enable TMR0 to start Blanking/Gain block
</i></font><font color="#008000">@ INT_RETURN
</font><font color="#0000FF"><i>'---[TMR0 - interrupt handler]-------------------------------
' inhibit GetEcho for 1 cycle through TMR1 with value loaded at end of transmit
' code then change TMR1 to ramp up gain in 2.74mS steps
</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
T0CON = %11000101 <font color="#0000FF"><i>' On, 8b, PSon, 1:64, for Gain step
</i></font>TMR0L = 170 <font color="#0000FF"><i>' Preload to 170 for 2.74mS INT
</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
</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
<b>GOTO </b>MoreGain <font color="#0000FF"><i>' gain inc'd to 5
</i></font><b>CASE IS </b>> 6
<b>GOTO </b>EndGain
<b>END SELECT
</b>MoreGain:
Gain = Gain + 2 <font color="#0000FF"><i>' RA.0 is I/P, so count x2
</i></font>PORTA = Gain <font color="#0000FF"><i>'sent out RA.1-RA.4, set gain amp
</i></font>SkipGain:
<font color="#008000">@ INT_RETURN
</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:
EchoTime.LowByte=TMR1L
EchoTime.HighByte=TMR1H <font color="#0000FF"><i>' capture the counts
</i></font><font color="#008000">@ INT_RETURN
</font><b>END
</b>
The DEBUG quits after the splash. I suspect it is getting blown up by the interrupt.
Thanks for looking at it.
Bo