PIC16F819 default oscillation frequency of internal oscillator?

Status
Not open for further replies.

d@nny

Full Member level 5
Full Member level 5
Joined
May 28, 2011
Messages
246
Helped
11
Reputation
22
Reaction score
11
Trophy points
1,298
Activity points
3,238
Hello!
i am using following code in pic16f819 and internal oscillator is working but i dont know at what frequency? Please tell me the frequency and how to select different frequencies?

Code:

processor PIC16F819
#include <p16f819.inc>
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO
J equ 20h
org 0
goto main
main:
banksel PORTB
clrf PORTB
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
................................................ continue

The code is working 100% ok but i dont know at what frequency? and how to select frequencies?
 

The first item on the agenda when working with a new IC or MCU is visit the manufactures product page:

Microchip's PIC16F819 Product Page

You'll see according to the features listed, the PIC has an 8 MHz Internal Oscillator.

While you're there grab the PIC's datasheet, an absolute must have, any datasheet errata and yes MCUs have "bugs" too, so grab any silicon errata or peripheral errata.

PIC16F818/819 Datasheet

Reviewing any errata can greatly reduce stress levels and aspirin intake during the development process.

The datasheet for the particular MCU series you're working with is its bible, read it, study it, know it.

Datasheet information concerning internal oscillator frequency configuration:


Check the datasheet for further details for internal oscillator configuration.

Also take a look at any appnotes listed, they usually pertain to that specific MCU series and can give valuable info, tips and shortcuts to implementing your design.

Hope these guidelines and info help in your endeavors.
 
  • Like
Reactions: d@nny

    d@nny

    Points: 2
    Helpful Answer Positive Rating

Thank you so much
Actually i am familiar with pic16f84 as i am using pic16f84 book and start mcu just 3 days ago so i am a bit confuse. If any one can tell me at which frequency my code is working i can understand the information in above quote. Please make it a bit clear that at what frequency i am working ? 8MHz or 32KHz?
 

If you haven't made any changes to the OSCCON register, IRCF2:IRCF0 bits. The system clock is most likely set at the default 8MHz of the internal oscillator. However, use your programmer/debugger and at the OSCCON register and see what state the IRCF2:IRCF0 bits are set.

From the datasheet:



---------- Post added at 19:51 ---------- Previous post was at 19:34 ----------

Or you can explicitly set the register with:

Code:
banksel OSCCON
movlw B'01110000'
movwf OSCCON

To ensure it is set at 8MHz or adjust to whatever clock rate is appropriate for your app.
 
Reactions: d@nny

    d@nny

    Points: 2
    Helpful Answer Positive Rating
thank you so much for
reply and i am understand now how to set the internel frequency but a bit confuse about
(bit 2 IOFS: INTOSC Frequency Stable bit
1 = Frequency is stable
0 = Frequency is not stable)
what is mean by that?
how much internel oscillator is precise?
internel oscilator is Resistance Capacitor oscilator?
and what is mean by stable and not stable frequency?
which option is better?
thanking you in anticipation

---------- Post added at 06:19 ---------- Previous post was at 05:58 ----------

I have tested all frequencies and the default frequency is 31 KHZ
Please reply my above question plzzzzz
 

In regards to your PM:

I have tested the intstruction you have given above and discoverd that the default frequency is 31.25 KHz.

I assuming the instruction you're referring to is the SFR, OSCCON register, IRCF2:IRCF0 bits. It really shouldn't be an issue, it's good practice to preset all your SFRs required for a program to function correctly.

Reference pg. 38, REGISTER 4-2

Just use the snippet I posted earlier:

Code:
banksel OSCCON
movlw B'01110000' ; 8MHz Internal Oscillator Frequency Select bits
movwf OSCCON

In regards to your PM:

The internal oscillator is Resistance Capacitor.

There are actually two internal oscillators, INTRC source (31.25 kHz) and INTOSC source (8 MHz). Only the INTRC is specified as RC, the other an oscillator block, which may or may not get a clock signal form INTRC. I'll need to read the datasheet further.

Reference pg. 37, 4.5.3 OSCILLATOR CONTROL REGISTER

In regards to your PM:

How much precise it is?

Oscillator accuracy is very dependent on Temperature, Vdd and Operating Temperature Rating.

@Vdd = 4.5v -5.5v, Chip Temp 25°C, 0°C to 70°C Temp Rating

INTOSC Accuracy = +/- 5%, with 1% typical
INTRC Accuracy = Actual Freq. Range 26.562kHz to 35.938kHz

Is the accuracy good enough, well that depends on your application:

Standard delays, PWM, etc - most likely
Digital clock running 24/7 - not likely

Reference pg. 127, 15.3 DC Characteristics: Internal RC Accuracy

In regards to your PM:

what is mean by stable and not stable frequency pleaseeee?

Quote from PIC 16F818/819 Datasheet:


What does this mean, simple, if the system clock is set to 31.25kHz and your program changes the IRCF bits to any other value the system clock must resync and there is a momentary instability while it locks on to the new clock frequency. The IOFS bit is cleared during the instability, unstable clock, and then the IOFS bit is set when the new system clock is stable. Your program can monitor the IOFS bit to know when system clock is stable again.

Reference pg. 37, 4.5.4 MODIFYING THE IRCF BITS
and
Reference pg. 37, 4.5.5 CLOCK TRANSITION SEQUENCE WHEN THE IRCF BITS ARE MODIFIED

The above should answer your questions in the Personal Message (PM).

Are there any other questions?
 
Reactions: d@nny

    d@nny

    Points: 2
    Helpful Answer Positive Rating
Thank you sooo muchhhhhhhh

---------- Post added at 14:54 ---------- Previous post was at 14:41 ----------

YA another question
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO

can i change this in some way to select 8mhz in __config file?????????

---------- Post added at 16:02 ---------- Previous post was at 14:54 ----------

whats about this code to check stable frequency before proceed if i change the frequency in my code for counting or some other purposes and than switch back to 8mhz

processor PIC16F819
#include <p16f819.inc>
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO
J equ 20h
org 0
goto main
main:
banksel OSCCON
movlw B'01110000'
movwf OSCCON
stable: btfss OSCCON , 2
goto stable
banksel PORTB
clrf PORTB
banksel TRISB
movlw B'00000000'
movwf TRISB




************stable: btfss OSCCON , 2
goto stable
 

Thank you sooo muchhhhhhhh

I'm happy I was able to help.

By the way, EDABoard members are encourage to mark each posting they find helpful by clicking on the "Did you find this post helpful?" - Green Thumbs Up Icon.

It's the best way to show gratitude to another member for help received.

YA another question
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO

can i change this in some way to select 8mhz in __config file?????????

Unfortunately, no, the __CONFIG directive can set or unset bits only in the configuration register. The bit definitions, like _WDT_OFF, are actually just EQUs list in p16f819.inc. You can actual open the .inc file up in an editor as see those and other EQUs available to your assembler program.


Yes, that's the idea.

Of course the instability only occurs when changing from a FOSC of 31.25KHz, IRCF<2:0> = 000 to a higher FOSC, IRCF<2:0> = anything other than 000.

Any other change in IRCF<2:0> has no effect on FOSC stability. You mainly want to avoid doing clock critical routines like generating PWM, CCP, etc during FOSC instability simple operations like assigning a value to PORTB, TRISB, etc will most likely not be effected by the FOSC instability.

Hope the infor helps in your endeavors.
 
Reactions: d@nny

    d@nny

    Points: 2
    Helpful Answer Positive Rating
Thank you so much
can you please give me some reference to understand programming counter as in look up table for seven segment in many programmes i have seen it but cant understand what it is completely? i have used pcl partilally in seven segment to night. but want complete information?
Actually you are teaching me the whole PIC16F819
 

Are you display a countdown or time on the 7-segment display?

How many digits? Do you have a schematic of your circuit?
 
Reactions: d@nny

    d@nny

    Points: 2
    Helpful Answer Positive Rating
only one digit. No schematic.
I just want to know the pcl and program counter.
 

Hello!
I also want some good debounce switch routine and its explanation?
 

Hi D@nny,

Ok, rather than spend hours stepping you through the details, I'm going to introduce you to some of the best PIC tutorials available online:

The lessons cover the baseline and midrange PIC architectures using assembly language and freely-available PIC C compilers.

Gooligum PIC Tutorials

This particular tutorial covers 7-Segment Displays, Lookup Tables and PCL in Assembly:





And tutorial covering switch debouncing:





Hardware debouncing is the alternative to software debouncing, I can post some links and upload some docs pertaining to this technique if you are interested.

Step through the tutorials covering the topics of your interest and let me know which topics you would like me to elaborate.

I very impressed with Gooligum's tutorials, they are well documented with good source code. I'm sure you will be impressed as well.

Ciao
 
Last edited:
Reactions: d@nny

    d@nny

    Points: 2
    Helpful Answer Positive Rating
IS it need to calibrate the PIC16F819 oscilator in OSCTUNE register or it is by default in Tune mode?
 

The factory setting should suffice.

Beware, modifying some MCU calibration clock settings can be a tricky affair. If the wrong value is enter it can, depending on the MCU, "brick" the device.

Some Atmel MCUs are particularly prone to this problem. I've not dealt with the PIC16F819 on that level, so this is the best advice I can give.

The old adage, "If it isn't broke, don't fix it" applies here.

---------- Post added at 07:59 ---------- Previous post was at 07:51 ----------

If you should happen to let temptation get the better of you.

Always record or backup the factory clock calibration value, before modifying it.
 

Hi d@nny,

Have you had a chance to checkout those Gooligum Tutorials.

If so let me know what you think of them.
 

they are best but i cant understand linker as i have not ever used mplab but write programme in notepad and used MPASWIN. The best thing is that they define timer0 interrupt, and comparator function very easy manner specially time calculations but i cant understand shadow copy i think that is linker command
 

Keep plugging away at them.

I'll put together a list of items you need further examples of to fully understand.
 

processor PIC16F819
#include <p16f819.inc>
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO
J equ 20h
K equ 21h
org 0
goto main
main:
banksel OSCCON
movlw B'01110000'
movwf OSCCON
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
Flasher:
bcf PORTB , 1
bsf PORTB , 0
nop
nop
call delay
bcf PORTB , 0
bsf PORTB , 1
call delay
goto Flasher
fin:
goto fin
delay:
movlw D'10'
movwf K
clrf J
delay1:
nop
decfsz J , f
goto delay1
delay2:
nop
decfsz J , f
goto delay2
decfsz K , f
goto delay1
return
end


Simplest 50Hz frequency for 12vdc to 220vac picture below.
Will this work if i use it to make inverter?
can i control duty cycle of this frequecy with pwm in pic16f819 or it is not possible? Their is another method to do this with pwm? i mean is the 50hz pwm will be realtime or the frequency i made with code can be attached with pwm?
 

processor PIC16F819
#include <p16f819.inc>
__CONFIG _CP_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _CCP1_RB2 & _LVP_OFF & _BODEN_ON & _MCLR_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_IO
J equ 20h
K equ 21h
org 0
goto main
main:
banksel OSCCON
movlw B'01110000'
movwf OSCCON
banksel TRISB
movlw B'00000000'
movwf TRISB
banksel PORTB
Flasher:
bcf PORTB , 1
bsf PORTB , 0
bcf PORTB , 0
bsf PORTB , 1
goto Flasher
fin:
goto fin
delay:
movlw D'20'
movwf K
clrf J
delay1:
nop
decfsz J , f
goto delay1
delay2:
nop
decfsz J , f
goto delay2
decfsz K , f
goto delay1
return
end
 

Status
Not open for further replies.

Similar threads