PIC16F1829 Oscillator question - Page 1
Forum section: electronics / general

author: blewisjr
author_rank: Frequent Contributor
timestamp: March 05, 2013, 09:34:12 pm
content: Hello Everyone,I am working through the tutorials that came with my PICkit 3 starter kit. The chip being used is the PIC16F1829The 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 speedbit 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.

author: AlfBaz
author_rank: Super Contributor
timestamp: March 05, 2013, 10:15:21 pm
content: Quote from: blewisjr on March 05, 2013, 09:34:12 pmYou 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 inputbit 2 does nothingbits 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.QuoteMost pics take 4 cycles to complete one instruction so its 500k/4

author: AndyC_772
author_rank: Super Contributor
timestamp: March 05, 2013, 10:20:11 pm
content: http://ww1.microchip.com/downloads/en/DeviceDoc/41440A.pdfOSCCON is described on page 71. 00111000 means:bit 7 = 0, 4x PLL is disabledbits 6..3 = 0111, internal oscillator at 500 kHzbit 2 = 0 (unused)bit 1..0 = 00, clock is determined by FOSC <2:0> in Configuration Word 1That's where the 500 kHz comes from. The PIC takes 4 clocks per instruction, giving an instruction rate of 125 kHz.

author: blewisjr
author_rank: Frequent Contributor
timestamp: March 05, 2013, 10:22:33 pm
content: Thank youVery 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 wooI am learning so much doing this so glad I picked it up as a hobby.