Hello,
I want to count, as an example, how much time (or instruction cycles) a FOR/NEXT loop takes to do its count using TMR1 in Timer mode.
So I made this piece of code but I can never read any result in the PIC's memory (I have the PIC connected to my PICKit2 so I can readout the memory easely).
What am I doing wrong?
Code:
<html><head></head><body><!--StartFragment--><pre><code><font color="#000080"><i>' Fuses PIC16F88
</i></font><font color="#008000">@ DEVICE INTRC_OSC_NOCLKOUT
@ DEVICE PROTECT_OFF
@ DEVICE WDT_ON
@ DEVICE PWRT_OFF
@ DEVICE MCLR_OFF
@ DEVICE BOD_OFF
@ DEVICE LVP_OFF
@ DEVICE CPD_OFF
@ DEVICE DEBUG_OFF
@ DEVICE CCPMX_OFF
@ DEVICE2 IESO_OFF
@ DEVICE2 FCMEN_OFF
</font><font color="#000080"><i>'____________________________________________________________________________
' Registers 76543210
</i></font>OPTION_REG = %10000000 <font color="#000080"><i>' PORTB Pull-Ups disabled
</i></font>ANSEL = %00000000 <font color="#000080"><i>' Disable analog inputs
</i></font>ADCON0 = %00000000 <font color="#000080"><i>' A/D Module is OFF
</i></font>CMCON = %00000111 <font color="#000080"><i>' Comparator Module is OFF
</i></font>INTCON = %00000000 <font color="#000080"><i>' All Interrupts are disabled
</i></font>TRISA = %00000000 <font color="#000080"><i>' Set Input/Output
</i></font>PORTA = %00000000 <font color="#000080"><i>' Ports High/Low
</i></font>TRISB = %00000000 <font color="#000080"><i>' Set Input/Output
</i></font>PORTB = %00000000 <font color="#000080"><i>' Ports High/Low
</i></font>T1CON = %00000000 <font color="#000080"><i>' TMR1 settings
'____________________________________________________________________________
' Variables
</i></font>Ctr_A <b>VAR BYTE </b><font color="#000080"><i>' counter
</i></font>Ctr_B <b>VAR WORD </b><font color="#000080"><i>' counter
</i></font>Mem_Loc <b>VAR WORD </b><font color="#000080"><i>' memory Location Pointer
</i></font>Result <b>VAR WORD</b>(10) <font color="#000080"><i>' holds the TMR1 value
</i></font>Ctr_A = 0
Ctr_B = 0
Mem_Loc = $FA8
Result = 0
<font color="#000080"><i>'____________________________________________________________________________
' Program
</i></font><b>FOR </b>Ctr_A = 0 <b>TO </b>9 <font color="#000080"><i>' 10 count loop
</i></font>TMR1H = 0 <font color="#000080"><i>' reset Timer
</i></font>TMR1L = 0 <font color="#000080"><i>' reset Timer
</i></font>T1CON.0 = 1 <font color="#000080"><i>' start Timer
</i></font><b>FOR </b>Ctr_B = 0 <b>TO </b>100 : <b>NEXT </b>Ctr_B <font color="#000080"><i>' let TMR1 increment a little
</i></font>T1CON.0 = 0 <font color="#000080"><i>' stop Timer
</i></font>Result.LowByte = TMR1L <font color="#000080"><i>' store LOW TMR1's value to Result
</i></font>Result.HighByte = TMR1H <font color="#000080"><i>' store HIGH TMR1's value to Result
</i></font>Result[Ctr_A] = Ctr_A <font color="#000080"><i>' assign Result's index
</i></font><b>NEXT </b>Ctr_A <font color="#000080"><i>' loop
</i></font><b>ERASECODE </b>Mem_Loc <font color="#000080"><i>' free-up 32 mem locations
</i></font><b>FOR </b>Ctr_A = 0 <b>TO </b>9 <font color="#000080"><i>' 10 count loop
</i></font><b>WRITECODE </b>Mem_Loc, Result[Ctr_A] <font color="#000080"><i>' store Result(x) var
</i></font>Mem_Loc = Mem_Loc + 1 <font color="#000080"><i>' increment mem location
</i></font><b>NEXT </b>Ctr_A <font color="#000080"><i>' loop
</i></font><b>END</b></code></pre><!--EndFragment--></body></html>
Bookmarks