Searching \ for '[PIC]:PIC18F252 Instruction Count Discrepancy' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=count
Search entire site for: 'PIC18F252 Instruction Count Discrepancy'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:PIC18F252 Instruction Count Discrepancy'
2003\03\11@124323 by daniel_sweet

picon face
part 1 1636 bytes content-type:text/plain; charset=ISO-8859-1 (decoded 7bit)

Hi,

I have been seeing some discrepancies between the instruction count of the MPLAB Simulator and the actual output of the PIC. Generally I feel that the simulator count is correct ( by counting instructions myself!) and that something else is happening with the chip. I am fairly new to PICs and very new to the PC18F252 so wander if I am doing something stupid (?!).

As an example, I have setup a simple loop using TMR0 to generate a pulse on PortB, bit 7.

Conditions:
PIC18F252
MPLAB 6.12
10Mhz Crystal HS-PLL = 40Mhz clock

Using the simulator stopwatch I have measured that the period should be as follows:

High = 261 instruction Cycles (26.1us)
Low  = 260 Instruction Cycles (26.0us)

When I look at the output from PortB, bit 7 on a scope I see slightly different timing to that expected:

High = 26.1us
Low = 26.3us

This shows a difference in the low period of 0.3us or 300ns which is equal to 3 Instruction cycles.

Am i doing something stupid here?!! Why do I see this difference? Is the chip doing something else that I don't know about?
Can anyone sanity check me by running this code at all?

I have seen this problem when running the chip in HS mode @20Mhz and also when doing other loops, that don't use interrupts. I was running a similar program on the PIC16F84 and never saw this problem.

Any help or comments you may have would be much appreciated. I hope I have included enough information for you

Regards,
Daniel Sweet


--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body




part 2 3841 bytes content-type:text/plain;
       INCLUDE <P18F252.inc>

F       EQU     .1              ;FOR DESTINATION ARGUMENT


;STATUS EQU     .3              ;STATUS REGISTER:
CF      EQU     .0              ;  BIT 0 = CARRY BIT FLAG
DCF     EQU     .1              ;  BIT 1 = DIGIT CARRY BIT FLAG
ZF      EQU     .2              ;  BIT 2 = ZERO BIT FLAG
PDF     EQU     .3              ;  BIT 3 = POWER DOWN BIT FLAG
TOF     EQU     .4              ;  BIT 4 = TIME OUT BIT FLAG
RP0     EQU .5          ;  Bit 5 = Page Select
                               ;  BITS 5,6,7 DO NOT APPLY TO PIC16C54

NOTHING EQU     .0              ;USED TO RETURN NOTHING FROM SUBROUTINES

TRISC   EQU  H'0F94'
TRISB   EQU  H'0F93'
TRISA   EQU  H'0F92'


;IntCon
RIBF    Equ     .0
INT0IF  Equ     .1
TMR0IF  Equ     .2
RBIE    Equ     .3
INT0IE  Equ     .4
TMR0IE  Equ     .5
PEIE    Equ     .6
GIE             Equ     .7

;TOCON
T0PS0   Equ .0
T0PS1   Equ .1
T0PS2   Equ .2
PSA             Equ     .3
T0SE    Equ     .4
T0CS    Equ .5
T08BIT  Equ     .6
TMR0ON  Equ     .7

RAM     EQU     0Ch             ;START OF RAM
BODY    EQU     000H            ;START OF PROGRAM

       ORG     RAM             ;Start of RAM

       CBLOCK  0ch

               Count

       endc

       ORG     BODY            ;Start of ROM

       GOTO Start

       org     0x000008                ; high priority interrupt vector
       bra     TMR0_ISR

       org     0x000018                ; low priority interrupt vector
       RETFIE

;
;Call extenders
;
InitHw  GOTO    InitHwX

;
;Initialize the hardware
;
InitHWX
;       CLRWDT                  ;Reset watchdog timer
;       MOVLW   3Fh             ;External edge to timer
;       OPTION                  ;High to low edge for timer
                               ;Prescaler assigned to watchdog
                               ;Prescaler divide by 128 for now

       CLRF    BSR

       BSF ADCON1,PCFG1
       BSF ADCON1,PCFG2

       CLRF    PORTA
       CLRF    LATA
       MOVLW   008h
       MOVWF   TRISA
       MOVLW   00h
       MOVWF   TRISB
       MOVWF   TRISC
       RETLW   Nothing         ;End of "InitHW"
;--------------------PROGRAM-----------------------------------
START

       CALL    InitHw          ;Initialize hardware

;Set up priority interrupts.
       bsf     RCON,IPEN       ;enable priority interrupts.
;       bsf     IPR1,TMR1IP     ;set Timer1 as a high priority interrupt source
       bcf     INTCON,TMR0IF   ;clear the Timer1 interrupt flag
       bsf     INTCON,TMR0IE   ;enable Timer1 interrupts
       bsf     INTCON,GIEH     ;set the global interrupt enable bits

;Timer1 setup
       clrf    T0CON
       bsf             T0CON,PSA
       bcf             T0CON,T0CS
       bsf             T0CON,T08BIT
       clrf    TMR1H           ;clear Timer1 high
       clrf    TMR1L           ;clear Timer1 low
       bsf             T0CON,TMR0ON    ;turn on Timer1

MLOOP
       goto    MLOOP

;-------------------------------SUBROUTINES---------------------------------
TMR0_ISR                        ; high priority isr

       clrf    TMR0L
       bsf     PORTB,7         ;Turn on PORTB<7> to indicate high priority
       bcf     INTCON,TMR0IF   ;Clear the Timer1 interrupt flag.

T0POLL
       btfss   INTCON,TMR0IF   ;Poll TMR11 interrupt flag to wait for another
                               ; TMR1 overflow.
       bra     T0POLL
       bcf     INTCON,TMR0IF   ;Clear the Timer1 interrupt flag again.
       CLRF    TMR0L
       bcf     PORTB,7         ;Turn off PORTB<7> to indicate the
                               ; high-priority ISR is over.
       retfie


       return

       END
;
;


--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body




part 3 2 bytes
-

2003\03\11@125400 by

flavicon
face
Can you realy see the difference between 26.0 and 26.3 us
on a scope ? Does the overall frequency also have the same
differense ?

Jan-Erik Söderholm.

daniel_sweetspamKILLspamNTLWORLD.COM wrote:

> Using the simulator stopwatch I have measured that the period should be as follows:
>
> High = 261 instruction Cycles (26.1us)
> Low  = 260 Instruction Cycles (26.0us)
>
>When I look at the output from PortB, bit 7 on a scope I see slightly different timing to that expected:
>
>High = 26.1us
>Low = 26.3us

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body

2003\03\11@170615 by Herbert Graf

flavicon
face
It is very likely the original poster is using a digital scope to measure
the pulse. Those scopes CAN be great, however when using the measure
function you have to be very careful WHERE the scope is measuring things. It
is likely that there is some capacitance on the line that is "rounding" the
edges causing a slightly longer time to be measured then what the PIC is
outputting. TTYL

> {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...