PDA

View Full Version : Configuration bits and timing



Christos_K
- 14th June 2005, 19:00
Hi! I have two questions for you experts!

1) How can I include configuration bits such us: "__config _XT_OSC & _WDT_OFF & _PWRTE _ON & _CP_OFF" to my code? I am using a PIC18F2680.

If I just enter them it produces an error. I've tried with INCLUDE "18f2680" but then it pops out the PIC18F2680.inc file and it gives me the following errors:
WARNING: Unable to open INCLUDE file P18F2680.INC.
ERROR Line 16: ELSE without a matching IF..THEN. (LEDBLINK.pbp)
ERROR Line 24: ENDIF without a matching IF..THEN. (LEDBLINK.pbp)
ERROR Line 12: Syntax error. (18F2680.INC)
ERROR Line 13: Bad parameter to LIST command. (18F2680.INC)
ERROR Line 14: Syntax error. (18F2680.INC)
ERROR Line 17: Bad parameter to LIST command. (18F2680.INC)
ERROR Line 18: Bad parameter to LIST command. (18F2680.INC)
ERROR Line 20: Syntax error. (18F2680.INC)
ERROR Line 21: Syntax error. (18F2680.INC)
ERROR Line 22: Syntax error. (18F2680.INC)
ERROR Line 25: Bad parameter to LIST command. (18F2680.INC)
ERROR Line 26: Syntax error. (18F2680.INC)
ERROR Line 27: Syntax error. (18F2680.INC)


And another question. When I am using an external oscillator what should be the value for the Oscillator configuration bit? My code is suppossed to turn on and off an LED with a pause 1000. When I use XT and LP the pause is 4 seconds while when I use HS the pause is about 400msec...What am I doing wrong? I have defined the OSC as 20 since the oscillator I am using is 22.1184MHz...

Melanie
- 15th June 2005, 02:07
There are various ways of including your CONFIG settings into an 18F series PIC... here's one...

1. Go and find the 18F2680.INC file in your PBP subdirectory.
2. Make a COPY of it and file the copy away safely as the ORIGINAL in case you need to go back to it at some time in the future.
3. Use Notepad or some similar editor and REMOVE these three lines...

__CONFIG _CONFIG1H, _OSC_XT_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
__CONFIG _CONFIG4L, _LVP_OFF_4L

4. Save the file.

Now, in your .BAS Source code, somewhere at the start of your program you can include lines like this (this is just an example and these settings may not be suitable for the P18F2680 or for your needs)...



'
' PIC Defines
' ===========

@ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _XT_OSC_1H
' Oscillator Switch-over Disabled
' Set for XT Oscillator
@ __CONFIG _CONFIG2L, _BOR_ON_2L & _PWRT_ON_2L & _BORV_42_2L
' Brown-Out Reset Enabled
' Power-On Timer Enabled
' Brown-Out Trip set to 4.2v
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
' WatchDog is ON
' Watchdog Postscaler set to 1:128
@ __CONFIG _CONFIG3H, _CCP2MX_ON_3H
' CCP2 is Multiplexed with PortC.1
@ __CONFIG _CONFIG4L, _LVP_OFF_4L
' Low-Voltage Programming is OFF
@ __CONFIG _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L & _CP2_ON_5L & _CP3_ON_5L
@ __CONFIG _CONFIG5H, _CPB_ON_5H & _CPD_ON_5H
There will be no errors and no clash with duplicate configurations which are not allowed with the MPASM compiler.

Where do you find a list of configuration definitions? Two places, cross reference BOTH... (a) The DATASHEET Section "Special Features of the CPU" and (b) the P18F2680.INC file in the MPASM Suite subdirectory of your MPLAB installation. Look towards the end of the file to find the Configuration Bits settings.

RayL113
- 15th November 2012, 16:45
I think this thread would be the right place to ask this. I have a 18F26K80 that I'm trying to turn off the A/D on the A ports.

I tried the following;
ADCON0=$00 'switch the Analogue A/D pins to Digital I/O mode.
ADCON1=$00 'switch the Analogue A/D pins to Digital I/O mode.
ADCON2=$00 .
TRISA = $FF ' set port a to all inputs ' 28
TRISB = $00 'set port b to all outputs ' 29
TRISC = $FF 'set port c to all inputs ' 30

However, the inputs on the A ports are still ignored. What am I doing wrong??
Thanks

HenrikOlsson
- 15th November 2012, 17:32
Hi,
Open up the datasheet and take a look at the ADC section - especially the ANCON register. It says:

The ANCONx registers are used to configure the operation of the I/O pin associated with each analog channel. Clearing an ANSELx bit configures the corresponding pin (ANx) to operate as a digital only I/O.

Cool device that, 12bit ADC with differential input, two internal references - hadn't noticed it before.

/Henrik.

RayL113
- 17th November 2012, 03:49
I've tried;
ANSEL = $00
ANSEL = 0
ANSEL0 = 0
and get "ERROR Line 30: Syntax error.30: Syntax error 30: Syntax error"
Any suggestions on the correct way to enter this setting in this new chip?

RayL113
- 17th November 2012, 05:06
I didn't see ANSEL in the p18f26k80.h file.
So I tried the following using the ANCON configuration registers and it seems to work;

ADCON0 = %00000000 ;P364 A/D CONTROL REGISTER 0
ADCON1 = %00000000 ;P365 A/D CONTROL REGISTER 1
ADCON2 = %00000000 ;P366 A/D CONTROL REGISTER 2
ODCON = %00000000 ;P179 PERIPHERAL OPEN-DRAIN CONTROL REGISTER
ANCON0 = %00000000 ;P369 A/D PORT CONFIGURATION REGISTER 0***
ANCON1 = %00000000 ;P369 A/D PORT CONFIGURATION REGISTER 1***
CM1CON = %00000000 ;P378 COMPARATOR CONTROL x REGISTER
CM2CON = %00000000 ;P378 COMPARATOR CONTROL x REGISTER

Thanks for pointing me in the right direction.

HenrikOlsson
- 17th November 2012, 08:53
That's because there is no ANSEL register in the 26K80. The register is called ANCONx.

/Henrik.