Is there an SFR tweak to let an 08M2 use an external clock source ?.

Buzby

Senior Member
Hi,

I would like to drive an 08M2 from an external clock source.

Is there an SFR tweak that can be used to select the clock source ?.

( As the earlier 08M was a PIC12F683 which supported external clocks, I'm hoping the 08M2 is similar. )

Cheers,

Buzby
 

hippy

Technical Support
Staff member
Leg 2 ( Download Serial In ) is CLKIN/OSC1 for a bare PICmicro so it might be possible. It would probably depend on what parts of the internal oscillator circuitry is controlled by Configuration Fuses or by SFR. You would have to study the datasheet and experiment.
 

Buzby

Senior Member
Looking at the datasheet for PIC12F683 it does look like a single bit in OSCCON will select external clock.

That SFR also looks like it is the one PICAXE probably twiddles when changing frequency using setfreq etc.
I'm just hoping the firmware doesn't clobber it at other times !.

I'll give it a try tonight.

Cheers,

Buzby
 

Buzby

Senior Member
Thanks for that. I must have been having a senior moment !.

The SFR structure looks a bit more complex in the 08M2, and the clock options are more comprehensive, but I'll give it a try.

Cheers,

Buzby
 

bpowell

Senior Member
Clock source is in the CONFIG1 word...I dont think you can change config bits from within the application code.
 

Buzby

Senior Member
I saw the clock internal/external source select as being in OSCCON ( Bits 0 and 1 in SFR 099h in bank 1 ), which I think is accessible.

It does look like CONFIG1 is inaccessible, but with a bit of luck I might not need to change anything in there.

There's only one way to find out !.

Cheers,

Buzby
 

hippy

Technical Support
Staff member
It seems to be a mix of FOSC2:0 and SCS1:0 bits which ultimately control the clock source, a mix of CONFIG and SFR. One has to work through everything to figure out what other and actual consequences there are knowing it is configured for internal clock.

For example the oscillator may be disabled by CONFIG when not using an external clock, but that might not matter if the oscillator is not needed and a TTL clock can be forced into the appropriate pin. But if CLKIN is disabled then that would be problematic. It might be possible to route some other timer source oscillator.

There are some 20 pages related to the clock in the datasheet and I have never had the inclination to work my way through them and understand it all. Any potential gain never seemed worth the pain to me.
 

Buzby

Senior Member
... Any potential gain never seemed worth the pain to me.
Yes, it might not be worth it, but it won't take long to find out.

The challenge was prompted by the recent thread about dividing an input frequency.

It may be that the overhead of the firmware gets in the way, but if it works it would rather cool !.
 

bpowell

Senior Member
The only way to configure the 12F1840 to use the internal oscillator (which is how PICAXE has configured it) is to hard-code it in the config word (FOSC), OR, switch to the internal osciallator during run-time by changing the SCS bits of the OSCCON register...however, option #2 would require that *something* be clocking the PIC along until it reached that instruction and executed; which isn't the case. I'd bet a dollar the FOSC bits in CONFIG1 are set to "100" (Internal Oscillator, I/O functions on the CLKIN pin).

In the event I'm wrong, and you are able to change to an external clock, you'll need to clear bit 7 i the Alternate Pin Function register as well...that's currently set to 1 (to put the Serial-In on pin 2...when you clear it, Serial In will be on Pin 6.) this may or may not confuse the PICAXE firmware...I presume it's using an interrupt on Pin 2 to start a download....since it will go into "download mode" with a level change vs. a received serial character...so you might be out of luck.


Sorry to be a Debbie-Downer!
 

bpowell

Senior Member
It *might* be possible to write (with an ICSP) *just* the config bits and not affect the application code...I've never tried.

If you attempt this, be very careful...the CONFIG1 word also contains the Code Protect bits...disabling (setting) these bits will wipe the chip. Then you'll have a factory-config 12F1840 chip with a "08M2" label!
 

hippy

Technical Support
Staff member
you'll need to clear bit 7 i the Alternate Pin Function register as well...that's currently set to 1 (to put the Serial-In on pin 2...when you clear it, Serial In will be on Pin 6.)
That won't work if you mean for programming; the firmware uses bit-banged serial for programming, hard-wired to leg 2 and cannot be moved.

Getting it to accept an external clock source is just one part. Using it with that may be another challenge.
 

bpowell

Senior Member
That won't work if you mean for programming; the firmware uses bit-banged serial for programming, hard-wired to leg 2 and cannot be moved.
So the whole effort may be moot then...having a CLK or OSC signal on leg 2 will almost certainly trigger download resets...and you won't be able to get into the code to run a "Disconnect" as you'll be clocking from that Leg 2...
 

hippy

Technical Support
Staff member
So long as the clock signal is held low when the PICAXE powers-up that should allow it to start and execute the DISCONNECT command, then release the clock from being held low, then POKESFR to switch to that external clock. That might be as simple as -

Code:
               .-------|>|------.
               |                |
        ___    |   | V+   0V |  |
CLK >--|___|---^-->| SI   SO |--'
                   | X4   X1 |
                   | I3   X2 |
Code:
PowerOnReset:
  Disconnect
  High C.0
  PokeSfr ...
 

Buzby

Senior Member
The short answer to my question is no !.

Close scrutiny of the datasheet shows that at reset the accessible SFR bits are set to '00', which tells the PIC to use the clock source specified in CONFIG1 for startup.
As we know the 08M2 can startup without an external clock or crystal. This means that CONFIG must be set to use the internal oscillators for the clock source.

I've managed to switch frequencies using the SFR, but only to those available with setfreq, so not much use there.

I'm giving up with this. If I really needed it I'd learn PIC, not PICAXE !.

Cheers,

Buzby
 

AllyCat

Senior Member
Hi,

The challenge was prompted by the recent thread about dividing an input frequency.
.
I'm not sure how or why you'd want to "divide an input frequency" (using a PICaxe) and whether it would be from a (TTL) Clock source or a resonator/crystal, but an inspection of the data sheet suggests that it "should" be possible:

As already discussed, you can't use the normal external clock, but you should be able to use Timer 1: The Data Sheet (edited) says:

5.2.1 EXTERNAL CLOCK SOURCES
An external clock source can be used as the device system clock by performing ....the following actions:
• Write the SCS<1:0> bits in the OSCCON register to switch the system clock source to:
- Timer1 oscillator during run-time


Sadly, the Timer 1 input is also Leg2, so you'll still need to jump through the hoops suggested by hippy in #14, e.g. Start with Leg2 held low; Issue a DISCONNECT; "Enable" the external oscillator using a hardware "trick"; Wait for the Timer1 Oscillator Ready (T1OSCR) bit of the OSCSTAT register to be set; Switch the system clock to use Timer1.

Timer 1 can itself be used in (at least) three different modes: 1. Internal oscillator, 2. External (TTL) Clock Source (Leg2); 3. Internal Oscillator with External (32 kHz) crystal (Legs 2 and 3).

Note that the external clock input is a Schmitt Trigger (ST) input so might need a decent TTL amplitude.

The Oscillator is described as "optimised" for 32 kHz, but you might be able to push in a higher frequency clock. The Pin Description table (page 10) says: OSC1 XTAL — Crystal/Resonator (LP, XT, HS modes), but I guess that applies only when used for the master system oscillator not for Timer 1.

Cheers, Alan..
 
Top