Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Newbie, please help with power problem

Status
Not open for further replies.

techieguy

New Member
Hi I'm fairly new to microcontroller programming but am picking things up relatively quickly. Unfortunately I haven't been able to figure this problem out regarding the power source I use to run the programmed PIC16F84A. I use a serial programmer to program the pic offline before putting it into my breadboard circuit.

For right now I'm just testing outputs using LED's while I'm learning programming. If I connect up 3 AA batteries (~3.5V) in series to power the pic, the program goes through the loops without any problem and starts over at the end like it's supposed to. However adding a 4th AA battery (~4.7V) the program will start over halfway through.

I'm really stumped on this. Please let me know if you think of anything that could be causing this problem. BTW I don't fully understand the WDT but have found clearing it in the program makes things run better for me.

Thanks in advance for your help
Here's the little program I'm running:

;***Constants
STATUS equ 0x03
TRISB equ 0x86
PORTB equ 0x06
COUNT1 equ 0x08

;***Port Setup
bsf STATUS,5 ;Bank1
movlw 0x00
movwf TRISB ;PortB all outputs
bcf STATUS,5 ;Bank0

;***Start of Program
Start clrwdt
bcf STATUS,0 ;Clear Carry Flag
movlw 0x01
movwf PORTB
call Delay

;***LED Sequence
CountUp clrwdt
btfsc PORTB,7 ;Flash LED's once seq is done
goto Blink1
rlf PORTB,1
call Delay
goto CountUp

;***Flash LEDs
Blink1 clrwdt
movlw 0x00 ;Turn Off LEDs
movwf PORTB
call Delay
movlw 0xFF ;Program Start over at this point
movwf PORTB ;with 4 batteries but contines fine if 3
call Delay
movlw 0x00 ;Turn Off LEDs
movwf PORTB
call Delay
movlw 0xFF ;Turn On LEDs
movwf PORTB
call Delay
;
;More flashing
;
;

;***I have a little more sequence stuff after this but it never runs.
;***unless i remove the 4th AA battery.
;
goto Start
 
Nothing springs to mind, but you're making life difficult for yourself (and for us).

You should use the MicroChip include files, and NOT define your own equates for them - it's only going to cause errors, and why not just use the official ones?.

If you check my tutorials ALL of them use the official include file, but it's amazing how many examples on the net (particularly for the long obselete 16F84) use them?.

In the same vein, you write:

rlf PORTB,1

Again, this shouldn't be used - it just causes confusion, you should use the definitions in the MicroChip include file where it becomes:

rlf PORTB, F

Or if using W instead of a file

rlf PORTB, W

This applies to various other numbers you use as well, where you should use the MicroChip defines, which makes everything more clear.

The section you've posted also doesn't show the fuse settings, this should be included in the source code, so we don't have any clue how you might be setting them.

As for your power supply, it's best to use 5V - use a 9V battery and a 5V regulator to power it, and see what happens then - don't forget the two capacitors round the regulator, as close as possible to it!.
 
Pardon me but wouldn't 3 AA batteries = 4.5v and 4 AA batteries = 6.0v?

Could 6.0v VDD be a problem on the 'F84?

Regards, Mike
 
Thanks for your replies.

I had some used AA batteries laying around and decided to use those which explains why it's not 4.5V(3AA), 6V(4AA).

And this morning I rewrote a simple program using the include file as you suggested.

I made RB0 (0x01) LED flash 3 times
then made RB0,1,2 (0x07) flash 3 times
then tried making all PORTB (0xFF) flash 3 times
*at which point all LED's turned on 1 time then the program restarted where RB0 started flashing 3 times again. And yup, using 3AA it worked just fine (all LEDs flashed 3 times).

I would gladly include any "fuse settings" but I am new to programming and do not know what those are.
 
You are making your life miserable by enabling the WDT during program debugging phase. The WDT period could be as short as 18ms when not being setup correctly and this might reset your PIC while you are inside a Loop and before you can have a chance to CLRWDT it. It use RC oscillators so its timing is dependant on supply voltage and that would explains why higher voltage shorten the onset of WDT operating.

So, disable the WDT in your config bit and test your problem. If your happy with its running, then you can add the WDT to the code.

Or, you can add the CLRWDT as the first instruction of your delay subroutine and see if it works.
 
Fixed

I thought the watchdog timer was the problem too so I was using clrwdt in various places. That was until I found out how to write the config to disable the WDT lol. The problem still occurred even with the WDT disabled.

It turned out to be the /MCLR pin was causing the resets. I had it connected directly to the ~5V and when I set all the LEDs for PORTB on, I guess the voltage/current on /MCLR wasnt enough and therefore caused the reset. I put a 100ohm resistor between /MCLR and 5V and all seems to be working fine now.
 
I'm guessing?, but from what you said about using flat batteries, that you DON'T have a good sized electrolytic across the batteries either?.

You're asking for trouble using duff batteries anyway, but it's VITAL to have an electrolytic across them.
 
I wonder if the 'flat' or 'duff' batteries are part of the problem?

Have you considered building a power supply for your project board? Use one of those old wall-warts, you know, down there in that bottom work bench drawer (grin)... Use a decent size electrolytic and a 0.1uf disc on the input of a 7805 or 78L05 regulator and another 0.1uf disc on the output side and you'll be in good shape for all those wonderful and exciting experiments that lay ahead of you...

Regards, Mike
 
I wonder if the 'flat' or 'duff' batteries are part of the problem?

Yeah, a sloppy setup is part of the problem. I would advice you (@techieguy) to clean it up first before asking for further help. It would save us all the grief.
 
Dont even think about exceeding 5V for digital circuits, especially when dealing with larger scale integrated circuits like microcontrollers. The only exception is when programming it, and only when the manual permits it.
 
mstechca said:
Dont even think about exceeding 5V for digital circuits, especially when dealing with larger scale integrated circuits like microcontrollers. The only exception is when programming it, and only when the manual permits it.

I'd be even more careful maintaining the supply voltage within the specified limits when programming the chip. I once had a design that uses a surface mounted PIC. Due to an incorrectly wound transformer, a multiple rail switch mode power supply circuit supplied 5.5V to the PIC. The PIC would verify fail when programmed in circuit (ICSP) when using this power supply. However, when supplied with a clean 4.75V-5.25V supply, the PIC would program verify OK. After programming, the PIC ran fine at 5.5V.
 
motion said:
However, when supplied with a clean 4.75V-5.25V supply, the PIC would program verify OK. After programming, the PIC ran fine at 5.5V.

Interestingly enough, the requirement for a 'production programmer' is to work at different supply voltages - sounds like that could be why?.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top