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.

weird pic LED output behaviour

Status
Not open for further replies.

bbgil

Full Member level 2
Full Member level 2
Joined
Mar 11, 2006
Messages
135
Helped
13
Reputation
26
Reaction score
9
Trophy points
1,298
Activity points
2,321
Hi. maybe someone can explain why my 16F977a is acting weird. this is a simple asm code. just blink 3 led. but the problem is when there are 3 LED, its not blinking the correct delay (500ms). but when only two, it's correct. what give's? do the amount of led and the power supply have effects on the timing cycle? here's the code.

; Configurations
LIST P=16F877a, W=-302
#include <p16f877a.inc>
__CONFIG 0x3D71 ; HS MODE,WDT OFF, BOREN

BANK_0 EQU 0x00
BANK_1 EQU 0x80
BANK_2 EQU 0x100
BANK_3 EQU 0x180

ORG 0x00

; The program starts here
; When the program starts, RAM Bank 0 is "active"

movlw B'11111000' ; prepare data for TRISB

BANKSEL BANK_1 ; "activate" Bank 1
movwf TRISB ; copy W to TRISB

BANKSEL BANK_0 ; "activate" Bank 0

Loop movlw B'00000111' ; prepare data for PORTB
movwf PORTB ; write W to PORTB
;
call Delay_500ms ; call delay subroutine

movlw B'00000000' ; prepare data for PORTB
movwf PORTB ; write W to PORTB
;
call Delay_500ms ; call delay subroutine
goto Loop ; jump back to Loop


; ****** DELAY SUBROUTINES ******

; ****** SUBROUTINE Delay_500ms ******
Delay_500ms
BANKSEL BANK_3
movlw .50
movwf 0x193
LoDe500
call Delay_10ms
BANKSEL BANK_3
decfsz 0x193, F
goto LoDe500
BANKSEL BANK_0
return

; ****** SUBROUTINE Delay_10ms ******
Delay_10ms
BANKSEL BANK_3
movlw 0xff ; outer counter const
movwf 0x191 ; outer counter
LoDel2 movlw 0x40 ; inner counter const
movwf 0x192 ; inner counter
LoDel1 decfsz 0x192,F
goto LoDel1

decfsz 0x191,F
goto LoDel2
BANKSEL BANK_0
return

; ****** END OF SUBROUTINES ******

END
 

Would you care to do this tests also?:

Test it with one LED.

Simulate the whole thing with MPSIM (replace the delays, if any, by single lines).

Is it possible to format your code to post here? I don't feel akin to read such a mess.
 

tried with only one LED. work's fine. only when i add the other two, the timing fails. with 84a, no problem, so what is it with 877a that make's it different? shouldn't be affected, right?
 

Just a couple of thoughts;

Firstly, are you driving the led directly from the PIC or is it through a resistor to limit current ? if you are not using a resistor, or too low a value one then you may be creating more than 25mA per pin load and dropping the 877 below its low voltage threshold and causing it to either reset or to enter low power oscillator mode, perhaps the bit configuration flags are set differently for each chip you have and so one has brown out reset and one not?

for the resistor value you can use the following R=V/I (ohms law) for the resistor value. Redone for LED's as R=(Vs-Vf)/If where Vs= input voltage (i.e 5v) minus Forward voltage of LED (i.e) 3.4v = 1.6v divide by If=Amp rating of LED (i.e 20mA) = 0.020 giving a value in this example case of 1.6/0.02 = 80 Ohms, pick the closest value resistor above that value i.e 100R and use that.

Also check the voltage coming into the PIC and make sure thats above any brown out level while all 3 LED's are on, can you see any dimming of the LED's as more are turned on ?

I realise that you may already know these basic steps so please excuse me if that is the case, but it always pays to check the basics first.

It "COULD" be a dodgy PIC, heck I've seen it before but its pretty rare, I would favour an under volt situation if its only with all 3, also check using 3 pins not next to one another i.e on different ports A B C etc
 

    bbgil

    Points: 2
    Helpful Answer Positive Rating
hello

What Programmer you are using to program the chip?

Also check your power supply.



Sam
 

Tnx a bunch guys for all suggestions. its working nicely now. its the loading effect of the LED's. once i put s 220 ohm resistor, its fine. tried also some other codes, working nicely as well. more power to EDA.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top