PIC Microcontroller does not work

Status
Not open for further replies.

peacezim

Newbie level 4
Joined
Jul 11, 2009
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Germany
Activity points
1,356
Dear All,
I am facing a problem in testing a very simple code with PIC16F73.
I just want to set the PA0 pin high, so that I can see the LED switched ON.
But unfortunately I cannt see this happening in the hardware.
But at the same time I can see the same code in the MPLAB simulator working fine.

I guess it is a hardware problem. I do not know how can I check if the crystal oscillator is working fine. I do not have a CRO. I am using 4MHz crystal with HS mode.

I even tried changing the Chip once. But cudnt help me .

Can any one propose some ideas to test what is wrong in it?

Can anyone provide a working hex file tested on ur PIC, so that I can check it here too?
 

Hi,

It would probably be better if you posted your program code and circuit diagram first.

More likely someone can spot the error from that - a picture of your layout can also help, there are so many things that you can do wrong when you first start - we have all been there !
 

Please try for ADCON1 = 0X06; in order to make the POrt A as a digital port. Please make the port is a common drain port or TTL port. If common drain there is a pull resistor need. The LED is simply a resistor 680 ohm in series with led to ground should be fine....!!! Good luck dude.....

Added after 3 minutes:

Please try for ADCON1 = 0x06; , in order to make the portA as a digital port. And pls double check on datasheet is that a common drain or TTL port. The pull up resistor needed for common drain. The led simply a resistor 680 ohm in series to ground. Good luck dude....
 

A small correction too....I am using 4MHz crystal with XT mode.

Please see the code and the circuit diagram attached.

I had forgot to connect the capacitor in the reset circuit at MCLR. Can this be the reason? What if I directly connect this pin to 5V VCC?

__CONFIG(WDTDIS & XT & UNPROTECT);

void main()
{
ADCON1=0x06;
PORTA=0;
TRISA=0x00;
while(1)
{
RA0=1;
}

}
 

Hi,

Your circuit diagram looks ok although it is more usual to have the Mclr on a 4k7 or 10K resistor - 1K will still work ok though.

Leaving out the Mclre capacitor is no problem although you should preferably always fit a 100nf capacitor across 0 and +5v as close to the pic as possible.

Possible hardware problems, 1K might be too high for the led you have, try say 680R or 470R and check you have the led the correct way round, easy to get it wrong.
To prove you have the right direction use the resistor and led across your 5v psu.

Do not know if you are using a breadboard or soldered stripboard but the crystal and its capacitors should be on very short leads, not 100 mm connector wires.
If you are using an old, dusty breadboard it can often loose the crystals signal with the poor contacts.

Your first post said you were using 4meg in HS mode but according to the datasheet it should be XT.

I'm not into C coding, but your code seems to have got PortA configured ok, you could try portB just to be sure.
Microchip do give free beginners C tutorials with their complier downloads that do things like flash a led - you could check you code against that.

Also search the many tutorials like this https://www.best-microcontroller-projects.com/pic16f84.html


Shout if you are still stuck..
 

The LED is ok with 1k, since I tested it already by giving 5V directly.

I am using a new breadboard. And the leads of Crystal are only of some 1 cmm length.

XT is right, as I mentioned in the second post.

I even tried PortB but the same result.

In addition,
I kept 47K resistor at the /MCLR.
I measured the DC volts on each pin of crystal: OSC1: 0.06V, OSC2: 0V
AC volts on the crystal: 0V or 0.1V
Pull Osc1 to Gnd & pull Osc1 to Vcc : In both cases it is 0V in OSC2
Between RA0 and Gnd: 0.06V
I placed 0.1 uF ceramic on Vcc.
In addition to all these, I also changed the PIC. But the result is the same.
I even changed the position of wiring in the breadboard(It is a new one).
Now I plan to solder on a general purpose PCB and try the same.
 

Hi,

No idea about the reading from the osc pins, even an oscilloscopes load can affect the crysal never mind a voltmeter.

The mclr should be 4.7k , also shown as 4K7, 47K will work but more prone to interference.

Do not have that chip, but wil try and get a hex file over to you shortly, will ask a friend to look at your C code, as I would think that is where your problem is.

Added after 57 minutes:

Hi again

Attached is a .hex file that turns on just PortB, 0 and PortB, 1
 

Hi
If you have a voltmeter , check the voltage at RA0 . If you are getting +5V at that pin , then you need to check the LED and the LED connection. There is no problem with the code. Can you post the hex code that has been generated by your compiler....

And connect a capacitor to the MCLR pin. The datasheet says :
"The behavior of the ESD protection on the MCLR pin
has been altered from previous devices of this family.
Voltages applied to the pin that exceed its specification
can result in both MCLR and excessive current beyond
the device specification during the ESD event. For this
reason, Microchip recommends that the MCLR pin no
longer be tied directly to VDD. The use of an
RC network is suggested"
 

Hi,

I would expect to see 150mVDC or 300mVAC at OSC2.
I would not try an measure OSC1, as the loading will most likely stop the xtal.
I have always used HS mode for 4MHZ XTAL with 15pf caps to GND.
Is the XTAL good?, Do you have a spare?

I also find enabling the power-up timer and Brown-out help remove a lot of problems.

Change:
__CONFIG(WDTDIS & XT & UNPROTECT); to..
__CONFIG(HS & WDTDIS & PWRTEN & BOREN & UNPROTECT);

Do you have the correct IC selected?

Also ask yourself?
Q. Have you ever put more than 5.5V into the circuit in error?

Q. Have you ever reversed the PSU polarity by accident?

If so, the chips most likely dead!.

It always a good idea to add an idiot diode to prevent the common mistake.

If you can not afford the voltage drop, place it across the supply in reverse so it conducts when the power is reversed, AND be SURE to put a small fuse before the diode. 100mA. Also an LED can be added so you know you have not blown the fuse.

Where is the supply voltage coming from, is it a good clean supply?
Be carefully of SMPS, some can create very fast spikes that are invisible to a DVM and most slow scopes, but deadly to PIC's

I find putting a 7805 reg on the PCB / breadboard helps.

My feeling from the info give, is the XTAL is not OSC, or an issue with the Power Up reset.

Note: if you are using a variable Desk PSU, are you setting the voltage then apply the power or winding it up with the output on? This can effect the POR.

Hope this helps.

Please let us know if you have fixed it?

Ian.
 

Hi,

Im not sure if it would work in your situation your problem also is the same as what i have experienced before.

Clear the mcu through supplying High MCLR.
 

Hi Please do not connect the 5v directly to MCLR.
configuration watchdog disable, XT should be ok.
no any capacitor to MCLR is required. What kind of compiler use??? Please use 5v for Vcc. If u can not turn on the LED please try the circuit below, or other pin with your LED circuit.




__CONFIG(WDTDIS & XT & UNPROTECT);

void main()
{
ADCON1=0x06;
PORTA=0;
TRISA=0x00;
while(1)
{
RA0=1;
} 5V
|
} > 1K
<
>
| 100ohm LED
RA0 ---------------/\/\/\----|>|-----------
|
gnd
 
SOME TIMES SOFTWARE PROBLEM ARISES
 

What compiler and which PIC programmer are you using? If you are comfortable in programming in C, you can try mikroC. I am using the same. Sometimes, if you don't select the right options for Oscillator, WDT, and MCLR, you have this kind of problem.

- Raj
https://pic16f628a.blogspot.com
 


I soldered the circuit on a PCB(I was using a breadboard untill now). But no change in the result....
I will check your suggestions.
I will try changing the CONFIG settings as u suggested and let you know the result.
Untill now I have tried with 3 PICs and 2 Oscillators.....I was already using a 7805 regulator, for the full wave rectifier circuit I wired...
I strongly suspect that the programmer TopWin is not correct(even though it shows "Write complete" after programming).
 

peacezim said:
I strongly suspect that the programmer TopWin is not correct(even though it shows "Write complete" after programming).

Have you checked you can read back the programmed data after restarting TOPVIEW and your PCB. Sometimes third party programmer do not verify correctly.

Also some third party programmers do not read the CONFIG bits from the file, or if they do, do not always apply them correctly.

Please try and set the CONFIG bits in TopWin.

I know a lot a people are on a budget, but you can get a PICkit2 with demo board for 22GBP, in the UK that not even a night in the pub(if you can if one that is still in business!) I think that's a real bargain. It completely integrates with MPLAB, has debug, a simple build-in logic analyser and UART Tool. It also will power the target, within limit, so no extra wires, PSU etc.

Next option, is to find a local friend with an other programmer who can help you check you chips out, someone in a local college or business.

Also, you could look a try a different, simple programmer and software from the web.
http://freenet-homepage.de/dl4yhf/winpicpr.html#wxpic
using the very simple COM84 or JDM interfaces. Links within the url above.

Regards
Ian
 

Finally I figured out that its not a problem with the Programmer, and also not an issue with the code.
Either all the 2-3, 16F73-PICs I tried were damaged Or the 2 crystals I tried were not working....I will figure it out and try to send you an update later.

I could program a 16F84A with same programmer, with 20Mhz crystal in HS mode, and it worked fine.......I am happy to see that

So, many thanks to you all...for trying to help me......

Will come to you with new issues later
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…