Author Topic: PIC16F1829 Oscillator question  (Read 3357 times)

0 Members and 1 Guest are viewing this topic.

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
PIC16F1829 Oscillator question
« on: March 05, 2013, 09:34:12 pm »
Hello Everyone,

I am working through the tutorials that came with my PICkit 3 starter kit.  The chip being used is the PIC16F1829

The goal of the tutorial is to blink a LED.  To do this they create a delay based off a 500KHz oscillator setup to create a visible 1.5 second delay.

In the data sheet for the PIC16F1829 it states the OSCCON register is used to set the CPU speed via either the internal or external Oscillator.

Bits 0 and 1 are the SCS.  If these bits are 00 the clock used is determined by the FOSC config word.  If it is 01 it uses timer1 and if it is 1x it uses bits 6-3 of OSCCON (IRCF) to determine clock speed.

FOSC configuration word is set to the internal oscillator so that gives me 31KHz to 32MHz to work with clock speed wise.  SCS is 00 so it uses that setting.

So apparently if OSCCON is set to b'00111000' it gives me 500KHz and apparently this setting lets the cpu process 125k instructions per second.

Now that my crappy background is stated here are my questions and keep in mind I am very new to this stuff.

How does OSCCON being set to 00111000 give me 500KHz? Self Answered(see below)
Also how does a 500KHz clock speed give me 125k instructions per second?

Feel free to explain with math if you have to because I feel that will help out a lot I could not find any math for this in the datasheet or in the tutorial.

Edit: Self Answered first question edit is for others with the same.
The first bit 0 can be ignored here as it is for higher clock speeds.
bits 6 - 3 are IRCF<3:0> which dictate clock speed
bit 2 = 0 which is un implemented.
bit 1 - 0 are the SCS for choosing your clock.
What I missed in the data sheet is a list of clock speed settings for the IRCF<3:0>  turns out that 0111 = 500KHz clock.

Second question is still un answered.
« Last Edit: March 05, 2013, 10:18:45 pm by blewisjr »
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2184
  • Country: au
Re: PIC16F1829 Oscillator question
« Reply #1 on: March 05, 2013, 10:15:21 pm »
How does OSCCON being set to 00111000 give me 500KHz?
You need to look at what the individual OSCCON bits mean and look at the diagram of the clock description. It usually shows multiplexing blocks that select one of multiple inputs based on contlrol bits used.
In this instance bit7 = 0, means the 4xPLL (basicaly multiplies input freq by 4) is off,
bits 6 to 3(named IRCF) = 0111 If you look at the mux block in the picture it selects one of umpteen frequencies from the post scaler, here it's the 500kHz input
bit 2 does nothing
bits 1 and 0 are set to 0 which makes the clock select mux chose the the input based on the FOSC config word.

Its seems you knew most of that anyway, from your post.
Quote
Also how does a 500KHz clock speed give me 125k instructions per second?
Most pics take 4 cycles to complete one instruction so its 500k/4
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4250
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: PIC16F1829 Oscillator question
« Reply #2 on: March 05, 2013, 10:20:11 pm »
http://ww1.microchip.com/downloads/en/DeviceDoc/41440A.pdf

OSCCON is described on page 71. 00111000 means:

bit 7 = 0, 4x PLL is disabled
bits 6..3 = 0111, internal oscillator at 500 kHz
bit 2 = 0 (unused)
bit 1..0 = 00, clock is determined by FOSC <2:0> in Configuration Word 1

That's where the 500 kHz comes from. The PIC takes 4 clocks per instruction, giving an instruction rate of 125 kHz.

Offline blewisjrTopic starter

  • Frequent Contributor
  • **
  • Posts: 301
Re: PIC16F1829 Oscillator question
« Reply #3 on: March 05, 2013, 10:22:33 pm »
Thank you :D

Very much appreciated.  While I was racking my brain I actual found the IRCF bit list in the data sheet.  Edited post then saw your reply so thanks anyway.

Also thanks I did not realize it was 4 cycles per instruction that will clear up a lot.

This data sheet is amazing with enough digging you can find everything.  Now that I understand this I can move on woo :D

I am learning so much doing this so glad I picked it up as a hobby.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf