• 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.

external RC OSC

Status
Not open for further replies.

Deagol_the_Dead

New Member
I was working through this tutorial at http://www.mstracey.btinternet.co.uk/pictutorial/progtut4.htm when I noticed that the counter to delay the turning on/off of the LED is too long. I am using the specified resistor and capacitor, but I am using a PIC16F84A-20. I looked in the datasheet for RC, but all it shows is how to connect the RC to pin 16 and "5k Ohm <= R <= 100k Ohm, C > 20pF".

The original code had the delay decrementing 255, 255 times. This made the LED stay on/off for a little over a minute and a half. I changed it to decrement 255 only 5 times and this makes the LED stay on/off for ~1 sec.

Questions:

How would you calculate which size capacitor and resistor for a 20 MHz 16F84A?

How does the RC time constant get worked into the equation?

Code:
LIST            P=PIC16F84A
INCLUDE         "P16F84A.INC"
__CONFIG _RC_OSC & _PWRTE_ON & _CP_OFF & _WDT_OFF

COUNT1  equ 08h
COUNT2  equ 09h

        bsf STATUS,5   ;switch to Bank 1
        movlw 00h      ;set the Port A pins
        movwf TRISA    ;to output.
        bcf STATUS,5   ;switch back to Bank 0 

Start   movlw 02h      ;turn the LED on by first putting
        movwf PORTA    ;it into the w register and then on the port
        call setCount2
        call delay

        movlw 00h      ;turn the LED off by first putting
        movwf PORTA    ;into the w register and then on the port 
        call setCount2
        call delay

        goto Start

delay
Loop1   decfsz COUNT1,1  ;subtract 1 from 255
        goto Loop1       ;if COUNT is zero, carry on.
        decfsz COUNT2,1  ;subtract 1 from 5
        goto Loop1       ;go back to the start of our loop
        return

setCount2
        movlw 05h      ;put the value of 05h in the W register
        movwf COUNT2   ;now move it to our COUNT2 register
        return
        end
 

Attachments

Deagol_the_Dead

New Member
The time constant is t = RC (R in Ohms, C in Farads)

So for the schematic above:

t = 330000 * .00000000022

t = 0.0000726

1/RC = 13774.1046

divided by 4 for PIC

= 3443.5261

3443.5 What?
 

Deagol_the_Dead

New Member
Another thing that keeps bugging me is at the top of that same page, he says:

"If we are using a 4MHz crystal, then each instruction will take 1/4MHz, or 1uS to complete."

Wouldn't this be 0.25uS instead of 1uS?

(1/4,000,000 = .00000025 = .25uS or 250nS)
 

panic mode

Well-Known Member
If you use 4MHz crystal, external PIC oscillator runs at 4MHz.
This frequency is internaly divided by 4 so actual PIC clock is
only 1MHz. In other words PIC will execute only 1000000 instruction
in one second when mcu is coupled with 4MHz crystal.
So each instruction will take 1/1000000Hz = 1uS.
 

panic mode

Well-Known Member
about units:

t (time) is measured in seconds.

1/t has unit 1/s (which is Hz).

When you divide it by four number of pulses will reduce
four times but unit will remain Hz.


I'm too lazy to check the datasheet but if I remember correctly
speed was about same when running 4MHz crystal and RC clock
using 100K and 22pF. If I'm not mistaken, your values (330K and 220pF)
will produce clock 33x slower (resistor is 3.3x larger and capacitor is
10x larger, hence 3.3*10=33).
If the 4MHz comparison was correct (it's based on my memory which
is not the ultimate reference) this would roughly be equivalent of
4000000Hz/33=121200Hz or about 120kHz. Let me know if this value
makes sense.
Using same logic, 20MHz equivalent would use 22pF and 18k or
22k resistor... (20MHz/4MHz=5 and 100k/5=20k or 18-22k when using
standard values resistors)
 

Deagol_the_Dead

New Member
Thanks Panic mode. It makes a lot more sense to me now.

I found the table, finally, in the very back of the datasheet. The table in the "Complete Mid-Range Reference Manual.pdf" doesn't match up too well with the table in the PIC16F84A datasheet.

The lowest values in the tables are for 300pF and 100K, which is aroung 25KHz, so I GOTS TO CHANGE THAT RC!

Thanks again!
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top