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.

Frequency

Status
Not open for further replies.

YAN-1

New Member
Hi. How do I know if my 16F877A is a 20 MHz and not a 4 MHz one (I bought a 20 MHz PIC but I think the seller gave me a 4 MHz one instead)? I bought a 20 MHz crystal and connected it to the PIC. When i write a certain delay in my program and simulate it, the stop watch feature in MPLAB shows that the delay is very short, but when I actually place the PIC in-circuit, it is extremely longer than that indicated by the simulation. Where could the problem be?
 
Is there a "20" or "4" marked on the chip?

You can get MPLAB to simulate any speed; it's in the options somewhere. If you have it set to 20MHz one instruction will take 0.2us. 4MHz will take 1.0us per instruction.

Microchip doesn't make separate versions. The ones that pass quality control for 20MHz are sold as such. The ones that don't are sold as 4MHz...even though they may well work at 20MHz.

Post your delay code and we'll see if there's something causing your problem.

Mike
 
YAN-1 said:
Hi. How do I know if my 16F877A is a 20 MHz and not a 4 MHz one (I bought a 20 MHz PIC but I think the seller gave me a 4 MHz one instead)? I bought a 20 MHz crystal and connected it to the PIC. When i write a certain delay in my program and simulate it, the stop watch feature in MPLAB shows that the delay is very short, but when I actually place the PIC in-circuit, it is extremely longer than that indicated by the simulation. Where could the problem be?

The 16F877A will probably be stamped with it's speed anyway, but even if it isn't, 4MHz PIC's work fine at 20MHz (I've NEVER heard of one which didn't!).

In any case, even if it didn't work, it wouldn't run at a lower frequency, it just wouldn't run at all.

How is your crystal connected, and what value capacitors are you using?, and what are your fuses set to (it should be HS for 20MHz).
 
Well my capacitors are 12 pf and the crystal is connected just like in the data sheets (across OSC1 and OSC2 and with the 2 capacitors connected to ground). But I was setting the fuse to XT instead of HS. Do you think this is why?
 
YAN-1 said:
Well my capacitors are 12 pf and the crystal is connected just like in the data sheets (across OSC1 and OSC2 and with the 2 capacitors connected to ground). But I was setting the fuse to XT instead of HS. Do you think this is why?

No, I've found it doesn't make a great deal of difference, I've sometimes set it wrong accidently, and it's always worked fine - but there's no guarantee that it will!. But if it doesn't work, it won't oscillate at all, not just run at the wrong frequency.

I would suggest you've probably got the MPLAB simulation wrong?, I would also suggest that you use the delay code generator on the PICList to generate your delay code - there's no point doing it yourself 8)
 
Hmm. Well tomorrow morning I will go back to my bench (starting around 7 hours from now) and will be working there all day long. I will try to do my delay that way and will post my code if I still face trouble. But some weird things were happening today! I mean the PIC seemed to operate even when I removed the capacitors on the crystal! Anyways, I will change the configuration to HS tomorrow and try to solve things. I would appreciate it if you could help me out during the day if I post another question or something while I am working. Thanks.
 
take those stupid capacitors out, i don't get why everybody uses them, i don't and I always get the circuit to do what i want
 
Well the PIC only seems to be working when it is configured for XT, not HS (20 MHz crystal)?!
 
tom2000 said:
take those stupid capacitors out, i don't get why everybody uses them, i don't and I always get the circuit to do what i want

You SHOULD use the capacitors, check the actual operation of the oscillator circuit (MicroChip provide details in some datasheets), and they are an essential part of the oscillators operation. If you leave them out, you 'may' be lucky and have enough stray capacitance for it to oscillate, particularly if your layout is poor.

But there's NO advantage to leaving them out, and to do so is extremely bad practice!.

YAN-!: How are you building the circuit?, is it on a breadboard?.
 
Yes it is on a bread board. I am testing several programs but they only work if the fuse is set to XT, not HS. And there is something wrong (probably because I am using a bread board) because I have to keep pressing on the wire that connects the crystal to the OSC1 input with my hand in order for the program to go on executing! But that's the least of my problems at the moment. I still don't get the delay I want or the one indicated by the simulation stop watch.
 
YAN-1 said:
Yes it is on a bread board. I am testing several programs but they only work if the fuse is set to XT, not HS. And there is something wrong (probably because I am using a bread board) because I have to keep pressing on the wire that connects the crystal to the OSC1 input with my hand in order for the program to go on executing! But that's the least of my problems at the moment. I still don't get the delay I want or the one indicated by the simulation stop watch.

A breadboard isn't a good thing to build it on!, they are only really suitable for very low frequency use, at 20MHz the large stray capacitances of a breadboard may well cause problems. It's also very important to keep the leads to the crystal and capacitors as SHORT as possible, a breadboard makes this very difficult - if you check the veroboard layout on my 876 and 877 tutorial boards you will see how short I keep them! **broken link removed** and **broken link removed**.

I would suggest you build a processor board similar to my tutorial one, and if you want to use a breadboard then fit the processor board with suitable SIL plugs which can plug directly into the breadboard. Notice the existing 876 board has all the sockets at one side, which would make it very simple.
 
Yan,

May I ask if you have disabled LVP (Low Voltage Programming) in your config' settings? The symptom you describe is quite common when LVP is enabled and the PGM pin is left 'floating'...

Good luck with your project... Regards, Mike
 
Oh yes I did. I un-checked all the fuses in the IC-Prog before downloading the program. But still, there is something wrong because I have to keep touching the crystal with my hand in order for the program to run! And it only works if the config. is XT and not HS even though it is a 20MHz-device. I still don't know why. Thank you for your concern. I appreciate it.
 
Can we see a picture of your setup? Perhaps there's something there that you're doing but not telling us or don't realize.

I have used PICs on breadboards all the time with never a problem. I haven't run them at 20MHz, but up to 10MHz.

And we still don't know that there is a problem. When you say that it's not working, do you mean it's not working the way it should or that the PIC isn't operating at all? Turning on LEDs at different parts in the code would tell you how far your program is getting.

Mike
 
Well.. when I said it doesn't work unless you press the wire with your hand or press the crystal, I meant that the PIC doesn't receive the clock signal unless that is done. When I do, the program runs nicely and the LEDs flash like they are supposed to. But when I let go, the crystal is disconnected for some reason and the program stops at the instruction it was executing (as if you removed the crystal in the middle of the operation), and so the LEDs remain latched at whatever value they reached at that point. When I touch the crsytal again, the program goes on again and so on! It's really weird and frustrating :cry:
And I don't think I can use solder boards at the moment because I need to test several circuits before I attempt to weld one of them permanently. So bread boards are all I can use for now.
 
YAN-1 said:
Well.. when I said it doesn't work unless you press the wire with your hand or press the crystal, I meant that the PIC doesn't receive the clock signal unless that is done. When I do, the program runs nicely and the LEDs flash like they are supposed to. But when I let go, the crystal is disconnected for some reason and the program stops at the instruction it was executing (as if you removed the crystal in the middle of the operation), and so the LEDs remain latched at whatever value they reached at that point. When I touch the crsytal again, the program goes on again and so on! It's really weird and frustrating :cry:
And I don't think I can use solder boards at the moment because I need to test several circuits before I attempt to weld one of them permanently. So bread boards are all I can use for now.

As already suggested, can you post a picture of your layout?, it sounds to me like your problems may stem from poor layout of the oscillator circuit. Breadboards probably aren't very good at 20MHz, and I suspect you probably aren't using the shortest possible wires?.
 
Well actually I don't have any means of taking a picture right now. But it just worked. I replaced the crystal with a new one and everything is ok. Turns out these things can mal-function easily. Thank you for your help.
 
Nigel Goodwin said:
tom2000 said:
take those stupid capacitors out, i don't get why everybody uses them, i don't and I always get the circuit to do what i want

You SHOULD use the capacitors, check the actual operation of the oscillator circuit (MicroChip provide details in some datasheets), and they are an essential part of the oscillators operation. If you leave them out, you 'may' be lucky and have enough stray capacitance for it to oscillate, particularly if your layout is poor.

may be lucky ?

i must be bulid 20 or so circuits, never put those stupid capacitors and it ALWAYS oscillated

those caps are waste of parts and space

ps. give me a fken break, i am getting clean oscillation with 25MHZ crystal on my bread board with my 16f84a's, no caps no bs

and the leads on the crystal must be around inch long
 
tom2000 said:
may be lucky ?

i must be bulid 20 or so circuits, never put those stupid capacitors and it ALWAYS oscillated

those caps are waste of parts and space

ps. give me a fken break, i am getting clean oscillation with 25MHZ crystal on my bread board with my 16f84a's, no caps no bs

and the leads on the crystal must be around inch long

If you're building it on breadboard then the stray capacitances are greater then the values required for the capacitors - so it may well work without them (simply because breadboards are rubbish!). But that doesn't mean you can leave them out in proper construction!, your breadboard layout includes them as part of the breadboard itself.

But they are an essential part of the oscillator circuit, without capacitance (either installed or stray) it won't work! - and you shouldn't recommend people to follow such faulty advice!. It's just like capacitors on 78xx voltage regulators, it 'may' apparently work without them, but under certain circumstances it WILL be unstable - so just like oscillator circuits, it's vitally important that you fit them!.
 
Status
Not open for further replies.

Latest threads

Back
Top