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.

Oscillator setup problem.

Status
Not open for further replies.

Peet19

Member
Hello everyone!
I want to set the oscillator of a PIC18F24K22, but for some reason I can't set the OSTS bit
(OSTS: Oscillator Start-up Time-out Status bit) in the OSCCON register.
I would like to use an 8MHz crystal.

SCS = 00
HFIOFS = 0
OSTS = 1
IRCF = 000
IDLE = 0

MOVLW 0x08
MOVWF OSCCON

The configuration bits are in the picture. What could be the problem? Why can't the OSTS bit be set to 1?

Thank you in advance for your help!

1673191324713.png
 
Hello everyone!
I
I would like to use an 8MHz crystal.

Why use a Crystal when the chip has a perfectly good internal oscillator ?

Looking back at some of our old 18Fk22 assembler code this is what we used for an 8mhz internal oscillator.

Varoius ways you can then check its working properly a 8mhz, a flashing led an easy visual one.

Code:
Main    movlw    b'01110000'        ; set internal osc to 8 mhz
        movwf    OSCCON
 
Why use a Crystal when the chip has a perfectly good internal oscillator ?

I usually use the internal osc too, but the K22 intosc has a spec of +/-5% over VDD and temperature.
Sometimes you can't tolerate the variation.

They're typically much better than that, but a spec is a spec.
 
I usually use the internal osc too, but the K22 intosc has a spec of +/-5% over VDD and temperature.
Sometimes you can't tolerate the variation.

They're typically much better than that, but a spec is a spec.
Yes, it all depends what you're using the PIC for, but for most purposes the internal osc is fine - but if you need higher accuracy, then a crystal is an option.
 
I see, thank you. You're right.
Wp100: your binary code sets the oscillator to 16MHz, not 8, but I get the point.
If I want to use an internal oscillator, shouldn't the binary value of the SCS bits be 10?
Or if I already set the internal oscillator in the configuration bits, it doesn't matter here?
 
I see, thank you. You're right.
Wp100: your binary code sets the oscillator to 16MHz, not 8, but I get the point.
If I want to use an internal oscillator, shouldn't the binary value of the SCS bits be 10?
Or if I already set the internal oscillator in the configuration bits, it doesn't matter here?
Sorry, yes you are correct it should be 01100000 for 8 mhz.
From the code we used and some one elses 24k22 code we have seen, the SCS bits are 00, but we could still be wrong.
To be sure set it up and do a little timing test.

As said its some years since we used a 18K chip and then very little mainly because its just so complex to set up with all its possible options, and for a beginner even more so.

If you are new to Pics then would recommend you use the 18F2520 or 18F4520 which are so much more simpler to code with assembly. Still available here in the UK though a bit dearer, unless you need certain features only the k22 has ?
 
If you are new to Pics then would recommend you use the 18F2520 or 18F4520 which are so much more simpler to code with assembly.
They all use the same instructions, so it's not really any simpler. There may be fewer peripheral registers, but that's usually because the peripherals are not as good.

I'd be hard-pressed to ever recommend a 18Fxx20 over a K22. The K22 is bad enough (circa 2010), but the 18F2520 is pushing 20 years old now (2004). You'll pay for it, too, since the older the chip the greater the cost. Older chips can easily be 2-3x the cost of newer ones.
 
Found we still had a 45k22 chip, so just ran up some code from 10 years ago and used it to test for differences with the SCS bits set at 00 and 10.

In both Simulation and on the actual hardware test rig, it made no difference to the timing of the simple PortB 'flashing' of 6 seconds on/off.

Perhaps someone else can explain these bits and how they actually work ?

Have attached the code for you to try yourself , just needs the chip type changing, along with a screenshot of the Debugger Simulation using Breakpoints and the Stopwatch. Note that this code needs the Configuatation Check boxed Ticked .


001673.jpg



001671.jpg
 

Attachments

  • 45K22series.zip
    1.8 KB · Views: 148
Found we still had a 45k22 chip, so just ran up some code from 10 years ago and used it to test for differences with the SCS bits set at 00 and 10.

In both Simulation and on the actual hardware test rig, it made no difference to the timing of the simple PortB 'flashing' of 6 seconds on/off.

Perhaps someone else can explain these bits and how they actually work ?

Study the datasheet - spend hours, get more and more confused - then just use the MCC to create the fuse settings (then cut and paste the result) :D

Or better still, skip step one and go straight to the MCC.

Certainly on the 18F27K42 I use there's more oscillator settings than just the fuses anyway, and you have to set both to get the result you want - I often resort to using __delay_ms(1000) to create a one second delay, and toggle a port pin, which you can check with a scope, or even a simple LED (I usually have an LED hung on a pin somewhere for debugging).

That is when you find that the clock is running eight times faster, or eight times slower than you expected :D
 
SCS = 00 says to use the osc selected by the CONFIG words, 10 says to use the intosc.
If the CONFIG is set for intosc you probably won't see a difference.

Either way, the simulator timing doesn’t use any of these... it uses whatever you tell it the processor freq is, so you can't use that to see what the osc changes do.
 
If the SCS bits are set to 00, i.e. Primary clock, the PIC expects an external clock signal. But if you set an internal clock in the configuration bits, that will be the primary clock. For that, of course, the frequency must be selected in the OSCCON register.
 
If the SCS bits are set to 00, i.e. Primary clock, the PIC expects an external clock signal. But if you set an internal clock in the configuration bits, that will be the primary clock. For that, of course, the frequency must be selected in the OSCCON register.
Maybe it's just in the way you've phrased it, but when SCS = 00 the pic sets the clock to be whatever you've specified in the CONFIG1 setting... it could be either external or internal based on the FOSC settings of the config word. This is the clock that's used at power up or reset, and your program can't change that (SCS is 00 at power up)

If you've set CONFIG1 to use the intosc then it will startup at 1MHz since the poweron default of the OSCCON register is 0x30.

Once it's up and running your program can change things using the various OSCCON register settings.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top