PDA

View Full Version : 16F88 internal clock configuration



Tgq
- 13th July 2004, 15:52
Hi
I'm looking for internal clock configuration @8MHz
Thanks

Melanie
- 13th July 2004, 19:40
There are many options here… so here‘s just one of them…

1. Ensure that your Device Oscillator Configuration Bits are set to INTRC_OSC_NOCLKOUT (if you don’t know how to do this, see the new FAQ section). This option also means that the two OSC pins are made available for I/O. If you need the Oscillator to output on OSC2, then select the appropriate option (again see FAQ section).

2. Somewhere at the start of your program (where you normally initialise your processors registers) add the line…

OSCCON=%01111000

I refer you to the Datasheet section 4, especially Register 4.2 OSCCON to discover what I have done.

3. If stabilising your clock to other events is important to you, then you may need to add this piece of code after the above OSCCON setting (otherwise it is not necessary)…

While OSCCON.2=0:Wend

This will ensure the PIC does not continue processing until the new Oscillator Frequency is stable by introducing a 4mS delay (see datasheet 4.6.5 item 4).

As with ALL the queries regarding the set-up of PICs – Read the Datasheet! – it’s all there waiting for you to discover.

Tom Gonser
- 7th March 2005, 00:44
As I am new to this, reading the data sheets sometimes pose more questions than they answer. Such is with trying to figure out how to use the Internal Osc on the 16F88.

I am moving from a 16876A where I used and external Osc - and have a program running fine there. Now, I want to move this program to the 16F88, and rather than use external Osc, use an internal. I have recompiled, tweaked the PORT.X settings, and am ready to go, BUT.

I see the F88 is an 8 mhz OSC, when I was using 4... Sure, I'd like to go faster, but just sticking to the same as the first pic is fine.

I have seen mention of setting the config bits to INTRC_OSC_NOCLKOUT in the include file.

As well I have seen advise to use OSCCON=%01111000 at the start - which mapping back to the data sheet looks like it is selecting a speed, but I can't find a table that maps to this..

I have also seen several references to OSC as RA6, etc... I just simply need to know what to read to find out how to use the internal oscillator and set it appropriately.. anyone have a few mintues to help out with a reply..

mister_e
- 7th March 2005, 02:34
Not quite sure as i didn't see any parts of your code but, if your 8MHZ setting is ok, you also must add DEFINE OSC 8 at the top.. did you?

for the internal setting, see datasheet in the OSCCON. all the setting are there.

in your case for 8MHZ
OSCCON=%01111000

for 4MHZ
OSCCON=%01101000

and so on for the other type of setting

Tom Gonser
- 7th March 2005, 04:18
Much closer.. THANKS!

I now see data on the LCD and on the 4800b Hyperterm screen, but the numbers are incorrect.. and the routines run differently..

Where data was reporting '1009', the text tag is fine, but the actual data is different..... like '3345', etc.

It looks like a timing problem some way?

Would the config bits effect this?

TG

mister_e
- 7th March 2005, 04:33
As we don't have any more info on your current project, it's still hard too see what's wrong with.. BUT at least, since your LCD and your serial communication are working without any kind of garbage display, it's a good sign that your PIC and code are running at the good speed.

If you did some assembler delay or something using TIMERs you must set your prescallers, rates, and delay with the new crystal speed

Did you try with the internal 4MHZ setting???

Tom Gonser
- 7th March 2005, 05:59
Hmmm.. I have tried with:

DEFINE OSC 4 'I want to use 4 mhz?
OSCCON=%01101000

and with setting these to 8Mhz ..

DEFINE OSC 8
OSCCON=%01111000 '8 Mhz

Both work about the same - 'some' plain text comes through, but the code is resetting because I am getting the initialization routine, which does not happen usually.

I am not doing any interrupts or anything, no jumps to assmbly code - pretty straightforward.

I did change the INC files:

changed the "XT_OSC" for "INTRC_OSC_NOCLKOUT" - It looks like this now:

;************************************************* ***************
;* 16F88.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2003 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 08/13/03 *
;* Version : 2.45 beta *
;* Notes : *
;************************************************* ***************
; Modified by THG - changed clock settin from XT_OSC
NOLIST
ifdef PM_USED
LIST
include 'M16F88.INC' ; PM header
device pic16F88, INTRC_OSC_NOCLKOUT, wdt_on, pwrt_on, lvp_off, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F88, r = dec, w = -302
INCLUDE "P16F88.INC" ; MPASM Header
__config _CONFIG1, INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF
NOLIST
endif
LIST

The strangest thing is that the program appears to be restarting when it should not. It should be looping through the main routine, but on the F88, it is picking up the initialization routine every few seconds.

scratching head....

mister_e
- 7th March 2005, 06:15
Hehe... i guess i found the problem

Here's all the configuration fuse available for you 16F88


;Configuration Byte 1 Options
_CP_ALL EQU H'1FFF'
_CP_OFF EQU H'3FFF'
_CCP1_RB0 EQU H'3FFF'
_CCP1_RB3 EQU H'2FFF'
_DEBUG_OFF EQU H'3FFF'
_DEBUG_ON EQU H'37FF'
_WRT_PROTECT_OFF EQU H'3FFF' ;No program memory write protection
_WRT_PROTECT_256 EQU H'3DFF' ;First 256 program memory protected
_WRT_PROTECT_2048 EQU H'3BFF' ;First 2048 program memory protected
_WRT_PROTECT_ALL EQU H'39FF' ;All of program memory protected
_CPD_ON EQU H'3EFF'
_CPD_OFF EQU H'3FFF'
_LVP_ON EQU H'3FFF'
_LVP_OFF EQU H'3F7F'
_BODEN_ON EQU H'3FFF'
_BODEN_OFF EQU H'3FBF'
_MCLR_ON EQU H'3FFF'
_MCLR_OFF EQU H'3FDF'
_PWRTE_OFF EQU H'3FFF'
_PWRTE_ON EQU H'3FF7'
_WDT_ON EQU H'3FFF'
_WDT_OFF EQU H'3FFB'
_EXTRC_CLKOUT EQU H'3FFF'
_EXTRC_IO EQU H'3FFE'
_INTRC_CLKOUT EQU H'3FFD'
_INTRC_IO EQU H'3FFC'
_EXTCLK EQU H'3FEF'
_HS_OSC EQU H'3FEE'
_XT_OSC EQU H'3FED'
_LP_OSC EQU H'3FEC'

;Configuration Byte 2 Options
_IESO_ON EQU H'3FFF'
_IESO_OFF EQU H'3FFD'
_FCMEN_ON EQU H'3FFF'
_FCMEN_OFF EQU H'3FFE'


use _INTRC_IO instead... i'm sure that will work.

Tom Gonser
- 7th March 2005, 07:29
I am using the _INTRC-IO, and also tweaked the serin2 stuff, so I have 'data' coming across all com lines now. Problem is that it is just 'off'..

1. ) It is resetting. I have one routine at the front which only happens on power up. The data from this is showing up off and on.

2.) the math is off. Where a value should sa 4.9volts it reads 3.3. Were a GPS lat should be 47.xxx, it reads 65,511, or some such. Same with all the other values, so I am sure the loops are off.

I made a simpler program that just spewed data to the different com ports - out on RB2, RA0, RA1. This just said "text", #counter - and looped from 1-100.. that worked fine. When I put the full program in, it gives bad data.

I think the original program for the 16F876/a was a 4Mhz program (??).. Does running this at 8 Mhz mess that up? Is there some setting that is needed? Does not seem like there should be....

Thanks a bunch for your assistance - I've never 'ported' from one PIC to another. This program works great on the other one... but we need to be on the F88.. did not know it was going to be so hard.

Tom

mister_e
- 7th March 2005, 08:20
o.k now it seems more a hardware problem than a software problem. be sure your supply line is neat an un-noisy. 10uF tantalum+0.1uF must be place close to your PIC... AS close as you can.

AND be sure your MCLR pin is tie to VCC via resistor.

Enable power-up timer can be great. Also as Melanie previously said it can be interesting to test the 'oscillator frequency is stable bit' before proceed to any of your initialisation process.

look at the a/d register setting(ADCON and others)... i'm sure that they're different from the PIC you used before.

Tom Gonser
- 7th March 2005, 14:42
The hardware is pretty skimpy.. I have the F88 a 5.1v supply, and a resistor from MCLR to power. I have only power and ground supplied, and then serial lines out from the appropriate port pins. No caps no nothing.

Whats odd is that with small program.. like only a portion of the one I am porting over, it works. It wakes up, it does its routine, then it starts doing a simple read from data input, put data into array, and read data from array out to the three serial outputs. This works fine.

Whats odd is when I put my WHOLE program in place, it chokes.. It periodically shows the data, but when it does the math is always wrong, and it looks to be resetting as I see the initialize routine results now and then.

I don't know about ADCON as I am only doing serial data in on Port B1, and serial data out on B2 and also A0,A1. I am setting the serial data out on A1 to 4800b by using SERIN2, and the rest is 9600b. - But again, this seems to work fine with a smaller program...

Must be some timing setting beyond what I've had to set before.

TG

mister_e
- 7th March 2005, 16:24
so there's no analog to digital conversion on a.0 and a.1 ???

you must disable those analog pins to make them digital.. at least

ANSEL=3 'set a.0 and a.1 as digital input

and capacitor should be consider.

Tom Gonser
- 7th March 2005, 16:38
Set the .. ANSEL=3 'set a.0 and a.1 as digital input, thx. Probably a good idea, but did not have any impact.

Oddly as I test, I find that my setting for OSCAL 8 mhz or OSCAL 4 Mhz does not have any impact on the system..

I have tried:

OSCCON=%01101000 ' 4 mhz
DEFINE OSC 4

----

and in another test...

DEFINE OSC 8
OSCCON=%01111000 '8 Mhz


Something must not be getting written somewhere. I'd expect that these settings would have a big impact on overall system operation.

Is there some prescaler setting that I am missing?

tg

mister_e
- 7th March 2005, 16:48
prescaller have nothing to do with your code if you're not using TIMERs. Can you post your code here or it's a 'military secret' ;)

Tom Gonser
- 7th March 2005, 19:59
This program reads a data sentence sent at 9600b 8,1.n. The sentence has two start bytes, then 34 data bytes. It works on the 16F876A on the test board from Microchip, but the plain old F88 on my breadboard is acting strange as the thread indicates..

TG

mister_e
- 7th March 2005, 20:41
reason is simple... you run out of memory...

PIC16F876 : 8K
PIC16F88: 4K
YourCode :4287 words

so you can for sure shrink it using internal or external EEPROM instead of arrays and few other things. It has to fit in a 4k memory space

Tom Gonser
- 8th March 2005, 03:58
...wow, that easy huh? Well, I removed some of the code, and it does run much better, indeed!! I still see some odd behavior however:

1. The voltage calculation is inaccurate
2. The 'initialize' subroutine does not fire, or only partially fires
3. The N, S, E, W Select Case does not appear to be working as the values are missing in the output
4. The Select Case routine for the lock flag (which is 1,2, or 3. is showing an ERROR - or something besides these values.

The other calculations look right...

I think all this may be convincing me not to try to port over, as this program runs really well on the other chip... arghhh

mister_e
- 8th March 2005, 04:18
Post your new code here to see wha can it should be.

Tom Gonser
- 8th March 2005, 04:47
Here it is..

It won't do much unless you have this particular type of GPS that outputs the wierd data.. I captured some as a text file(which it is not).

Attached is a zip file with

1. shorter program files (Less the LST - it was too big)
2. the 16F88 include file I use

TG

mister_e
- 8th March 2005, 06:51
probably i'm getting older and need to sleep after only 22 hours awake but, i can't see why it's not working. I really suspect an hardware problem now. 0.1 uF ceramic Capacitor close to the PIC.

i didn't get any compile error with the select case stuff.

did you install the PBP patch for the F88???

Here's the patch (http://www.melabs.com/downloads/P245A1.EXE)

about the calculation what about if you skip the hexa to decimal and do like Bruce propose few post ago!!!

Tom Gonser
- 8th March 2005, 07:03
Thanks.. I'll try the patch and see what happens. Is the CAP from Gnd - + close to the V+ pin? I have nothing there.

What post about skipping the Hex conv? I don't see that post in this thread.

TG

Tom Gonser
- 8th March 2005, 07:10
Odd.. that patch does not work for me. It says the 16F88 file is an "unknown version"...

mister_e
- 8th March 2005, 07:16
hhhhhhhhhhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa So you don't have the PBP 2.45!!!! probably the main cause of all your problem. OR if you have V2.45, remove it, reboot your system in 'safe mode', reinstall everything, and after that install the patch. everything should be done in a shell environement.

start>> all programs>> accesories>> command prompt

AND yes the capacitor must be place between 5 volt and ground as close as you can to the PIC.

mister_e
- 8th March 2005, 07:19
What post about skipping the Hex conv? I don't see that post in this thread.

TG

i thought it was on this post... sorry

there you go (http://www.picbasic.co.uk/forum/showthread.php?t=1351&page=2&pp=5)

Tom Gonser
- 8th March 2005, 14:22
Hmmm.. Reinstalling PBP is just copying files to a folder I thought. I think I need to do this, but am not sure exactly how to 'deinstall'. PBP does not show up in WinXP as a program that has a de-installer. I can move them out of a folder, restart, then put them back, but I don't see what that would do.

Also, I think the 16F88.bas file is corrupt because the installer tries to update it, but says it fails because of an unknown version of that 16f88.bas.... This is probably the reason for the odd behaviour.

I'll ping MELABS..

Thanks for all your help!

Tom

Tom Gonser
- 9th March 2005, 04:05
Thanks folks!! The pesky (and cool) 16F88 gave up the ghost, and is computing math right!! I re-installed PBP, updated the 16F88.INC files, and reduced program space to 3000 from 4200. I DID have to struggle with the _CONFIG settings a bit, finally dupmping the .INC files in favor of putting it in the code after the @...

[but] The ONLY thing that remains is an odd thing... My 'Onetime' routine does not appear to 'take'... I WANT it to go the the routine 'Onetime', and output data on the various serouts.. sort of a 'welcome' for 5 seconds.. What they DO is 'flash' super fast, and then disappear. Then the main program loop starts and things work fine..

This is the LAST issue with this port! Is the fact I was running at 4mhz on the other unit an issue? I have the following OSC flags:

DEFINE OSC 8
OSCCON=%01111000 '8 Mhz
CMCON = 7 'turn comparators off
ANSEL = 0 'All digital


A section of the program follows:

....

Init:

PORTA = %00000 'Initialize PortA to all zeros - all output
TRISA = %00000 'All port A output

PORTB = %00000010 'Initialize PortB
TRISB = %00000010 'Port 2 input

' -----[ Main Code ]-------------------------------------------------------

Gosub Onetime

Menu:' ****** [Main Program Loop] ************************************************** ***************
gosub counter ' main counter routine
gosub getdata ' go get data
gosub calcvalue ' calculate values
gosub displayit ' display information
if wp > 10 then
gosub waypoint
endif

goto menu

'************************************************* ************************************************
'************************* [First Screen] *****************
Onetime:
wp= 0
serout2 Apinout, 16468, [I,CLR]
serout2 Apinout, 16468, [I,L1_C1]
serout2 Apinout, 16468, [" MicroTracker"]
serout2 Apinout, 16468, [I,L2_C1]
serout2 Apinout, 16468, ["(C)05 GPSFlight"]

serout2 AGPSout, 16572,[27,91,50,74] ' clear screen vt-100
serout2 AGPSout, 16572,[27,91,#10,59,#10,72] ' 10 th row, 10 column
serout2 AGPSout, 16572,["GPSFlight MicroTracker"]
serout2 AGPSout, 16572,[27,91,#12,59,#3,72] ' 5 th row, 3rd column
serout2 AGPSout, 16572,["GPS Waypoint Port 4800-8-1-n"]
serout2 AGPSout, 16572,[27,91,#13,59,#3,72] ' 5 th row, 3rd column
serout2 AGPSout, 16572,["Connect GPS to this port to recieve waypoints"]

serout2 cpinout, 84,[27,91,50,74] ' clear screen vt-100
serout2 cpinout, 84,[27,91,53,59,51,72] ' 5 th row, 3rd column
serout2 cpinout, 84,["GPSFlign MicroTracker (C) 2005 GPSFlight, Inc.",10, 13]

serout2 AGPSout, 16572,[27,91,50,74] ' clear screen vt-100
serout2 cpinout, 84,[27,91,50,74] ' clear screen vt-100
Pause 5000
Return

Kaya Onur
- 6th February 2011, 08:38
There are many options here… so here‘s just one of them…

1. Ensure that your Device Oscillator Configuration Bits are set to INTRC_OSC_NOCLKOUT (if you don’t know how to do this, see the new FAQ section).

Hi everybody, I have just started to learn about pic programming. My searches through Google end up in this forum most of the time.

Could you please guide me to this FAQ section mentioned? I tried every FAQ link on the pages but I am unable to find the correct one which will take me to the place where this INTRC_OSC_NOCLKOUT and other options are explained.

Thanks.

mackrackit
- 6th February 2011, 09:00
I think this is what you are looking for
http://www.picbasic.co.uk/forum/showthread.php?t=543

Kaya Onur
- 6th February 2011, 09:10
I think this is what you are looking for
http://www.picbasic.co.uk/forum/showthread.php?t=543

It is! Thank you.