Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC 16F870 / glitches/artifacts on PORTA,PORTB and PORTC

Status
Not open for further replies.

ripkars

Junior Member level 1
Joined
Feb 23, 2007
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,422
porta portb portc

Hi all,
I'm encountering glitching/artifact effects on the output latches associated to PORTA, PORTB and PORTC registers of a PIC 16F870.
The code which writes to those ports is:

Code:
SCL_UP          EQU     H'0020'
SCL_DN          EQU     H'0021'
SDA_ORG         EQU     H'0022'
TBYTE           EQU     H'0023'
LAMP1           EQU     H'0024'
LAMP2           EQU H'0025'
T_LAMP1         EQU H'0026'
T_LAMP2         EQU H'0027'
TEMPB           EQU H'0028'
TEMPC           EQU H'0029'

        ORG 00H
        ;PORTA -> LEDS + BUTTON
        ;PORTB -> DATA (SDA)
        ;PORTC -> CLOCK (SCK)

        BCF         STATUS,7       ;disable all interrupts

        BSF         STATUS,5       ;Switch to Bank 1
        MOVLW   b'00000111'     ;set Porta pins to digital
        MOVWF   ADCON1        ;i/o (instead of analogical)
        MOVLW   b'00000001'     ;Set the Port A pins
        MOVWF   TRISA            ;to output (except RA0).
        BSF         STATUS,5      ;Switch to Bank 1 again (NOT NECESSARY?)
        MOVLW   b'00000000'     ;Set Port B to output
        MOVWF   TRISB            ;
        BSF         STATUS,5      ;Switch to Bank 1 again (NOT NECESSARY?)
        MOVLW   b'00000000'     ;Set Port C to output
        MOVWF   TRISC            ;
        BCF         STATUS,5      ;switch back to Bank 0

        MOVLW   d'5'
        MOVWF   SCL_UP
        MOVLW   d'5'
        MOVWF   SCL_DN
        MOVLW   d'150'
        MOVWF   LAMP1
        MOVLW   d'150'
        MOVWF   LAMP2
        MOVF      LAMP1,0       
        MOVWF   T_LAMP1
        MOVF       LAMP2,0
        MOVWF   T_LAMP2
        MOVLW   B'00000000'     ;initialize address register
        MOVWF   TBYTE
        CLRW

;Main cycle
RESTART
                BSF             PORTA,2                 ;turn on RA2 (Led GREEN)
                CALL    GENERIC_DELAY
                BCF             PORTA,2                 ;turn off RA2
                BTFSS   PORTA,0                       ;if RA0 is UP -> begin
                        GOTO    RESTART
                                BCF             PORTA,2
                                ;GOTO   (OTHER_CODE_NOT_POSTED_BUT_FOR_SURE_NOT_IMPORTANT)

;Loop Blinking Led
GENERIC_DELAY
                                CLRW
DLY_GEN                 DECFSZ  LAMP1,1
                                GOTO    DLY_GEN
                                DECFSZ  LAMP2,1
                                GOTO    DLY_GEN
                                ;RICARICO LAMP1 E LAMP2
                                MOVF    T_LAMP1,0
                                MOVWF   LAMP1
                                MOVF    T_LAMP2,0
                                MOVWF   LAMP2
                                RETURN

On RA0 there is a switch that selects the start input (0V / +5V),
On RA2 there's a led
The problem is: I turn on the circuit and set the switch to +5V and it starts blinking (as it should) but at the same time it turns on, without an apparent reason, also led on RA3 or RA1 (which insetad stays turned on fixed, it does not blink).
Similar problems happened putting other leds on PORTB and PORTC (and obviously changing the circuit/software.
I add that:
1) the circuit is built over a breadboard
2) the leds are linked in the following manner: PIN---ANODE....CATODE---RESISTOR(1Kohm<R<3Kohm)---GND
3) the oscillator is a RC one(10kohm/100pf)

Thanks to everyone who will partecipate to this discussion,
Riccardo
(P.S.: please excuse my bad english...)
 

The led IS BLINKING but the time that remains in the off state takes about 2 or 3 instructions time, and the on state takes what the generic delay says.
you should use a simulator so you can find bugs like this one easily.

regards.
 

narcizzo u were right: after burning the pic with this code
Code:
RESTART	
		BSF		PORTA,2			;accendo RA2 (Led VERDE)
		CALL	GENERIC_DELAY
		BCF		PORTA,2			;spengo RA2
		CALL	GENERIC_DELAY
		BTFSS	PORTA,0			;se RA0 è UP -> Cominicia
			GOTO	RESTART
				BCF		PORTA,2
				GOTO	MAIN_LOOP
instead of this one
Code:
RESTART	
		BSF		PORTA,2			;accendo RA2 (Led VERDE)
		CALL	GENERIC_DELAY
		BCF		PORTA,2			;spengo RA2
		BTFSS	PORTA,0			;se RA0 è UP -> Cominicia
			GOTO	RESTART
				BCF		PORTA,2
				GOTO	MAIN_LOOP
which u correctly told me that was wrong, the led begins to blink correctly.
However, I continously experience glitches on all PORTs as said in the previous post... any idea about the reason? May it be some strange capacitance (side-)effect of the breadboard??
Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top