Hi, Just got this reply from Microchip explain the oddity I've been seeing, after a bit of a delay. Thought it might be useful to some people. It has certainly restored my confidence in my mental health!! Just need to work round it now..... : ( Thanks, DAN > > From: Tech.Support@microchip.com > Date: 2003/03/11 Tue PM 10:42:33 GMT > To: > Subject: Re: Fw: PIC18F252 Instruction Count Issue > > > Daniel > > I apologize for the delay. I do not know what happened to your first email. > > I tried out the code and the both the interrupt latency and the delayed > increment after writes to the timer seem to be incorrectly simulated. Since > there is one interrupt and two writes to the timer, this probably accounts > for the three cycles missing in the simulation. I will report the issue to > our developers to get fixed. As a general rule, if the part and the > simulator behave differently, the part is right and the simulator is wrong! > > Sincerely, > > Mike Garbutt > Sr. Applications Engineer > Microchip Technology > > > > > > world.com> To: tech.support@microchip.com > cc: > 03/11/2003 08:23 Subject: Fw: PIC18F252 Instruction Count Issue > AM > > > > > > > Hi, > > I sent this mail to the Tech Support area on hte 28th February. Is it > possible for somebody to tell me the status if this query or if it is not > going to be dealt with? > > Thank you for your help, > Regards, > Daniel Sweet > ----- Original Message ----- > From: > To: > Sent: Friday, February 28, 2003 2:34 PM > Subject: PIC18F252 Instruction Count Issue > > > > Hi, > > > > I have been seeing some discrepancies between the instruction count of > the MPLAB Simulator and the actual ouput 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. > > > > 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 6 on a scope I see slightly > different timing: > > > > 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. The attached excel file is a copy of the > data from the scope. > > > > Am i doing something stupid here?!! Why do I see this difference? Is the > chip doing something else that I don't know about? > > > > 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 > > > > > INCLUDE > > 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 hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu