Maker Pro
Maker Pro

PIC clock.

I

ian field

Anyone know which Microchip document elaborates on using external clock
source?

The configuration is well documented for oscillator types LC, LP, XT or HS,
but less explanation is given on using an external oscillator "can", my plan
is to build a development area header board for use with a PICKit 2 that has
sockets for various PICs, a further socket is to be provided for swappable
oscillator cans and maybe 2 or 3 crystal oscillators based on a HEX-inverter
for frequencies I dont have oscillator cans for.

The variety of tutorials I've collected have a variety of "author's
favourite clock frequencies", so I need to build flexibility into the
development board - jumpers/changeable modules to select the right
oscillator for the tutorial example being used, preferably without
constantly having to unsolder crystals and change loading capacitors all the
time.

TIA.
 
A

Anthony Fremont

ian said:
Anyone know which Microchip document elaborates on using external
clock source?

The configuration is well documented for oscillator types LC, LP, XT
or HS, but less explanation is given on using an external oscillator
"can", my plan is to build a development area header board for use
with a PICKit 2 that has sockets for various PICs, a further socket
is to be provided for swappable oscillator cans and maybe 2 or 3
crystal oscillators based on a HEX-inverter for frequencies I dont
have oscillator cans for.

Just feed the clock to the clock input (CLKI) of the PIC. Leave the other
pin disconnected and select ECIO as the oscillator type in the __CONFIG
word.
The variety of tutorials I've collected have a variety of "author's
favourite clock frequencies", so I need to build flexibility into the
development board - jumpers/changeable modules to select the right
oscillator for the tutorial example being used, preferably without
constantly having to unsolder crystals and change loading capacitors
all the time.

PLL?
 
R

Richard Seriani

ian field said:
Anyone know which Microchip document elaborates on using external clock
source?

The configuration is well documented for oscillator types LC, LP, XT or
HS, but less explanation is given on using an external oscillator "can",
my plan is to build a development area header board for use with a PICKit
2 that has sockets for various PICs, a further socket is to be provided
for swappable oscillator cans and maybe 2 or 3 crystal oscillators based
on a HEX-inverter for frequencies I dont have oscillator cans for.

The variety of tutorials I've collected have a variety of "author's
favourite clock frequencies", so I need to build flexibility into the
development board - jumpers/changeable modules to select the right
oscillator for the tutorial example being used, preferably without
constantly having to unsolder crystals and change loading capacitors all
the time.

TIA.
Which PIC?
If a mid-range device, the PICmicro Mid-Range MCU Family Reference Manual
has some detail.

Richard
 
I

ian field

Anthony Fremont said:
Just feed the clock to the clock input (CLKI) of the PIC. Leave the other
pin disconnected and select ECIO as the oscillator type in the __CONFIG
word.

Searching "ECIO" produced mainly dsPIC documents, the f84 datasheet only
lists the main oscillator types LP, XT & HS alongside a block diagram of a
"clock from ext system" into OSC1, so I assume that I should just select the
appropriate mode for the frequency to be used. That sheet has no mention of
ECIO in the section on oscillator mode.


I thought the whole point of using a PIC was to avoid a whole board full of
chips.
 
I

ian field

Richard Seriani said:
Which PIC?

The plan is to make a dvelopment board with multiple sockets to accomodate a
variety of PICs, and have the facility to easily change the oscillator
frequency to suit various tutorial example programs.

If a mid-range device, the PICmicro Mid-Range MCU Family Reference Manual
has some detail.

I have at least 2 versions of the midrange overview on my archive PC, I
don't recall any mention of a specific oscillator mode in config for an
external clock source.
 
A

Anthony Fremont

ian said:
Searching "ECIO" produced mainly dsPIC documents, the f84 datasheet
only lists the main oscillator types LP, XT & HS alongside a block
diagram of a "clock from ext system" into OSC1, so I assume that I
should just select the appropriate mode for the frequency to be used.
That sheet has no mention of ECIO in the section on oscillator mode.

Yes, that dinosaur doesn't have the EC mode specifically, but it does have
an OSC1 input that can be used with an external clock. If you look at the
16F628 (another antique but better than the f84), you will see that it has
EC mode in the CONFIG word and that they chose to call the input pin CLKIN.
On the 16F88 (my preferred 18 pin mid-range part), it is called ECIO and the
pin is named CLKI. I can't help it if Microchip isn't consistant with their
naming conventions.
I thought the whole point of using a PIC was to avoid a whole board
full of chips.

You're the one that brought up "jumpers/changeable modules", so I suggested
a PLL as a possible alternative. For most of my projects, I use the F88 and
the INTOSC module which is good enough to do serial comms. If I need more
accuracy than that, I add a xtal.
 
I

ian field

Anthony Fremont said:
Yes, that dinosaur doesn't have the EC mode specifically, but it does have
an OSC1 input that can be used with an external clock. If you look at the
16F628 (another antique but better than the f84), you will see that it has
EC mode in the CONFIG word and that they chose to call the input pin
CLKIN. On the 16F88 (my preferred 18 pin mid-range part), it is called
ECIO and the pin is named CLKI. I can't help it if Microchip isn't
consistant with their naming conventions.

The f84 might be ancient but its still a good choice for beginners (like me)
as it has less additional features that have to be disabled for simple
examples than even the f627, there is also a huge resource of tutorial
sample programs for the f84 on the net. Quite frankly, using even an f84 to
flash a single LED is like using an atom bomb to kill an ants nest!
You're the one that brought up "jumpers/changeable modules", so I
suggested a PLL as a possible alternative. For most of my projects, I use
the F88 and the INTOSC module which is good enough to do serial comms. If
I need more accuracy than that, I add a xtal.

Maybe I exaggerated a bit but a suitable PLL plus glue logic is going to
cost - and also the hassle of ordering the parts I don't have - so I'd
probably end up cobbling something together with a 74LS629, hence a board
full of chips.
 
R

Richard Seriani

ian field said:
The plan is to make a dvelopment board with multiple sockets to accomodate
a variety of PICs, and have the facility to easily change the oscillator
frequency to suit various tutorial example programs.



I have at least 2 versions of the midrange overview on my archive PC, I
don't recall any mention of a specific oscillator mode in config for an
external clock source.
Ian,

I may be totally missing the point of your requirements, but section 2 of
this document goes into external clock sources fairly thoroughly:
http://ww1.microchip.com/downloads/en/DeviceDoc/33023a.pdf

You wrote, "...I don't recall any mention of a specific oscillator mode in
config for an external clock source.", so you may have an older version. The
copy I have specifically mentions external crystals, resonators, and RC
oscillators, as well as internal oscillators. It also addresses the
oscillator configuration bits (fosc0:fosc1 or fosc0:fosc2, depending on the
PIC).

You also wrote, "The configuration is well documented for oscillator types
LC, LP, XT or HS, but less explanation is given on using an external
oscillator "can", ..."

If what you are looking for is something about HAVING to set the CONFIG bits
for external oscillators, that only has to be done if using an external RC
oscillator, not crystals or resonators. However, you do have to specifically
address the low, mid, or high frequency configuration (LP, XT, HS), based on
the frequency of the oscillator used, via the CONFIG fosc bits. For
instance, if your PIC is capable of operating at 20 MHz and you swap a 4 MHz
crystal for a 20 Mhz crystal, you will have to change the configuration from
XT to HS (if I recall). On the other hand, if you use the internal
oscillator, you have to specifically set the OSCCON bits for the desired
frequency, in addition to setting fosc CONFIG bits.

Anyway, the bottom line seems to be that, if all you want to do is change
out an external crytal or resonator, you only have to worry about setting
the fosc0:fosc1 CONFIG bits if using many of the mid-range devices (for
example, 16f84a). At worst, you have to set three CONFIG bits on other
mid-range PICS (fosc0:fosc1) if you also want to select between internal or
external RC oscillators and, if using the internal oscillator, setting the
appropriate bits in OSCCON.

I hope this helps. If I still don't understand, please try to help me. I may
be a little older, but I am not completely untrainable (though 37 years of
marriage still has its moments where my wife would disagree with that
statement).

Richard
 
A

Anthony Fremont

ian said:
The f84 might be ancient but its still a good choice for beginners

I disagree. It's an obsolete part that is vastly inferior to the _cheaper_
alternatives. To convert f84 code to run on a 628 or 88 consists of these
three steps:
__CONFIG adjustment
Account for start of user RAM being moved to a slightly higher address
Initialize CMCON on the 628 (ADCON on the 88)

That's it. That's all you have to do. It's trivial compared to effort of
trying to make sense of banking.

IMO, the 18F line is really the best choice for PIC beginners. It works
with C, and you don't have to learn about banking until you want to make use
of the rest of the RAM.
(like me) as it has less additional features that have to be disabled
for simple examples than even the f627, there is also a huge resource
of tutorial sample programs for the f84 on the net.

That's only cuz the Internet refuses to conform to rules of entropy and let
the old info rot away. Well that and guys like you that won't let the F84
die a natural death. ;-)
Quite frankly,
using even an f84 to flash a single LED is like using an atom bomb to
kill an ants nest!

That's why I use a 12F683 for that. It is a great part for driving an RGB
LED.
Maybe I exaggerated a bit but a suitable PLL plus glue logic is going
to cost - and also the hassle of ordering the parts I don't have - so
I'd probably end up cobbling something together with a 74LS629, hence
a board full of chips.

This looks pretty cool for $3:
http://www.mouser.com/search/Produc...3PWvirtualkey59500000virtualkey595-CDCEL913PW
Of course it will need a PIC or something to configure it, and another stage
to divide the generated clock back down to something usable.
 
I

ian field

Richard Seriani said:
Ian,

I may be totally missing the point of your requirements, but section 2 of
this document goes into external clock sources fairly thoroughly:
http://ww1.microchip.com/downloads/en/DeviceDoc/33023a.pdf

You wrote, "...I don't recall any mention of a specific oscillator mode in
config for an external clock source.", so you may have an older version.
The copy I have specifically mentions external crystals, resonators, and
RC oscillators, as well as internal oscillators. It also addresses the
oscillator configuration bits (fosc0:fosc1 or fosc0:fosc2, depending on
the PIC).

You also wrote, "The configuration is well documented for oscillator types
LC, LP, XT or HS, but less explanation is given on using an external
oscillator "can", ..."

If what you are looking for is something about HAVING to set the CONFIG
bits for external oscillators, that only has to be done if using an
external RC oscillator, not crystals or resonators. However, you do have
to specifically address the low, mid, or high frequency configuration (LP,
XT, HS), based on the frequency of the oscillator used, via the CONFIG
fosc bits. For instance, if your PIC is capable of operating at 20 MHz and
you swap a 4 MHz crystal for a 20 Mhz crystal, you will have to change the
configuration from XT to HS (if I recall). On the other hand, if you use
the internal oscillator, you have to specifically set the OSCCON bits for
the desired frequency, in addition to setting fosc CONFIG bits.

Anyway, the bottom line seems to be that, if all you want to do is change
out an external crytal or resonator, you only have to worry about setting
the fosc0:fosc1 CONFIG bits if using many of the mid-range devices (for
example, 16f84a). At worst, you have to set three CONFIG bits on other
mid-range PICS (fosc0:fosc1) if you also want to select between internal
or external RC oscillators and, if using the internal oscillator, setting
the appropriate bits in OSCCON.

I hope this helps. If I still don't understand, please try to help me. I
may be a little older, but I am not completely untrainable (though 37
years of marriage still has its moments where my wife would disagree with
that statement).

Richard


At the very least you've given me some clues what to search for, its now
obvious that these things evolve along with other device features and
there's no substitute for fully exploring the data sheet for each device I
try.

Thanks.
 
I

ian field

Anthony Fremont said:
I disagree. It's an obsolete part that is vastly inferior to the
_cheaper_ alternatives. To convert f84 code to run on a 628 or 88
consists of these three steps:
__CONFIG adjustment
Account for start of user RAM being moved to a slightly higher address
Initialize CMCON on the 628 (ADCON on the 88)

That's it. That's all you have to do. It's trivial compared to effort of
trying to make sense of banking.

IMO, the 18F line is really the best choice for PIC beginners. It works
with C, and you don't have to learn about banking until you want to make
use of the rest of the RAM.


That's only cuz the Internet refuses to conform to rules of entropy and
let the old info rot away. Well that and guys like you that won't let
the F84 die a natural death. ;-)


That's why I use a 12F683 for that. It is a great part for driving an RGB
LED.


This looks pretty cool for $3:
http://www.mouser.com/search/Produc...3PWvirtualkey59500000virtualkey595-CDCEL913PW
Of course it will need a PIC or something to configure it, and another
stage to divide the generated clock back down to something usable.

................and scroll, select & back buttons and a LCD module to tell me
what frequency I've selected and and
and...........................................
 
R

Richard Seriani

I disagree. It's an obsolete part that is vastly inferior to the
_cheaper_ alternatives. To convert f84 code to run on a 628 or 88
consists of these three steps:
__CONFIG adjustment
Account for start of user RAM being moved to a slightly higher address
Initialize CMCON on the 628 (ADCON on the 88)

That's it. That's all you have to do. It's trivial compared to effort of
trying to make sense of banking.


ANSEL (analog select), so we don't try to drive digital signals into an
analog input, instead of ADCON?

I, too, have used the 16f88 in place of the 16f84a, but it seems most
courses (high school and university) start out teaching the 84a. Probably
because there is so much information available. Of course, as long as the
required results are demonstrated, I haven't yet found a professor who won't
allow use of a PIC which has more features (the 16f88 and 16f87x seem to be
quite popular). In fact, it is sometimes encouraged in order to disuade
students from totally plagiarizing code from the internet.

Which chip, manufacturer, or chip family to teach at the entry level is, in
my opinion, less important than getting the students interested in the idea
of being able to make the MCU do something - anything - they program it to.
Those who want to pursue it will have the spark ignited, visit sites and
newsgroups that espouse various technologies, and make their own decisions
about which component, language, and development environment best fits their
current project. Those who only want a grade with little effort or real
desire to learn, won't - no matter which chip was used in the course.

Thanks for reading.

Richard
 
A

Anthony Fremont

ian said:
...............and scroll, select & back buttons and a LCD module to
tell me what frequency I've selected and and
and...........................................

Of course it's not the friendliest interface in the world, but one
pushbutton and one LED would do it. Short presses to step thru the presets
and a long press to store the new setting. One LED can provide all the user
feedback needed. Just sayin'........
 
I

ian field

Anthony Fremont said:
Of course it's not the friendliest interface in the world, but one
pushbutton and one LED would do it. Short presses to step thru the
presets and a long press to store the new setting. One LED can provide
all the user feedback needed. Just sayin'........

Quite a feat for someone (me) who hasn't done the flash a LED trick yet!
 
A

Anthony Fremont

Richard said:
ANSEL (analog select), so we don't try to drive digital signals into
an analog input, instead of ADCON?

Oops sorry about that. I didnt' verify it, I was just spouting from memory.
;-) One other "tiny" detail is that CMCON changed banks between the 628 and
the 88.
 
I

ian field

Anthony Fremont said:
Oops sorry about that. I didnt' verify it, I was just spouting from
memory. ;-) One other "tiny" detail is that CMCON changed banks between
the 628 and the 88.

Regarding one of your earlier posts - you did eventually give the correct
answer, I should have examined a later data sheet (F628) which does describe
the external oscillator setting in configuration word.

Its back to the drawing board anyway - I don't have any 4 or 10MHz
oscillator cans, a 20 can be divided by 2 to give 10 but requires divide by
5 for 4MHz which gives odd MS ratio, a 40 divided by 4 gives 20 & 10, and
divided by 10 gives 4 so that's a permanently soldered in can and a couple
of LSTTL dividers, the PIC in practice book most of the assignments use
32.768kHz so that's a 74C04 and watch crystal with a couple of gates left
over for any other low frequency clock might be needed in the future.

There is still the question of how to set the configuration word for an
F84 - in spite of them costing twice as much as more capable less ancient
parts, I bought a couple because most of the tutorials I have are based on
the F84.
 
R

Richard Seriani

ian field said:
There is still the question of how to set the configuration word for an
F84 - in spite of them costing twice as much as more capable less ancient
parts, I bought a couple because most of the tutorials I have are based on
the F84.
You can set up your config word the same way as for other mid-range chips.
You just add one of the following to the __CONFIG word, depending on which
oscillator frequency you are using:

_HS_OSC
_XT_OSC
_LP_OSC

Of course, you can also input your config directive as binary or hex, if you
want. Just set/clear the fosc bits, as required (see Sections 6.0 - 6.2 of
the 84A datasheet).

Tables 6-1 and 6-2 in the datasheet will give you an idea of the frequency
ranges for the different settings.

Good luck with the project.

Richard
 
A

Anthony Fremont

ian said:
Regarding one of your earlier posts - you did eventually give the

Eventually? ;-)
correct answer, I should have examined a later data sheet (F628)
which does describe the external oscillator setting in configuration
word.

You should always be looking at the latest datasheet/errata/etc. At any
rate, I don't know what difference the EC (or ECIO) modes really make. I
suspect you could still select HS or XTAL and it would still work fine.
AFAIK LP, HS and XTAL only affect the drive levels of the built in
inverter(oscillator). Since you are supplying an external signal to the
CLKI(or CLKIN depending), you aren't using the built in inverter to do
anything, so the drive level is relatively irrelevant. I suspect that EC
mode powers the inverter completely down so that the PIC uses a little less
juice.
Its back to the drawing board anyway - I don't have any 4 or 10MHz
oscillator cans, a 20 can be divided by 2 to give 10 but requires
divide by 5 for 4MHz which gives odd MS ratio, a 40 divided by 4
gives 20 & 10, and divided by 10 gives 4 so that's a permanently
soldered in can and a couple of LSTTL dividers, the PIC in practice
book most of the assignments use 32.768kHz so that's a 74C04 and watch
crystal with a couple of gates
left over for any other low frequency clock might be needed in the
future.
There is still the question of how to set the configuration word for
an F84 - in spite of them costing twice as much as more capable less
ancient parts, I bought a couple because most of the tutorials I have
are based on the F84.

I don't think it really matters what you use, but I think you should
experiment and find out. :) You will learn the most if you just
experiment for yourself. It's time to stop making plans and to start
writing some code. :) The f84 is ok to learn on, but it won't be long
before you want an ADC, a UART, more RAM, more/better timers built in, etc
etc etc..... ;-)
 
I

ian field

Anthony Fremont said:
Eventually? ;-)


You should always be looking at the latest datasheet/errata/etc. At any
rate, I don't know what difference the EC (or ECIO) modes really make. I
suspect you could still select HS or XTAL and it would still work fine.
AFAIK LP, HS and XTAL only affect the drive levels of the built in
inverter(oscillator). Since you are supplying an external signal to the
CLKI(or CLKIN depending), you aren't using the built in inverter to do
anything, so the drive level is relatively irrelevant. I suspect that EC
mode powers the inverter completely down so that the PIC uses a little
less juice.


I don't think it really matters what you use, but I think you should
experiment and find out. :) You will learn the most if you just
experiment for yourself. It's time to stop making plans and to start
writing some code. :) The f84 is ok to learn on, but it won't be long
before you want an ADC, a UART, more RAM, more/better timers built in, etc
etc etc..... ;-)


As a hardware person I don't see much problem using external peripherals and
keeping the software side as simple as possible if it makes life easier.
 

Similar threads

K
Replies
8
Views
1K
klem kedidelhopper
K
I
Replies
7
Views
906
Ben Jackson
B
I
Replies
1
Views
769
Brendan Gillatt
B
M
Replies
1
Views
2K
M.Randelzhofer
M
D
Replies
9
Views
786
Dirk Bruere at Neopax
D
Top