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.

RC oscillator is very slow

Status
Not open for further replies.

BOBKA

New Member
Hi,


I was experimenting with 18f452 pic and a simple led tutorial. It appears that the RC oscillator frequency is about 0.1Hz, can I modify it somehow?
Basically, the code for the blinking is present below, it doesn't have any delays:

#include <p18f452.inc>

__CONFIG _CONFIG1H, _OSCS_ON_1H & _RC_OSC_1H ; External Clock on OSC1 & OSC2
__CONFIG _CONFIG2L, _BOR_ON_2L & _BORV_20_2L & _PWRT_OFF_2L ; Brown out reset on at 2.0V, no power-up timer
__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H ; watchdog off, postscaler count to 128
__CONFIG _CONFIG3H, _CCP2MX_ON_3H ; CCP2 pin Mux enabled. What is this?
__CONFIG _CONFIG4L, _STVR_ON_4L & _LVP_ON_4L & _DEBUG_OFF_4L ; Stack under/overflow reset on, LVP on, debug off
__CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L ; all protection off
__CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
__CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
__CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
__CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
__CONFIG _CONFIG7H, _EBTRB_OFF_7H

org 0x0000

COUNT1 equ 0x01
COUNT2 equ 0x02

clrf TRISD ; set all bits in TRISD to zero.

Main
bsf PORTD, RD1 ; set bit RD1 in the PORTD register
bcf PORTD, RD1 ; clear bit RD1 in the PORTD register
goto Main

END


Using this code, the led is on for about 4 seconds, and then off for like 10 seconds. I am using simple RC oscillator (R & C, R to vdd, C to gnd) as presented in the datasheet. The R=10k, and C=100uF (25V).

What should I change to increase the oscillation frequency?
 
Yes, MUCH smaller - and try reading the datasheet, it explains how to calculate the components based on the frequency you want - although I'm sure they never imagined anyone using a 100uF.
 
To be fair, in the 16F88 datasheet, just for example, I didn't find any info on actually calculating component values.

However, just as a bit of a reality check, by [latex]f0=1/(2*pi*R*C)[/latex] your component values give a natural frequency of 0.159 Hz... What were you thinking with that huge capacitor?? I wouldn't expect this to be the exact oscillation frequency because it doesnt take into account the switching points, etc, but it gives at least a ballpark figure which seems to agree with your experimental results.

if you swapped in a 100pf capacitor you should get more like 100-200Khz, drop the resistor to 4.7k or so and you might get more like double that much.

But, I'd still highly recommend you just buy (or find) yourself a crystal or ceramic resonator, or switch to a PIC with an internal oscillator... Even if you do get an RC oscillator working at a higher speed, it's still going to be like 1/100 the speed you could easily get with a crystal, plus be WAY less stable...
 
evandude said:
To be fair, in the 16F88 datasheet, just for example, I didn't find any info on actually calculating component values.

I didn't in the 18Fxx2 sheet either?, but page 295 gives graphs of frequency variations against supply voltage for four values of R, and two values of C.

I also agree with Evandude - use a crystal or ceramic resonator - you should be able to find them in an old TV set.
 
I have changed the capacitor to 100pF and total resistance of 5.4k, but the oscillating frequency ended up to be vert slow (but faster than before).

Where can I find the equation to calculate the frequency, or how is it called, cause I couldn't find anything similar in the datasheet for 18fxx2.

Thank You :)
 
The oscillator frequency divided by 4 is available on the CLKOUT pin (if it's not configured as a general I/O pin). If you have an oscilloscope/frequency meter, you can measure it.
 
You're not ALL that far away from the minimum values (3k and 20pF). You should not even bother trying to calculate the frequency - it's going to vary wildly based on the exact components you use (many caps have a 10-20% tolerance...) and it's not going to be stable with temperature - which is probably why they didn't bother putting equations to calculate it in the datasheet. If it's going too slow for you, you're better off just trying smaller values until you're happy, or you hit the minimums.

Either way, i still think you're going to be pretty disappointed with the speed and performance you will get out of it, it's going to be quite poor compared to a crystal. Honestly, I don't think I've ever seen ANYONE use an external RC oscillator with a PIC before, and it seems there's a good reason for that... especially when proper crystals and ceramic resonators are so cheap.
 
evandude said:
Honestly, I don't think I've ever seen ANYONE use an external RC oscillator with a PIC before, and it seems there's a good reason for that... especially when proper crystals and ceramic resonators are so cheap.

I've certainly never used one, I use the internal ones - because it's more stable than an external one, and it frees I/O pins.
 
Nigel Goodwin said:
I've certainly never used one, I use the internal ones - because it's more stable than an external one, and it frees I/O pins.


Nigel: do you mean peak has an internal oscillator?

I was just using RC because I didn't have an opportunity yet go and by an oscillator

Thank you guys for your immediate reply.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top