Problems with the PIC18F25K22

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Post by Aresby » Wed Apr 04, 2012 6:55 pm

Senacharim wrote:Every PIC I've ever worked with has within it an internal ~31kHz oscillator which it defaults to. This is the same one the internal Timer registers are clocked from by default. In the event of external osc failure, it also defaults to this.

You can test this--write a program which toggles the on/off of an LED every, say, 1 millisecond. Then, ground out the external oscillator (I use thru-hole, so touching the pins with one's finger does it for me...) and watch the blink speed of the LED slow way down, but not actually stop.
Perhaps this is what happened to me? My program did not run (apparently) but maybe it was running several hundred times slower than it should have and appeared "hung" (just like I said in my article). I shall test it and update, hopefully over the Easter break.
Perhaps one should also note the difference between Big Endian and Little Endian bit arrangements... or not. Not sure for a beginner article.
Mmm, maybe not then. As I said, this is for the beginner (like me). I don't understand the difference or the names - yet. I think I'll leave this out unless it is particularly pertinent to clocking the chip. But it's given me something else to look up!

Many, many thanks for looking at the article and your feedback. I feel I have learned a lot over the last few weeks, not least from the excellent support I've received from forum members.

I've just ordered some Tap-28 development PCBs for my next project (all the way from the States, so things are progressing).
Aresby
Swordfish & PIC Newbie

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Post by Aresby » Wed Apr 04, 2012 7:00 pm

Senacharim wrote:...getting the PLL to work is finicky. It must be done just right, and if it doesn't go then you'll be left with your default just clock, rather than your desired 4x clock.

When using PLL, the SCS<1:0> bits (System Clock Select) in the OSCCON must both be set to zero.
I shall re-read up on this and make the necessary changes when I have grasped the nuances of what you're telling me.

As it happened I only realised I wasn't running at full speed by checking the CLOCK/4 output on pin 6. And either my oscilloscope is rubbish or the clock signal (shape) is rubbish at that pin too (it's supposed to be a nice square wave, and at lower speeds it is, but at higher speeds it's well malformed!)

But it did kick in to full speed without issue so I will re-read for the zillionth time those pages of the Data Sheet, experiment and make the necessary changes.

So much to learn, so little time.
Aresby
Swordfish & PIC Newbie

User avatar
Senacharim
Posts: 139
Joined: Tue Aug 10, 2010 5:19 pm
Location: Ventura, CA

Post by Senacharim » Wed Apr 04, 2012 7:02 pm

That might only be the case when relying on the internal oscillator (I'm using my brain for the info source at the moment--it's not always 100% reliable)...

Anyhow, best of luck. Thanks for contributing.
Surviving Member
Bermuda Triangle Battalion
from 2026 to 1992

Voted "Most likely to time travel"--Class of 2024.

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Post by Aresby » Wed Apr 04, 2012 7:03 pm

David Barker wrote:Many thanks for the contribution to the WIKI - it's nice to see someone learning and sharing with others...
No problem David, my pleasure.

It's my way of giving back to others (hopefully), having received help right here in this forum myself.

And it ensures that I have learned enough to be confident enough to teach others and get my knowledge verified. We're all beginners once. :)

Definitely a win-win situation for everyone, IMHO.
Aresby
Swordfish & PIC Newbie

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Post by Aresby » Wed Apr 04, 2012 7:05 pm

Senacharim wrote:That might only be the case when relying on the internal oscillator
You mean the poor shape of the clock output?

Well, the crystal certainly delivers a nice clean square wave at 16MHz that's for sure.

I suspect it's a limitation of the silicon.
Aresby
Swordfish & PIC Newbie

User avatar
Senacharim
Posts: 139
Joined: Tue Aug 10, 2010 5:19 pm
Location: Ventura, CA

Post by Senacharim » Wed Apr 04, 2012 7:34 pm

Meant the PLL SCS bits thing.
Surviving Member
Bermuda Triangle Battalion
from 2026 to 1992

Voted "Most likely to time travel"--Class of 2024.

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Post by Aresby » Wed Apr 04, 2012 7:37 pm

I can test for that then (ie whether PLL is picky only on INT clock).

I'll run a test with both internal and external clocks and PLL on/off (this could even be done programmatically, I guess).

Seems to me that my article has generated a lot of work for me to do! Live and learn...
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Wed Apr 04, 2012 8:50 pm

16MHz is pushing the speed limit at which the IO pins can operate. A 16MHz clock would be ~62ns period, so that's 31ns high/31ns low. The slew-rate on the pins is almost half that time, so the output tends to be pretty rounded.

It's true of pretty much all the pins, so it's not just a PLL related thing.

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Post by Aresby » Thu Apr 05, 2012 6:19 am

Jerry Messina wrote:16MHz is pushing the speed limit at which the IO pins can operate... so the output tends to be pretty rounded.
Thank goodness it's the signal and not my oscilloscope, although I had suspected this as my' scope is supposedly good for 100Mhz.

I'd hate to drive any other equipment from this derived clock signal; at the very least it would have to be sharpened and squared up.

Jerry, you know I value your opinion too - have you had a chance to peruse the article?

I've had some feedback which I hope to address over the Easter period, but any other comments would be good.
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Thu Apr 05, 2012 9:30 am

It's a nice article... easy to read and well written.

If you're looking for a critique, my only complaint would be using the term 'special function register' to refer to the CONFIG registers. Microchip uses SFR to refer to control registers located in RAM (25K22 datasheet section 5.4.4), which is different than the flash-based Configuration registers (section 24.1), and it could be confusing to a beginner.

An important difference: accessing a SFR like OSCCON generates executable code, while CONFIG statements don't... they just set some data in the HEX file which get programmed into the chip when you download it.

Also, since a picture's worth a thousand words, it might be good to direct them to the oscillator block diagram in Figure 2-1. For example. if you look there it becomes apparent that if you want to use the PLL you have to have the Clock Switch Mux set to use the Primary Clock, so SCS<1:0> must be = %00

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Post by Aresby » Fri Apr 06, 2012 9:16 am

Thanks for the feedback. It's appreciated.

I admit that I have learned something new (again) - I thought they were ALL special function registers; obviously I was wrong and I've learned something useful which I'll use to correct my article.

This is exactly whiy I'm asking for validation of the article; I don't want to be misleading future readers of that article.

So I'll do what you suggest regarding the diagram (although I must admit it's only been recently that I've realised what it was trying to tell me).

I actually used my own article yesterday to set some values so at least I'm getting value out of it! :lol:

Sigh. Such a lot to learn. So little time. But what fun!
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Fri Apr 06, 2012 9:33 am

There are so many clock options on some of these chips that I find the diagram helps a lot. It doesn't always have the entire story, but it's pretty close.

The one thing that's really confusing though is that it's difficult to tell which control bits come from where, so you have to do a little digging to find out if the bits are in a config register or a SFR register, and which one.

be80be
Registered User
Registered User
Posts: 90
Joined: Mon Feb 23, 2009 2:15 am
Location: tn

Post by be80be » Sat Apr 07, 2012 8:17 pm

If you really want to have fun try this chip with HI-Tech C 18

I hate C but it's some how in my blood to help people with things such as this

Nice work here all.

You no why the fosc setting is not in there it's that dang microchip there nice new naming for configure's probably that's what was Hi-Tech new name and a day to dig them out.

And the chip sure has some registers

Once agin nice work all

Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Post by Aresby » Sun Apr 08, 2012 5:03 pm

Jerry Messina wrote:If you're looking for a critique, my only complaint would be using the term 'special function register' to refer to the CONFIG registers. Microchip uses SFR to refer to control registers located in RAM (25K22 datasheet section 5.4.4), which is different than the flash-based Configuration registers (section 24.1), and it could be confusing to a beginner.

An important difference: accessing a SFR like OSCCON generates executable code, while CONFIG statements don't... they just set some data in the HEX file which get programmed into the chip when you download it.
OK, I believe I have clarified the difference between these two types of register now - I'd be grateful for a brief check at your convenience. If I've got it wrong don't shy away from telling me!

I also added in the bit about the fail-safe 32KHz oscillator too, as well as correcting some typos, missing commas et al.

Now, Jerry, I hear what you say but I've not put the oscillator block diagram in (yet). As I'm aiming this at beginners I'm not wholly convinced that it would help, rather than hinder. It certainly meant nothing to me until I was well into my rather limited understanding of at least some of the oscillator registers. Especially when Microchip call the complex layout and plethora of esoteric names a simplified diagram.

And last, if not least, in the same way that I annihilated a good portion of the Amazonian rainforest in printing out the particularly poorly-named Data Sheet I would hope other beginners would do then same.

And then plant at least one tree to assuage their guilt of the aforesaid Amazonian bald patch.

The jury's still out on this one, though.
Aresby
Swordfish & PIC Newbie

User avatar
Senacharim
Posts: 139
Joined: Tue Aug 10, 2010 5:19 pm
Location: Ventura, CA

Post by Senacharim » Mon Apr 09, 2012 3:24 pm

Read thru the revised wiki entry, I find nothing particularly objectionable nor in need of large amounts of clarification.

Perhaps some small clarifications, but these are likely style choices of mine and not worth bringing up.

Good work.
Surviving Member
Bermuda Triangle Battalion
from 2026 to 1992

Voted "Most likely to time travel"--Class of 2024.

Post Reply