PDA

View Full Version : Config & Oscon settings 16F1825



retepsnikrep
- 16th September 2011, 19:46
I'm migrating from my trusty 12F683 to a 16F1825 and am confused by the config and oscon settings. I'm using PBP3 of course ;)

With 12F683 I have the following.



#config
__config _FCMEN_ON & _IESO_ON & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTOSCIO
#ENDCONFIG

OSCCON = 01110101 'Sets internal osc to 8 Mhz (Default) and stable



I just want to make that work with the 16F1825 but using the 16mhz int oscilator. I don't need anything fancy. I appreciate the 16F1825 has two config words.

I was thinking something like



#config
__CONFIG _CONFIG1, _FCMEN_ON & _IESO_ON & _FOSC_INTOSC & _WDTE_SWDTEN & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF
__CONFIG _CONFIG2, _LVP_OFF
#ENDCONFIG


Does the config need to be in CAPITALS? Does the above look comparable to what I have for the 12F683.

With the Oscon reg I'm very confused and am reading the datasheet. I just want it to run at 16mhz on the into osc but all the other settings are making my brainhurt!

I'm also confused about the relationship between the config words and the oscon reg PLLEN etc etc ARRGHHH!! :confused:

HankMcSpank
- 16th September 2011, 20:10
I use its larger sibling (16f1828), and have it set something like this for 16Mhz



@ __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF & _LVP_OFF
@ __CONFIG _CONFIG2, _LVP_OFF
DEFINE OSC 16
Osccon = 111010 'sets the internal oscillator to 16Mhz


Re the PLL...it confused me too, I haven't got access to the config settings I used (I certainly had it working at 32Mhz at one stage) , but the jists seems to be if you haven't got any refereence to PLLEN_ON in you config, then bit 7 of the Osccon register turns on the PLL

Edit: I don't know what's going on thereshould be a percentage sign and a leading 0 at the front of that Osccon entry...they are both disappearing when I click 'post reply'

mister_e
- 16th September 2011, 20:23
Try this

#CONFIG
__CONFIG _CONFIG1, _FCMEN_OFF & _IESO_OFF & _FOSC_INTOSC & _PLLEN_OFF & _WDTE_SWDTEN & _MCLRE_OFF & _CP_OFF & _BOREN_OFF & _PWRTE_OFF
__CONFIG _CONFIG2, _LVP_OFF
#ENDCONFIG

OSCCON = 1000
' x------- SPLLEN: don't care when _PLLEN_OFF in config fuse
' -1111--- Internal clock = 16MHz
' -----x-- Unimplemented
' ------00 System Clock Source = Determined by Config Word

DEFINE OSC 16 ' Tell PBP we use a 16MHz Clock
MPASM is case sensitive, IF the config are not in capital you'll receive some Symbol not previously defined error message.

EDIT: Yup, there should indeed have a percent sign ... Looks like the new vBulletin have new "Features"

Above the above OSCCON should be
OSCCON = % 01111000
without the space between percent signe and the first 0

mister_e
- 16th September 2011, 20:34
Out to do more test in the test area...

mister_e
- 16th September 2011, 20:54
last test, sorry ....


#CONFIG
__CONFIG _CONFIG1, _FCMEN_OFF & _IESO_OFF & _FOSC_INTOSC & _PLLEN_OFF & _WDTE_SWDTEN & _MCLRE_OFF & _CP_OFF & _BOREN_OFF & _PWRTE_OFF
__CONFIG _CONFIG2, _LVP_OFF
#ENDCONFIG

OSCCON = %01111000
' x------- SPLLEN: don't care when _PLLEN_OFF in config fuse
' -1111--- Internal clock = 16MHz
' -----x-- Unimplemented
' ------00 System Clock Source = Determined by Config Word

DEFINE OSC 16 ' Tell PBP we use a 16MHz Clock



Was ok the first time I posted it, messed when use the QuickEdit... so before posting it again, I switched to Advanced Moxe...paste the code again and we're up! Damn ;)

n0yox
- 8th July 2020, 20:07
I am trying to use a 16f1847 and can not get it to blink an led I am sure this is a config problem but just can't make it work. this is my config and blink program below.

Thanks!


;----[16LF1847 Hardware Configuration]------------------------------------------
#IF __PROCESSOR__ = "16LF1847"
#DEFINE MCU_FOUND 1
#CONFIG
cfg1 = _FOSC_INTOSC ; INTOSC oscillator: I/O function on CLKIN pin
cfg1&= _WDTE_ON ; WDT enabled
cfg1&= _PWRTE_OFF ; PWRT disabled
cfg1&= _MCLRE_OFF ; MCLR/VPP pin function is digital input
cfg1&= _CP_OFF ; Program memory code protection is disabled
cfg1&= _CPD_OFF ; Data memory code protection is disabled
cfg1&= _BOREN_ON ; Brown-out Reset enabled
cfg1&= _CLKOUTEN_OFF ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
cfg1&= _IESO_ON ; Internal/External Switchover mode is enabled
cfg1&= _FCMEN_ON ; Fail-Safe Clock Monitor is enabled
__CONFIG _CONFIG1, cfg1

cfg2 = _WRT_OFF ; Write protection off
cfg2&= _PLLEN_OFF ; 4x PLL disabled
cfg2&= _STVREN_ON ; Stack Overflow or Underflow will cause a Reset
cfg2&= _BORV_19 ; Brown-out Reset Voltage (Vbor), low trip point selected.
cfg2&= _LVP_OFF ; High-voltage on MCLR/VPP must be used for programming
__CONFIG _CONFIG2, cfg2

#ENDCONFIG

#ENDIF

#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF

OSCCON = %00001111
ADCON1 = %11111111 'PROBABLY NOT RIGHT??
ANSELA = 0 'PROBABLY NOT RIGHT??

MainLoop:

LED VAR PORTA.0
LED2 VAR PORTA.0
HighLED
High LED2
Pause 500
Low LED
Low LED2
Pause 500
Goto MainLoop

mpgmike
- 8th July 2020, 22:08
Just a casual observation; you're posting to a 9 year old thread instead of starting your own. In this 9 year old thread you can plainly see the working examples listed in previous posts:



#CONFIG __CONFIG _CONFIG1, _FCMEN_OFF & _IESO_OFF & _FOSC_INTOSC & _PLLEN_OFF & _WDTE_SWDTEN & _MCLRE_OFF & _CP_OFF & _BOREN_OFF & _PWRTE_OFF __CONFIG _CONFIG2, _LVP_OFF #ENDCONFIG
You list your own thing and wonder why it doesn't work for you. Am I being overly critical?!?

n0yox
- 9th July 2020, 17:18
This fixed my problem. I did not notice I had ticked 16fl1847 not 16f1847 in MeConfig . I changed "OSCCON = %11100000" to "OSCCON = %01110000" and added "DEFINE OSC 8". I am glad I figured it out before anyone answered.




;----[16F1847 Hardware Configuration] From MeConfig--------------------------
#IF __PROCESSOR__ = "16F1847"
#DEFINE MCU_FOUND 1
#CONFIG
cfg1 = _FOSC_INTOSC ; INTOSC oscillator: I/O function on CLKIN pin
cfg1&= _WDTE_OFF ; WDT disabled
cfg1&= _PWRTE_OFF ; PWRT disabled
cfg1&= _MCLRE_OFF ; MCLR/VPP pin function is digital input
cfg1&= _CP_OFF ; Program memory code protection is disabled
cfg1&= _CPD_OFF ; Data memory code protection is disabled
cfg1&= _BOREN_OFF ; Brown-out Reset disabled
cfg1&= _CLKOUTEN_OFF ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
cfg1&= _IESO_OFF ; Internal/External Switchover mode is disabled
cfg1&= _FCMEN_OFF ; Fail-Safe Clock Monitor is disabled
__CONFIG _CONFIG1, cfg1

cfg2 = _WRT_OFF ; Write protection off
cfg2&= _PLLEN_OFF ; 4x PLL disabled
cfg2&= _STVREN_OFF ; Stack Overflow or Underflow will not cause a Reset
cfg2&= _BORV_HI ; Brown-out Reset Voltage (Vbor), high trip point selected.
cfg2&= _LVP_OFF ; High-voltage on MCLR/VPP must be used for programming
__CONFIG _CONFIG2, cfg2

#ENDCONFIG

#ENDIF

;----[Verify Configs have been specified for Selected Processor]----------------
; Note: Only include this routine once, after all #CONFIG blocks
#IFNDEF MCU_FOUND
#ERROR "No CONFIGs found for [" + __PROCESSOR__ +"]"
#ENDIF


ANSELA = 0 ' Turn off analog port A
ANSELB = 0 ' Turn off analog port B
CM1CON0 = 0 ' Comparators off.
CM1CON1 = 0
CM2CON0 = 0 ' Comparators off.
CM2CON1 = 0
CPSCON0 = 0 ' Capacitive sense module off.
TRISB = %00000000
OSCCON = %01110000
ADCON1 = %11111111
DEFINE OSC 8