Searching \ for '[PIC]: Debugging Help Needed - Resetting?' 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/devices.htm?key=pic
Search entire site for: 'Debugging Help Needed - Resetting?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Debugging Help Needed - Resetting?'
2001\10\22@102938 by Allen Mahurin

picon face
Well, it doesn't take long to learn that THIS is the
resource pool.  Many of you have motivated me (through
your posts) to get into PICs, and I must say I enjoy
it ... until I got stuck.  I've programmed in BASIC
and even assembly for other chips, but this is my
first PIC program.  Could someone tell me if they see
a glaring error that I'm overlooking (I tend to do
that when I'm too close to it).

I have a program that's supposed to multiplex some
characters across 5 7-segment displays for about a
second, change to another set of characters for about
a second, go blank for another second, then repeat.
What my program *actually* does is show the first set
of characters and briefly flicker about every second
or two.  It's like it's resetting itself, and never
gets to the second set of characters.  I'd like to use
TMR0 for the 1 second intervals, but didn't fully
understand how to implement it, so I'm using the
variable loops.  Do I have an unintentional reset?

       list      p=16F84             ; list directive to
define processor
       #include <p16F84.inc>         ; processor specific
variable definitions

       __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _XT_OSC

; '__CONFIG' directive is used to embed configuration
data within .asm file.
; The labels following the directive are located in
the respective .inc file.

;***** VARIABLE DEFINITIONS

PCL             EQU             0x02            ; PCL RAM address
PortA           EQU             0x05            ; PortA RAM address
PortB           EQU             0x06            ; PortB RAM address
TrisA           EQU             0x85            ; TRISA RAM address
TrisB           EQU             0x86            ; TRISB RAM address
Status  EQU             0x03            ; Status RAM address
Z               EQU             0x02            ; Status Z Flag = Bit 2
RP0             EQU             0x05            ; Status RP0 bit = Bit 5
DelayL  EQU             0x0C            ; Delay register LOW byte
DelayM  EQU             0x0D            ; Delay register MID byte
DelayH  EQU             0x0E            ; Delay register HIGH byte
Pointer EQU             0x0F            ; Display data pointer
DispNum EQU             0x10            ; Selected display variable
Outer           EQU             0x11            ; Outer loop variable
Inner           EQU             0x12            ; Inner loop variable

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

; -------------
; PROGRAM START
; -------------


Main:           org 0x00                        ; Start address = 0000 (hex)
               clrf PortA                      ; Make sure all displays are off
               clrf PortB                      ; Make sure all segments are off
               bsf Status,RP0          ; Set RP0 for RAM page 1
               clrf TrisA                      ; All PortA = outputs
               clrf TrisB                      ; All PortB = outputs
               bcf Status,RP0          ; Set RP0 for RAM page 0
               bcf Status,0            ; Reset the Carry bit
               movlw 0x02                      ; Set the Inner loop
               movwf Inner
               movlw d'05'                     ; Set w = 5
               movwf Outer                     ; Set Outer = 5 (move w to Outer)

Show1:  decfsz Inner            ; Decrement Inner loop
               goto First1                     ; Z = 1, enter display routine
               decfsz Outer            ; Z = 0, decrement the Outer loop
               goto First1                     ; Z = 1, enter display routine
                                               ; Z = 0, exit the loop

               clrf PortA                      ; Make sure all displays are off
               clrf PortB                      ; including the first one
               movlw 0x02                      ; Set the Inner loop
               movwf Inner
               movlw d'16'                     ; Set w = 16
               movwf Outer                     ; Set Outer = 16 (move w to Outer)

Show2:  decfsz Inner            ; Decrement Inner loop
               goto First2                     ; Z = 1, enter display routine
               decfsz Outer            ; Z = 0, decrement the Outer loop
               goto First2                     ; Z = 1, enter display routine
                                               ; Z = 0, exit the loop

Blank:  clrf PortA                      ; Make sure all displays are off
               clrf PortB                      ; including the first one
               Call Delay2                     ; Wait for 1 second
               movlw 0x02                      ; Set the Inner loop
               movwf Inner
               movlw d'16'                     ; Set w = 16
               movwf Outer                     ; Set Outer = 16 (move w to Outer)
               Goto Show1                      ; Repeat the display loop

First1: clrf Pointer            ; Reset the pointer to 0
               clrf DispNum            ; Reset the display number
               movf Pointer,w          ; Put Pointer into W
               call DataTable1         ; Put digit value in W
               movwf PortB                     ; Now, display the new digit
               bsf PortB,0x07          ; Enable the first display
               call Delay1                     ; Brief pause
               bcf PortB,0x07          ; Disable the display
               incf Pointer            ; Add 1 to Pointer value
               incf DispNum            ; Make DispNum = 1

More1:  movf Pointer,w          ; Put Pointer into W
               call DataTable1         ; Put digit value in W
               movwf PortB                     ; Now, display the new digit
               movf DispNum,w          ; Put DispNum value in W
               movwf PortA             ; Enable the next display
               call Delay1                     ; Brief pause
               clrf PortA                      ; Disable the display
               incf Pointer            ; Add 1 to Pointer value
               rlf DispNum                     ; Rotate the DispNum value left
               movlw d'16'                     ; See if DispNum value has rotated too
far
               xorwf DispNum,w         ; to keep the range from pin 0 - 3
               btfsc Status,Z          ; Test the Zero bit
               goto Show1                      ; Z = 0, back to main loop
               goto More1                      ; Z = 1, next display of current loop

First2: clrf Pointer            ; Reset the pointer to 0
               clrf DispNum            ; Reset the display number
               movf Pointer,w          ; Put Pointer into W
               call DataTable2         ; Put digit value in W
               movwf PortB                     ; Now, display the new digit
               bsf PortB,0x07          ; Enable the first display
               call Delay1                     ; Brief pause
               bcf PortB,0x07          ; Disable the display
               incf Pointer            ; Add 1 to Pointer value
               incf DispNum            ; Make DispNum = 1

More2:  movf Pointer,w          ; Put Pointer into W
               call DataTable2         ; Put digit value in W
               movwf PortB                     ; Now, display the new digit
               movf DispNum,w          ; Put DispNum value in W
               movwf PortA                     ; Enable the next display
               call Delay1                     ; Brief pause
               clrf PortA                      ; Disable the display
               incf Pointer            ; Add 1 to Pointer value
               rlf DispNum                     ; Rotate the DispNum value left
               movlw d'16'             ; See if DispNum value has rotated too
far
               xorwf DispNum,w         ; to keep the range from pin 0 - 3
               btfsc Status,Z          ; Test the Zero bit
               goto Show2                      ; Z = 0, back to main loop
               goto More2                      ; Z = 1, next display of current loop

; -----------------------------
; SUBROUTINE: waste time (<3 ms)
; -----------------------------

Delay1: clrf DelayL                     ; Clear DelayL to 0
               movlw 0x05                      ; Set DelayM = '5'
               movwf DelayM
Wait1:  decfsz DelayL           ; Subtract 1 from DelayL
               goto Wait1                      ; If not 0, goto Wait1
               decfsz DelayM           ; Subtract 1 from DelayM
               goto Wait1                      ; If not 0, goto Wait1
               return                  ; Finish the delay

; --------------------------------------
; SUBROUTINE: waste more time (1 second)
; --------------------------------------

Delay2: clrf DelayL                     ; Clear DelayL to 0
               clrf DelayM                     ; Clear DelayM to 0
               movlw 0x0A                      ; Set DelayH = '10'
               movwf DelayH
Wait2:  decfsz DelayL           ; Subtract 1 from DelayL
               goto Wait2                      ; If not 0, goto Wait2
               decfsz DelayM           ; Subtract 1 from DelayM
               goto Wait2                      ; If not 0, goto Wait2
               decfsz DelayH           ; Subtract 1 from DelayH
               goto Wait2                      ; If not 0, goto Wait2
               return                  ; Finish the delay

; -----------------------------------------
; SUBROUTINE: lookup table for display data
; -----------------------------------------
; Bit 0 = Segment A
; Bit 1 = Segment B
; Bit 2 = Segment C
; Bit 3 = Segment D
; Bit 4 = Segment E
; Bit 5 = Segment F
; Bit 6 = Segment G
; Bit 7 = No connection

DataTable1:     addwf PCL               ; Add W value to PCL
               retlw b'01110110'               ; First symbol, first display
               retlw b'00111101'       ; Second symbol, first
display
               retlw b'01011011'       ; Third symbol, first
display
               retlw b'00111111'       ; Fourth symbol, first
display
               retlw b'01101001'       ; Fifth symbol, first
display

DataTable2:     addwf PCL                       ; Add W value to PCL
               retlw b'01000110'       ; First symbol, second
display
               retlw b'00101100'       ; Second symbol, second
display
               retlw b'00011001'       ; Third symbol, second
display
               retlw b'00110011'       ; Fourth symbol, second
display
               retlw b'01001001'       ; Fifth symbol, second
display


               END

By the way, I DID borrow some of the code (I read
someone else post the "Why reinvent the wheel?"
theory).  I altered variables much of the code for my
application.  When I ran it in MPLAB's simulator
(using NOPs for the delays), it seemed to run OK.  But
my programmed chips are running as explained at top.

Thanks in advance,

ATM



__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

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


2001\10\22@104301 by Eisermann, Phil [Ridg/CO]

flavicon
face
> -----Original Message-----
> Subject: [PIC]: Debugging Help Needed - Resetting?
>
>
> What my program *actually* does is show the first set
> of characters and briefly flicker about every second
> or two.  It's like it's resetting itself, and never
> gets to the second set of characters.

[snip]

>         __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _XT_OSC


It looks like you are enabling the watchdog timer, but you are never
resetting it in software. This is probably what is causing your resets. I
did not check if there are any other problems, but since you say it
similated fine, i'd try disabling the WDT first, to see if the problem goes
away.

-Phil

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


2001\10\22@121155 by Allen Mahurin

picon face
Doh!  Sorry about that - it was supposed to be set to
off.  The bad news is that it didn't change the
operation.   :(

I can make the circuit display the first set of
characters (with the current program), or the second
(by substituting Table2 in place of Table1) ... so
that part of the circuit works fine.  I just can't see
where/why it's looping back.  I even tried putting the
called lines of code above the originating code - to
see if maybe it was "going on" and repeating it ...
but no difference.

I'm open to suggestions.  If someone sees a glitch
I've missed, I'll gladly fix it.  If there's a better
way, such as using the TMR0 interrupt, I'll even do it
... I just don't quite understand setting it up (for 1
second).  I've thought about making the First and More
bits of code as subroutines.  Then, I'd use CALL
instead of GOTO.  This would allow me to see if the
code returns from these returns and can move on.  I'm
not sure ... looking for suggestions.   :)

Thanks again,

ATM

--- "Eisermann, Phil [Ridg/CO]" <peisermaspamKILLspamRIDGID.COM>
wrote:
> > {Original Message removed}

2001\10\22@122547 by Lawrence Lile

flavicon
face
Oh, man, I cannot count the times I forgot about the watchdog timer and had
this problem.  There are a few gotchas that always hang projects, especially
at the beginning, and I've made them all:

1.  Watchdog enabled, but not reset in software

2.  Master CLear enabled, but not held high in hardware

3.  Port GP3, or RA4,  which is open collector in some PICs, has no pullup
resistor

4.  Port RB3, which is a low voltage programming input in some PICs, held
high which louses up ICSP programming

5.  TRIS registers not set to the right direction.

Write these 1000 times in the  EEprom blackboard. Paste these on your
forehead or your computer monitor with a yellow sticky note, then look at it
every time you program a PIC.  If you make one of these common mistakes,
whack the sticky note with your palm and chant with me: "D'Oh!"

--Lawrence

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


2001\10\22@132419 by Allen Mahurin

picon face
LOL, thanks for the entertaining read.

Well, let's see:

> 1.  Watchdog enabled, but not reset in software

As smoeone else pointed out, I'd done the same ... but
setting it to OFF didn't correct the operation.  So
there's more ...

> 2.  Master CLear enabled, but not held high in
> hardware

I dno't see anywhere that I've enabled OR disabled it
(where should that be?) ... but it IS pulled high in
the hardware (through a 10k resistor).

> 3.  Port GP3, or RA4,  which is open collector in
> some PICs, has no pullup
> resistor

I tried to avoid this one completely ... RA4 is the
only I/O pin I didn't use.  RB0 - 6 control the 7
segments, while RB1 enables the first display and RA0
- 3 enable displays 2 - 5.

> 4.  Port RB3, which is a low voltage programming
> input in some PICs, held
> high which louses up ICSP programming

I'm using RB3, but I'm not doing ICSP programming.  I
have to pull the chip and drop it into a NoPPP to burn
the code.

> 5.  TRIS registers not set to the right direction.

I've got both "clrf TrisA" and "clrf TrisB" covered
(in the mainline of code, before the loops).

> Write these 1000 times in the  EEprom blackboard.
> Paste these on your
> forehead or your computer monitor with a yellow
> sticky note, then look at it
> every time you program a PIC.  If you make one of
> these common mistakes,
> whack the sticky note with your palm and chant with
> me: "D'Oh!"

I already did the DOH! for not turning of the WDT.
Other than that, thanks for the suggestions ... but
it's still broken.   ;)

ATM



__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

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


2001\10\22@185555 by Tony Nixon

flavicon
picon face
Allen Mahurin wrote:

> I have a program that's supposed to multiplex some
> characters across 5 7-segment displays for about a
> second, change to another set of characters for about
> a second, go blank for another second, then repeat.
> What my program *actually* does is show the first set
> of characters and briefly flicker about every second
> or two.  It's like it's resetting itself, and never
> gets to the second set of characters.  I'd like to use
> TMR0 for the 1 second intervals, but didn't fully
> understand how to implement it, so I'm using the
> variable loops.  Do I have an unintentional reset?


Only from the WDT enabled.

       __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _XT_OSC

Try...

       __CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC



This type of code is not recommended...

       movwf PortB             ; Now, display the new digit
       bsf PortB,0x07          ; Enable the first display
       call Delay1             ; Brief pause

Try...

       movwf PortB             ; Now, display the new digit
       goto $ + 1              ;  equals 2 NOP's
       bsf PortB,0x07          ; Enable the first display
       call Delay1             ; Brief pause



This is probably your code problem...

Show1:  decfsz Inner            ; Decrement Inner loop
       goto First1             ; Z = 1, enter display routine
       decfsz Outer            ; Z = 0, decrement the Outer loop
       goto First1


Try....

Show1:  decfsz Inner            ; Decrement Inner loop
       goto First1             ; Z = 1, enter display routine

       movlw 0x02              ; Reset the Inner loop
       movwf Inner
       decfsz Outer            ; Z = 0, decrement the Outer loop
       goto First1

In your code, [Inner] never gets reset, so it keeps decrementing to
0xFF, 0xFE etc.

Same for the [Show2:] code lines.

--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
salesspamspam_OUTbubblesoftonline.com

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


2001\10\23@084535 by Allen Mahurin

picon face
First of all, I'm happy to say that the suggestions
about the WDT yesterday paid off!  I have to retract
my comment about it not working.  I ran the circuit
for over 10 minutes (before), but the WDT was
resetting it.  After setting it to OFF, I never ran it
more than 1 minute.  It turns out that my time delay
was having the characters cycle every 1.5 minutes!  As
of now, the circiut works fine ... thanks a bunch
guys!

However, I'm confused by a couple of these last
suggestions:

{Quote hidden}

Why is it not recommended to BSF the PortB pin just
after writing to PortB?  Granted, I'm new to all of
this, so I just don't understand the reasonnig for the
caution (haven't heard this before).

{Quote hidden}

As far as Inner, it actually wasn't supposed to be
reset.  What it does is go from '0' (was cleared
previously), and count down to '0' again (which gives
it - what, about 256 cycles.  If I reset it as above,
it would only count twice.  The goal of the above code
is to decrement Inner for 256 counts as an inner loop.
It's nested within the Outer loop, which I can set to
some number of times (as a repeat).

Thanks,

ATM


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


2001\10\23@095710 by Gerhard Fiedler

flavicon
face
At 05:43 10/23/2001 -0700, Allen Mahurin wrote:
{Quote hidden}

Bit write instructions are so-called "read-modify-write" instructions: they
read the port (or register), modify a bit, write it back. If you do this
immediately after a port write to the same port (or another bit write
instruction), the ports may not yet be at their final voltage (capacities
etc.) This could result in modifying a port that you just changed in the
write operation and didn't intend to change in the bit operation, because
the "read" part of the "read-modify-write" does not yet read what has just
been written, but instead the value before the write -- and the "write"
part then writes this value back instead of the intended one.

This has been discussed quite a bit, you surely can find lengthy threads
about this on the PIClist, and probably an app note or two, too.

ge

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\10\23@135052 by Allen Mahurin

picon face
Cool ... thanks!

ATM

--- Gerhard Fiedler <spamBeGonegfiedlerspamBeGonespamGLOBO.COM.BR> wrote:

{Quote hidden}

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspamTakeThisOuTmitvma.mit.edu


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