PDA

View Full Version : What does this MCLR instruction mean?



bartman
- 11th November 2004, 05:21
I am going over the data sheet for a PIC12F629 controller again and see this note:

<b>When MCLR is asserted in INTOSC or RC mode, the internal clock oscillator is disabled.</b>

Does this mean that if I set up the MCLR to have voltage at the pin instead of having it get voltage internally that the chip has no internal clock at all to operate on? I'd have to have an external oscillator to make things work?

I don't know yet if I have to have the MCLR pin powered for this project. I think there must be another internal clock that runs regardless to run the software and this probably isn't a concern?

I also am still struggling as to how I program these extra special feature bits. The data sheet says:

<b>Address 2007h is beyond the user program memory space. It belongs to the special configuration memory space (2000h - 3FFFh), which can be accessed only during programming. See PIC12F629/675 Programming Specification for more information.</b>

I don't find a "Programming Specification" section in the datasheet. I think I need to program at least some of the bits if I want 5 outputs and possibly the MCLR pin available. I do see in the programmer itself I can toggle all these features when I select the chip so I suppose this does the same thing as writing them in the code myself?

Thanks.

Bart

bartman
- 13th November 2004, 22:47
Well, I figured that the worst that could happen is that I would destory a $2.00 chip so I tried my test program with both MCLR on and MCLR off.

I found that with it off I didn't need the 4.7K resistor on pin 4 which I suspected. When it was turned on I did need the resistor so the setting does what it is supposed to do.

Even with this comment from the data sheet that the internal clock is turned off when MCLR=ON it seems to make no difference as in the program still runs. So, in actual use what are the differences? Do I leave off the resistor for my final project or not? What good or bad results do I get with either way?

Thanks.

Bart

Melanie
- 13th November 2004, 23:46
MCLR is the Master Clear or Reset. Most PIC's have them, although not all PICs have the ability to handle MCLR internally.

For example, the 16F84, 16F872, 16F877 etc etc all need you to handle MCLR externally, whilst newer chips like the 16F628, the 12F675 etc have the additional ability to handle internally and that pin can be otherwise assigned for I/O (although usually INPUT ONLY).

There are times when you have poor supply lines, the PIC cannot Power-Up cleanly. Or there are circumstances when the PIC must power-up AFTER all kinds of other circuits that need to power-up first. In those instances, Power-On must be delayed (so that the external PSU or hardware has time to settle), by holding MCLR down, you in effect 'freeze' the PIC, only releasing it when MCLR reaches Vdd.

If your PSU is well designed, you can dispose of your Resistor and tie MCLR directly to Vdd (or have MCLR handled internally by the PIC if it is capable of doing so, and free yourself another pin for use elewhere). If your PSU is a little shitty, you might need that Resistor and also a Capacitor from that pin down to Vss. The size of the Capacitor will determine the ON delay. Note that some newer PIC's also have programmable On-Delay.

So, in effect, the kind of MCLR you employ is determined solely by your application and it's environment. There is no right or wrong path here. Your experience as an engineer will dictate what should be done under what circumstances.

1. Do I need both a Resistor and a Capacitor, and what size of Cap?
2. Can I get away with just a Resistor?
3. Can I tie MCLR straight to Vdd?
4. Can I use Internal MCLR (MCLR=OFF) and gain an extra I/O pin?


MCLR however must never be used to 'FREEZE' a program and expect it to continue from where it left off on release. MCLR changes internal registers, and when the PIC restarts, it's immediate operating environment will have changed. The Datasheet tells you which registers and conditions are affected.

Melanie

bartman
- 14th November 2004, 01:48
Cool. I'll have to determine that. My gut feeling is that this thing will be working outside so there might be little power issues. For the cost of a resistor no big deal. I don't need that other input line anyway on that pin.

I'd still like to know what this statement is referring to since the clock seemed to work (the program ran) regardless of MCLR=ON. Are they referring to a clock output not working in this mode?

<b>When MCLR is asserted in INTOSC or RC mode, the internal clock oscillator is disabled.</b>

Thanks.

Bart

Melanie
- 14th November 2004, 14:44
If you truely had MCLR ON and had this pin grounded, your PIC will not have run.

That statement means exactly what it says. When you're using the internal oscillator in either 4MHz free-running mode, or externally timed with an RC combination, then this oscillator stops when you have external MCLR and that pin is asserted (ie goes LOW since it's NOT-MCLR - as there's a line above it).

bartman
- 14th November 2004, 19:02
In the programmer I checked MCLR as "ON". At least I assume I did since a checkbox when checked usually means "ON" not off.

I also chose the internal clock.

I put it on the breadboard with +5v through 4.7K resistor to the MCLR pin and everything worked.

The way I read that statement it means that if MCLR=ON then the internal clock is off. Without a clock nothing would run so is there another type of clock that runs the program?

Just to experiment I tried programming the chip with MCLR=OFF and that also worked (didn't need the resistor on power on that pin - I could actually let it float for the experiment). If I had it "ON" and didn't give it power the program wouldn't run so I think I understand the on/off part of it. Clock issue is still foggy.

Bart

Melanie
- 14th November 2004, 20:21
MCLR=ON means you need to pull MCLR up to Vdd yourself. Your PIC will STOP if you Grounded this pin (regardless what oscillator is used). It should NOT be left floating in this instance. If you were using an Xtal or Resonator as the master clock source, then that oscillator does NOT stop when you ground MCLR, however the PIC is nevertheless prohibited from running.

MCLR=OFF means that MCLR is handled INTERNALLY and that pin can be used for I/O (Input actually). Whatever you do to the pin in this instance will have no bearing on the PIC running or not. It will be just another INPUT pin. You could leave it floating if it was unused.

bartman
- 14th November 2004, 21:08
So what "clock" is working with MCLR=ON? I am not using anything external for a clock. Something must be ticking right? There would be no way of making things work without one. Where does the chip get its timing if there are no external clocks and the internal one is disabled?

Bart

mister_e
- 15th November 2004, 04:15
>Where does the chip get its timing if there are no external clocks and the internal one is disabled?

nowhere... if it's working, let me know how you do that!!! Or maybe you programmer don't set fuses correctly or some aliens do the job for you!!!

>So what "clock" is working with MCLR=ON?

depending of you setting INTOSC, RC, XT,HS.... As already said... MCLR is only Master Clear, acting as an RESET.

regards

bartman
- 15th November 2004, 04:25
Well, like I said, the data sheet on this 12F629 says <b>When MCLR is asserted in INTOSC or RC mode, the internal clock oscillator is disabled.</b>

Perhaps the question is, what does "asserted" mean in this case? To me, it means that if you use MCLR=ON then it disables those two clocks. If it means anything else then enlighten me please!

I put MCLR=ON in the programmer. I am certain it programs it correctly otherwise that issues would have come up long before now with their programmer.

Here were my tests:

MCLR=NO / OSC=ON : Everything worked fine with nothing on the MCLR pin

MCLR=YES / OSC=ON: Everything worked fine so long as I had 5v on the MCLR pin. If I removed power to that pin everything stopped.

So, there is a clock ticking somewhere. How does it all work?

Bart

mister_e
- 15th November 2004, 05:02
In Clear it means that if you set:

MCLR=ON > you must have an external resistor on this pin and you cannot use this pin as an i/o

MCLR=Internal >you don't need any external resistor on this pin an you can use this pin as an i/o... usually Input.

for the blabla in the datasheet... it means to me that when MCLR=ON, if you pull down ths pin to ground, the internal or external oscillator will be disable. This is why your program will stop or not boot.

bartman
- 15th November 2004, 05:36
Then I have to say that the wording in this case is not the best it can be, but your explaination explains the experiment perfectly.

Now, in the same section it says <b>Address 2007h is beyond the user program memory space. It belongs to the special configuration memory space (2000h - 3FFFh), which can be accessed only during programming.</b>

This is in regard to the <b>bandgap</b> and <b>oscillator calibration</b>. These settings have to be saved before programming or they, apparently, will be lost and the calibration will be all out of whack.

When I read the blank chip there were no values in any of these locations (I couldn't even see them) and when I tried to program it told me that it didn't find any "oscillator calibration" and wanted to know if I wanted to use the value in 3FFFh. I said yes since no just stops the programming.

So am I to assume that if was looking for some kind of oscillator routine in my progam to calibrate and when it didn't find it it defaulted to this "saved" address values? It would seem that way, but then I can erase the chip and program it again and it still seems to find that value.

Just thinking outloud. Is the programmer preventing me from seeing and/or messing around in those addresses so my calibration values are all still intact?

Bart

mister_e
- 15th November 2004, 06:04
well as i know it depend of your programmer. I use PicStart for programming PIC and i know he doesn't change/erase any value of OSCCAL. what i suggest you, before the first time you want to program a new PIC (12cXXX,12Fxxx) read value and write it on you PIC (bottom/top).

look a this thread

http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=832&highlight=OSCCAL

bartman
- 19th November 2004, 16:36
I have been using IC-Prog to play around. I'm not too worried about this experimental stage. I'd still like to be able to figure out for sure what it is, or isn't, doing with the values in the event that someday I need proper calibration.

Bart

bartman
- 26th November 2004, 06:01
http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=832&highlight=OSCCAL

This thread indicates to have MCLR=off if using the internal oscillator and it doesn't give an explaination of why, but that contradicts what has been said here that is doesn't matter.

So, while things work I have no understand of why they work so in the future I may have a problem and not know why I'm having it.

So, it still boils down to this. Why does the datasheet for the 12F629 say the oscillator is disabled when MCLR is asserted? If it is disabled then NOTHING should work if I apply 5v to that MCLR pin and yet it works.

What clock is ticking away if everything is disabled?

I feel like I am going in circles with this trying to see an invisible answer.

Bart

Melanie
- 29th November 2004, 19:00
Note that MCLR has a LINE ABOVE IT.

This means it's NOT MCLR.

This means that ASSERTED is when you GROUND (0v) the Pin.

This is only valid if MCLR=ON in your config word.

bartman
- 30th November 2004, 01:32
Good.

Then there IS a clock running if it MCLR=ON and I'm putting 5v to that pin AND using the internal oscillator. That explains why the thing quits when I pull off the power to that pin.

Three questions down, 100,997 left to go...

Thanks.

Bart