Searching \ for ' [PIC] Errors suddenly appearing in ICD -' 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/devprogs.htm?key=icd
Search entire site for: 'Errors suddenly appearing in ICD -'.

No exact or substring matches. trying for part
PICList Thread
'[PICLIST] [PIC] Errors suddenly appearing in ICD -'
2001\04\27@153350 by Wendy Olend

flavicon
face
A few months ago, I was informed that my project team would be needing me to
write some firmware for the PIC 16f877.  Since I won't be taking my
"Introduction to Microcontrollers" class until this summer, I began to teach
myself about assembler, the chip and MPLAB.  After running around in circles for
quite awhile, I found a copy of Myke's book and finally started making some real
progress. (THANKS MYKE!!!)

Earlier this week, I finally felt comfortable enough to start writing some code.
My team leader advised me to become very familiar with interrupts, so  I decided
to design an 8-bit binary counter, utilizing an interrupt routine.  The
algorithm is simple:

    All necessary registers are initialized
    The program waits in MAIN for TMR1 to overflow, setting TMR1IF
    The value in COUNTER is written to PORTC (which is connected to a bank of
LEDs)
    The COUNTER is incremented and the whole thing starts again.

I spent a few days stomping bugs using MPLAB SIM.  Once I got everything
working, I loaded my demo board and used MPLAB ICD to see it in action.  I
expected everything to work perfectly (silly me).  However, I have observed
three problems which only occur In ICD.

    1.  When I clear TRISC, bits <1:0> do not reset.

    2.  When I initialize TMR1H, TMR1L does not increment.  This is pretty
minor, but I        want to understand why this is happening.

    3.  When the TMR1IF sets, the program does not go to the interrupt vector.
It just stays in the     Main loop indefinitely.

These problems occur every time I load the program, and ONLY while stepping
through the code in ICD; everything is still fine if I step through in SIM.

Before I drive myself crazy trying to fix my code, I'm wondering if anyone has
seen anything like this before.  It occurs to me that I could have a bad chip,
but I can't ask around for a new one until Monday.

So what do you think?  I'd appreciate any pointers, because this behavior seems
really strange to me.

Thanks,
Wendy

;*************************************************************
;*               cntrdemo.asm
;*    A demonstration program for the PIC 16f877
;*

;*


;*                Wendy Olend
;*               24 April 2001
;*


;*************************************************************

  list p=16f877              ;include files
  include"p16f877.inc"

COUNTER   equ  0x2d ;register declaration

  org         0x00
  goto        Initialize

  org         0x04
Interrupt
  movf        COUNTER,w ;copy counter value and
  movwf  PORTC          ;send it to PORTC
  incf        COUNTER,f ;increment counter
  bcf         PIR1,0         ;reset TMR1IF
  movlw       0xf0      ;TEST ONLY
  movwf  TMR1L          ;TMR1 will count from 0000-FFFF
  movlw       0xff      ;in actual execution
  movwf  TMR1H
  retfie

Initialize
  bsf         STATUS,RP0     ;switch to bank1
  bsf         INTCON,7  ;EN GIE
  bsf         INTCON,6  ;EN peripherial interrupts
  bsf         PIE1,0         ;EN TMR1 interrupt
  clrf        TRISC          ;PORTC all outputs
  bcf         STATUS,RP0     ;switch to bank0
  clrf        PORTC          ;make sure PORTC is clear
  movlw       b'00001101'    ;TMR1 setup prescaler 1:1,osc EN,
  movwf  T1CON          ;internal clock, timer EN

  movlw       0xf0      ;TEST ONLY
  movwf  TMR1L          ;TMR1 will count from 0000-FFFF
  movlw       0xff      ;in actual execution
  movwf  TMR1H

  bcf         PIR1,0         ;clr TMR1 overflow flag
  movlw       0x01      ;initialize counter
  movwf  COUNTER
Main
 goto         Main      ;wait for TMR1 to overflow
                   ;then goto interrupt vector
 END

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\04\27@173127 by Don Hyde

flavicon
face
{Quote hidden}

Do you have the bank bits set to bank 1?

>
>      2.  When I initialize TMR1H, TMR1L does not increment.
> This is pretty
> minor, but I        want to understand why this is happening.
>

Initializing won't immediately make it increment.  Perhaps you don't have
the ICD set to update the special function registers?  Since the ICD runs
much more slowly when it has to update all the registers on the screen, you
(or someone else) may have turned off some of the updating.

>      3.  When the TMR1IF sets, the program does not go to the
> interrupt vector.
> It just stays in the     Main loop indefinitely.

Do you have GIE and PEIE set?

Also, what evidence do you have that the interrupt has or has not run?  The
ICD only allows you to set one breakpoint, so debugging interrupts can be
somewhat more difficult with it.

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\04\27@181640 by Wayne Hortensius

flavicon
face
There may be more going on here (i.e. this is the first thing that struck
me), but for starters, I'd try moving the bsf INTCON,GIE down to the last
instruction before the main loop. Try that and see if it makes any difference.

Since you're turning on the interrupts before you get everything
initialized, I think there's a chance you're actually getting a TMR1
interrupt during your initialization code (since the contents of TMR1H &
TMR1L are not defined at startup, you could get an interrupt almost
immediately if they both happen to like coming up as 0xFF). Since you're
not saving W in the interrupt routine, you can't depend on the value of W
actually being what you think it is from instruction to instruction (i.e.
it could suddenly be 0xFF, as that's the last value it has during the
interrupt).

Regards,
Wayne

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\04\27@195559 by Bob Ammerman

picon face
> >      1.  When I clear TRISC, bits <1:0> do not reset.

Do you have the T1OSC enabled on pins C0 and C1?

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\04\28@105606 by rob

flavicon
picon face
I read somewhere that ICD doesn' t correctly support  tmr interrupts.
Correct me if am wrong.
----- Original Message -----
From: Wendy Olend <Wendy_J_OlendspamKILLspamRAYTHEON.COM>
To: <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU>
Sent: Friday, April 27, 2001 8:21 PM
Subject: [PIC] Errors suddenly appearing in ICD -Newbie


> A few months ago, I was informed that my project team would be needing me
to
> write some firmware for the PIC 16f877.  Since I won't be taking my
> "Introduction to Microcontrollers" class until this summer, I began to
teach
> myself about assembler, the chip and MPLAB.  After running around in
circles for
> quite awhile, I found a copy of Myke's book and finally started making
some real
> progress. (THANKS MYKE!!!)
>
> Earlier this week, I finally felt comfortable enough to start writing some
code.
> My team leader advised me to become very familiar with interrupts, so  I
decided
> to design an 8-bit binary counter, utilizing an interrupt routine.  The
> algorithm is simple:
>
>      All necessary registers are initialized
>      The program waits in MAIN for TMR1 to overflow, setting TMR1IF
>      The value in COUNTER is written to PORTC (which is connected to a
bank of
> LEDs)
>      The COUNTER is incremented and the whole thing starts again.
>
> I spent a few days stomping bugs using MPLAB SIM.  Once I got everything
> working, I loaded my demo board and used MPLAB ICD to see it in action.  I
> expected everything to work perfectly (silly me).  However, I have
observed
> three problems which only occur In ICD.
>
>      1.  When I clear TRISC, bits <1:0> do not reset.
>
>      2.  When I initialize TMR1H, TMR1L does not increment.  This is
pretty
> minor, but I        want to understand why this is happening.
>
>      3.  When the TMR1IF sets, the program does not go to the interrupt
vector.
> It just stays in the     Main loop indefinitely.
>
> These problems occur every time I load the program, and ONLY while
stepping
> through the code in ICD; everything is still fine if I step through in
SIM.
>
> Before I drive myself crazy trying to fix my code, I'm wondering if anyone
has
> seen anything like this before.  It occurs to me that I could have a bad
chip,
> but I can't ask around for a new one until Monday.
>
> So what do you think?  I'd appreciate any pointers, because this behavior
seems
{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\04\28@111536 by Roman Black

flavicon
face
{Quote hidden}

Wendy, seems not many people helped debug your code,
first, you are not saving or restoring context at
the start and end of the interrupt routine.
I think the datasheet has examples.
Also, the F877 defaults to make some pins analog
at startup, I didn't see you chenge this in your
code (ADCON1). There are probably some other small
things too, all adding up.

I suggest when working with a new PIC to make a
"setup" routine, you can use this with all your
future projects, and it covers all the register
setups for you. I do things like this:

    ; 16F84
    ;-------------------------
                               ; OPTION_REG
    movlw b'00000111'          ;
         ;  x-------           ; 7, 0=en, portb pullups
         ;  -x------           ; 6, 1=/, int edge select bit
         ;  --x-----           ; 5, timer0 source, 0=internal clock
         ;  ---x----           ; 4, timer0 ext edge, 1=\
         ;  ----x---           ; 3, prescaler assign, 1=wdt, 0=timer0
         ;  -----x--           ; 2,1,0,  prescaler rate select
         ;  ------x-            ; 111=256 timer0
         ;  -------x            ;
    banksel OPTION_REG         ; go reg bank 1
    movwf OPTION_REG           ; load data into OPTION_REG
    banksel 0                  ; back to normal bank 0
    ;-------------------------


This is just for the OPTION register. It looks
like a lot of work but once done you can just cut
and paste into future projects. And it really helps
to understand the register bits and what they do,
so much better than a long list of opcodes even
if they are well commented. :o)
-Roman

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


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