PDA

View Full Version : How to check oscillator frequency



Johan
- 10th July 2007, 11:59
Hi all,

I'd like to know how to check that the osccilator is working as requested. I mean how do I know exactly that the external crystal is working at 8 Mhz

I made some experiment with 18F4431, the program run well with internal oscilator setup 4Mhz, but it does not function when I switch to external crystal
I am using easypic 4 board.

Thanks,

Johan

skimask
- 10th July 2007, 16:30
Hi all,
I'd like to know how to check that the osccilator is working as requested. I mean how do I know exactly that the external crystal is working at 8 Mhz
I made some experiment with 18F4431, the program run well with internal oscilator setup 4Mhz, but it does not function when I switch to external crystal
I am using easypic 4 board.
Thanks,
Johan

Are you sure the config bits are set correctly in your program?

Johan
- 11th July 2007, 03:26
What config bits needed to set up ?
This is my test program , please correct if it is not correct:

\code
TRISA = %11111111 ' Set PORTA to all input
TRISB = %00000000 ' Set PORTB to all output
TRISC = %00000000 ' Set PORTC to all input
TRISD = %00000000 ' Set PORTD to all output
TRISE = %00000000 ' Set PORTE to all output
ANSEL0= %00000000 ' Analog channel AN0-AN7 off
ANSEL1= %00000000 ' Analog channel AN8 off

clear

main:
high portb.1
pause 1000
low portb.1
pause 1000
goto main

\code

the oscillator setting during programming with picflash is:
oscillator : int ra6 & ra7 as i/o
other setting left unchanged

thanks

mister_e
- 11th July 2007, 05:40
yeah... it run but the default OSC speed is set to 32KHz :eek:

just add those

OSCCON= %01100000 ' configure internal OSC @ 4MHZ
While OSCCON.2=0 : wend ' wait until OSC is stable
at the top of your code.

For the configuration bits, it's usual and recommended to set them in your code, have a look at the following...

http://www.picbasic.co.uk/forum/showthread.php?t=543

and here's a short example for a 18F2431, as inspiration source ;)



'
' Pic Configuration
' =================
ASM
__CONFIG _CONFIG1H, _OSC_IRCIO_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_ON_2L & _BORV_45_2L
__CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WINEN_OFF_2H
__CONFIG _CONFIG3L, _T1OSCMX_OFF_3L & _HPOL_LOW_3L & _LPOL_HIGH_3L & _PWMPIN_OFF_3L
__CONFIG _CONFIG3H, _MCLRE_ON_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L
ENDASM
DEFINE OSC 4

Now if you want to switch to the external OSC, use...


ASM
__CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_ON_2L & _BORV_45_2L
__CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WINEN_OFF_2H
__CONFIG _CONFIG3L, _T1OSCMX_OFF_3L & _HPOL_LOW_3L & _LPOL_HIGH_3L & _PWMPIN_OFF_3L
__CONFIG _CONFIG3H, _MCLRE_ON_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L
ENDASM
DEFINE OSC 8
and remove the OSCCON & WHILE : WEND lines

Johan
- 11th July 2007, 06:16
Thank you Mr.E,

On my programmer's setup page ( easypic ) there are configuration bits to setup ( see attachment ) . If I put the configuration at PBP, will this be a problem ?

mister_e
- 11th July 2007, 06:37
Nope, there's no problem at all. In fact, if you set the bits in your code, you'll no longer need to set them in Picflash as they're now included in the .HEX file.

Try the above, a click on 'Reload HEX'. You'll see that the Oscillator bit have change to HS or INT RC... depending which code above you have used.

I also have that board. Can't live without now :D

Johan
- 11th July 2007, 09:17
Mr.E,

I tried to put those asm lines, and got error messages :
Error 118 bla,bla,bla : Overwriting previous address content

But my problem is solved just by adding : define OSC 8 :)

mister_e
- 12th July 2007, 01:06
Yeah, but it seems you didn't read the first link i sent?

Read it (from post #1 to at least #5), and you'll know why it happen, and how to solve it.

Johan
- 12th July 2007, 03:50
Hi Steve,

I did read the posts and "still" try to understand it.
I forgot to mention that I use MPASM 5.03 assembler, because PM does not have inc file for 18F4431 ( or does it ? )

Melanie said :
3.b. When using Microchip's (MPASM) Assembler

If you're going to use MPASM, look for the appropriate file (example for a 16F628 look for P16F628.INC) located in something like the MCHIP_Tools subdirectory of your MPLAB installation. Here you’ll find the Configuration Bits located near the bottom of the list. Simply just use the ones you want. Hey presto your PIC is all defined and ready to run.

But how ? I am new to PBP, please help :)


Thanks,

Johan

skimask
- 12th July 2007, 11:46
I did read the posts and "still" try to understand it.
Old version. Latest is 5.11. Download MPLAB IDE v 7.61 (maybe 7.62 by now)


I forgot to mention that I use MPASM 5.03 assembler, because PM does not have inc file for 18F4431 ( or does it ? )
PM does NOT support 18Fxxxx.


Melanie said :
3.b. When using Microchip's (MPASM) Assembler
If you're going to use MPASM, look for the appropriate file (example for a 16F628 look for P16F628.INC) located in something like the MCHIP_Tools subdirectory of your MPLAB installation. Here you’ll find the Configuration Bits located near the bottom of the list. Simply just use the ones you want. Hey presto your PIC is all defined and ready to run.
But how ? I am new to PBP, please help :)

Edit the file using WORDPAD, NOTEPAD, or any other pad you can find, comment out the config bits you're NOT wanting and un-comment the rest.

mister_e
- 12th July 2007, 19:23
http://www.picbasic.co.uk/forum/showthread.php?t=543
<body onload="setInterval('blinkIt()',1000)">

<script type="text/javascript">
function blinkIt() {
if (!document.all) return;
else {
for(i=0;i<document.all.tags('blink').length;i++){
s=document.all.tags('blink')[i];
s.style.visibility=(s.style.visibility=='visible') ?'hidden':'visible';
}
}
}
</script>

<blink>POST #5</blink>
http://www.picbasic.co.uk/forum/showpost.php?p=6775&postcount=5



;************************************************* ***************
;* 18F4431.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2006 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 06/05/06 *
;* Version : 2.47 *
;* Notes : *
;************************************************* ***************
NOLIST
ifdef PM_USED
LIST
"Error: PM does not support this device. Use MPASM."
NOLIST
else
LIST
LIST p = 18F4431, r = dec, w = -311, w = -230, f = inhx32
INCLUDE "P18F4431.INC" ; MPASM Header
<BLINK> ;__CONFIG _CONFIG1H, _OSC_XT_1H
;__CONFIG _CONFIG2H, _WDTEN_ON_2H & _WDPS_512_2H
;__CONFIG _CONFIG4L, _LVP_OFF_4L</BLINK>
NOLIST
endif
LIST
EEPROM_START EQU 0F00000h
BLOCK_SIZE EQU 8


;)

Johan
- 13th July 2007, 08:36
Mr. E,
This is really confusing :)

I dont have 18F4431.INC on my PBP folder that you suggested to modify :
http://www.picbasic.co.uk/forum/show...75&postcount=5

But I can find 18F4431.INC on MPASM directory
Shall I copy & paste INC file from MPASM directory to PBP directory and edit it ?

Skimask: I have installed the new MPASM as you suggested\


Johan

mister_e
- 13th July 2007, 23:55
Sure you MUST have that file in the C:\PBP folder unless it wouldn't compile at all. Unfortunately, the one in MPASM Suite folder won't help. The one in MPASM folder DEFINE the PIC registers, Bits, Configuration bits etc etc etc. But, you could still create one using the one i posted above and save it to C:\PBP folder.

Johan
- 14th July 2007, 14:43
Thanks Steve,
It was my mistake , I looked at C:PBP\INC folder instead of C:PBP, that's why I never found the 18F4431.INC file.

Now, it it configured as your suggestion, and it works ( The Configuration bits on Picflash changed as well , save me some clicks, thanks )

One more thing, I 'd like to know more about HS PLL mode ( Datasheet 2.3 ). Suppose I want to use external 8 Mhz crystal to produce 32 Mhz clock, what settings are required ?



Johan

mister_e
- 14th July 2007, 15:23
;----- CONFIG1H Options --------------------------------------------------
_OSC_LP_1H EQU H'F0' ; LP
_OSC_XT_1H EQU H'F1' ; XT
_OSC_HS_1H EQU H'F2' ; HS
_OSC_RC2_1H EQU H'F3' ; External RC, RA6 is CLKOUT
_OSC_EC_1H EQU H'F4' ; EC, RA6 is CLKOUT
_OSC_ECIO_1H EQU H'F5' ; EC, RA6 is I/O
_OSC_HSPLL_1H EQU H'F6' ; HS-PLL Enabled
_OSC_RCIO_1H EQU H'F7' ; External RC, RA6 is I/O
_OSC_IRCIO_1H EQU H'F8' ; Internal RC, RA6 & RA7 are I/O
_OSC_IRC_1H EQU H'F9' ; Internal RC, RA6 is CLKOUT, RA7 is I/O
_OSC_RC1_1H EQU H'FB' ; External RC, RA6 is CLKOUT
_OSC_RC_1H EQU H'FF' ; External RC, RA6 is CLKOUT

_FCMEN_OFF_1H EQU H'BF' ; Disabled
_FCMEN_ON_1H EQU H'FF' ; Enabled

_IESO_OFF_1H EQU H'7F' ; Disabled
_IESO_ON_1H EQU H'FF' ; Enabled


i bet on...


'
' Pic Configuration
' =================
ASM
__CONFIG _CONFIG1H, _OSC_HSPLL_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_ON_2L & _BORV_45_2L
__CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WINEN_OFF_2H
__CONFIG _CONFIG3L, _T1OSCMX_OFF_3L & _HPOL_LOW_3L & _LPOL_HIGH_3L & _PWMPIN_OFF_3L
__CONFIG _CONFIG3H, _MCLRE_ON_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L
ENDASM
DEFINE OSC 32