PDA

View Full Version : 'DEFINE OSC 8' seems to be ignored by PBP ?



mr.sneezy
- 24th May 2010, 11:20
I must have kicked a big black cat recently, my project is going from bug to bug like I've never had before.

My current minor quirk is that on a PIC 18F1220 I'm finding my Pause statements run at double speed with a 8Mhz internal clock even though I set Define OSC 8 in the top of my code.
If I set the Internal clock to run at 4Mhz and Define OSC my timing is OK. Leaving the clock source at 4Mhz and setting PBP Define to 8Mhz has no effect on program speed. I'd have expected a pause to go double the time length like that...

I did an extra test and set Define OSC 16... Nope the pause statement (a LED flash) took the same time as with Define OSC 8 (or 4).

Is there a condition where things like pause and serial PBP statements don't use the Define OSC X statement ?

Acetronics2
- 24th May 2010, 15:08
Hi,

Could you provide your full piece of code ??? ( configs included )

Alain

Charles Linquis
- 25th May 2010, 04:12
The DEFINES are case-sensitive, and are not checked for syntax by the compiler. If you don't have it typed perfectly, it will be ignored.

mr.sneezy
- 25th May 2010, 05:46
The DEFINES are case-sensitive, and are not checked for syntax by the compiler. If you don't have it typed perfectly, it will be ignored.Thanks.
I changed the case to all upper and I did get a change in the compiler so my lower case must have been a problem.

I now get an assembler Config directive warning
Config Directive Error: (setting '8' not found for the processor 18F1220)

mackrackit
- 25th May 2010, 09:24
Must be those new fangled configs :rolleyes:

Sounds like you may have an @ someplace where it should not be.
Oh, and see post 2 :)

mr.sneezy
- 25th May 2010, 11:05
OK, here is my code warts and all, please excuse any spelling errors etc as this is a work in progress.
In this form the code compiles and runs fine, but if I un-remark the DEFINE OSC 8 line I get that compile error. At the moment I'm running at 4Mhz on the PIC.


'************************************************* *****************************
'MR.SNEEZY - test code for FrSky using Bosch BMP085 baro sensor.
'This version is for PIC 18F1220
'
'ADD/Do
'
'NOTES -
'
'LAST ACTION - scratch my head...
'
'PIC 18F1220 port/pin alocations
'-------------------------------
'PortA.0/Pin 1 = Serial TX
'PortA.1/Pin 2 = LED
'PortB.0/Pin 8 = I2C SCL clock
'PortB.1/Pin 9 = I2C SDA data

'-----------------------
' PIC Defines
' ===========
'Config bits

'Config1H register
@ CONFIG OSC=INTIO2
' Oscillator switch OFF
'
'Config2L register
@ CONFIG BOR=ON, PWRT=ON, BORV=27
' Brown out reset ON @ 2.7Volts
' Power-up timer ON
'
'Config2H register
@ CONFIG WDT=ON
' Watch dog timer ON
'
'Config3H register
@ CONFIG MCLRE=OFF
'Reset pin disabled
'
'Config4L register
@ CONFIG STVR=ON, LVP=OFF, DEBUG=OFF
' Stack over/underflow ON
' Low Voltage programming OFF
' Background debugger OFF

' Include "modedefs.bas" ' Include serial modes

' DEFINE OSC 8 '8Mhz clock used. Note - Set PIC config fuses on programmer to use Internal RC OSC

' Define some constants if needed

' Software Defines (variables and pins)
Cal_table var word[11] '11 word array to store calibration data
lUpres var long
lTemp_Var var Long
Temp_Var var byte 'temp variable
Temp_Var2 var Word 'temp variable
Temp_Var3 var word 'temp variable
UTemp var word 'uncompensated temp reading
UPres var word 'uncompensated pressure reading
i2c_Reg var Byte 'variable for target i2c register address

CPIN var PortB.0 ' I2C clock pin
DPIN var PortB.1 ' I2C data pin
SO Var PortA.0 'Serial out pin
LED var PortA.1 'Indicator LED, via 500ohm to +3.3V

'Alias's for calibration data in the sensor to match the Bosch parameter list names
AC1 var Cal_table[0] '
AC2 var Cal_table[1] 'BMP085 has 11 16bit values stored in EEPROM
AC3 var Cal_table[2] 'First byte is at $AA last at $BF, two bytes per cal value
AC4 var Cal_table[3] 'Lowbyte is MSB (e.g $AA), Highbyte is LSB (e.g. $AB)
AC5 var Cal_table[4] 'some values are signed (not AC4, AC5, AC6)
AC6 var Cal_table[5]
B1 var Cal_table[6]
B2 var Cal_table[7]
MB var Cal_table[8]
MC var Cal_table[9]
MD var Cal_table[10]

' Initialise Processor - check for each PIC type
' --------------------
ADCON1 = %11111111 'Turn off all AD's
OSCCON = OSCCON | %01100000 'set INTRC to 4 MHZ
' OSCCON = OSCCON | %01110000 'set INTRC to 8 MHZ
' OSCTUNE = 0 'OSC trim set to Null

' Set initial state of port pins as Input or Output

TRISA = %11111100 'Input(0 = output, 1 = Input)
TRISB = %11111100 '

' PIC initialization code
Low So 'Must start low, or you get rubbish on the LCD at PIC boot up.
Low LED 'LED on
pause 5000 'led on for x seconds
High LED 'LED off

Serout2 SO,16780,[$FE,$01] ' Clear LCD & home LCD cursor.
pause 10 ' wait for LCD to catch up
Serout2 SO,16780,[" FrSky Vario "] ' Serial print
Serout2 SO,16780,[$FE,$C0] ' Shift cursor to line2
Serout2 SO,16780,[" Development Jig "] ' Serial print
Pause 3000 'wait three seconds

i2c_Reg =$AA 'Start address of the BMP085 calibration data
I2CREAD DPIN,CPIN,$EF,I2C_REG,[STR Cal_table\11],cal_error 'Read 11 reversed words out of sensor

AC1 = (AC1.lowbyte<<8) + AC1.highbyte 'swap MSB and LSB of each to use in PBP (un-reverse then)
AC2 = (AC2.lowbyte<<8) + AC2.highbyte 'device stores the MSB in the Low byte, LSB in the High byte
AC3 = (AC3.lowbyte<<8) + AC3.highbyte
AC4 = (AC4.lowbyte<<8) + AC4.highbyte
AC5 = (AC5.lowbyte<<8) + AC5.highbyte
AC6 = (AC6.lowbyte<<8) + AC6.highbyte
B1 = (B1.lowbyte<<8) + B1.highbyte
B2 = (B2.lowbyte<<8) + B2.highbyte
MB = (MB.lowbyte<<8) + MB.highbyte
MC = (MC.lowbyte<<8) + MC.highbyte
MD = (MD.lowbyte<<8) + MD.highbyte

Serout2 SO,16780,[$FE,$01] ' Clear LCD & home LCD cursor.
Pause 10 ' wait for LCD to catch up
'Main loop -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Main:
Serout2 SO,16780,[$FE,$02] 'home LCD cursor.

Gosub Read_temp

lTemp_var = 0
For Temp_var = 0 to 9
Gosub Read_pres
lTemp_var = ltemp_var + lUpres
Next Temp_var
lUpres = lTemp_Var / 10

Serout2 SO,16780,["UT=",DEC utemp," "] 'Send Word size number to LCD
Serout2 SO,16780,["UP=",DEC lupres," "] 'Send Word size number to LCD

'lets see whats in the cal data array for a checking math in Excel - Rem out Utemp and lUpres above
' Serout2 SO,16780,[$FE,$2] ' Shift cursor to line_1 (128+addr) Note-Rem out Utemp and lUpres above
' Serout2 SO,16780,[SDEC AC1," ",SDEC AC2," ",SDEC AC3] 'display three signed cal values
Serout2 SO,16780,[$FE,$C0] ' Shift cursor to line_2
Serout2 SO,16780,[DEC AC4," ",DEC AC5," ",DEC AC6] 'display three unsigned cal values
Serout2 SO,16780,[$FE,$94] ' Shift cursor to line_3
Serout2 SO,16780,[SDEC B1," ",SDEC B2] 'display two signed cal values
Serout2 SO,16780,[$FE,$D4] ' Shift cursor to line_4
Serout2 SO,16780,[SDEC MB," ",SDEC MC," ",SDEC MD] 'display three signed cal values
' pause 100
Toggle LED
Goto main

'SUBROUTINES -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Read_pres:

i2c_Reg = $F4 '$F4 is the control register address
I2CWRITE DPIN,CPIN,$EE,I2C_REG,[$F4] ' Write $34+(oss << 6) to set pressure conversion
Pause 30 ' Delay 10ms after each write (30mS for HiRes results (oss=3))
i2c_Reg = $F6 '$F6 is the result register MSB
I2CREAD DPIN,CPIN,$EF,I2C_REG,[lUpres],I2C_error 'Read pressure MSB, LSB, XLSB, $F9(not needed).
lUpres = lUpres >> 13 'remove result from $F9 (>>8) + left shift result back to 19bits (>>5)
'it's because PBP reads four bytes if [Var] is a long...
return 'we only want top 19bits of the result.

Read_temp:
i2c_Reg = $F4 '$F4 is the control register address
I2CWRITE DPIN,CPIN,$EE,I2C_REG,[$2E] ' Write $2E to set temperature conversion
Pause 10 ' Delay 10ms after each write
i2c_Reg = $F6 '$F6 is the result register MSB
I2CREAD DPIN,CPIN,$EF,I2C_REG,[Utemp],I2C_error 'Read temperature MSB, LSB.
return

I2C_error:
Serout2 SO,16780,[$FE,$01] ' Clear LCD & home LCD cursor.
Pause 10 ' wait for LCD to catch up
Serout2 SO,16780,["i2c bus read error"] '
pause 2000
Toggle LED
Goto main

Cal_error:
Serout2 SO,16780,[$FE,$01] ' Clear LCD & home LCD cursor.
Pause 10
Serout2 SO,16780,["i2c cal read error "] '

End


I'll probably cross post this code on the BMP085 thread tomorrow when I go down the hill (literally) and prove if my pressure reading agrees with my GPS altitude.

mackrackit
- 25th May 2010, 11:45
I do not see where the problem is. So I must be missing something too.

I am concerned about the note stating something about setting the OSC config in the programmer. Seems like that gives a lot of folks trouble. Can you shut that part down? It is not needed.

Acetronics2
- 25th May 2010, 12:30
Could you try those lines ???





@ Errorlevel -306

'-----------------------
' PIC Defines
' ===========
'Config bits

@ __CONFIG _CONFIG1H, _IESO_OFF_1H & _FSCM_OFF_1H & _INTIO2_OSC_1H
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_27_2L
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_32K_2H
@ __CONFIG _CONFIG3H, _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVR_OFF_4L
@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
@ __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H

' Include "modedefs.bas" ' Include serial modes
' DEFINE OSC 8 '8Mhz clock used. Note - Set PIC config fuses on programmer to use Internal RC OSC
' Define some constants if needed

....
....


' Initialise Processor - check for each PIC type
' --------------------
ADCON1 = %11111111 'Turn off all AD's
OSCCON = %01100111 'set INTRC to 4 MHZ <<< I Think the error was here : define directly bits without ANY ORing ...
' OSCCON = %01110111 'set INTRC to 8 MHZ
' OSCTUNE = 0 'OSC trim set to Null



and comment your configs ... ( I cut and pasted from an old 1320 program of mine ... as you see I never believe in defaults !!! )

your OSCCON settings ... mmmhhhh, how to say, ... I do not like them !!!!

Alain

mr.sneezy
- 25th May 2010, 13:22
I do not see where the problem is. So I must be missing something too.

I am concerned about the note stating something about setting the OSC config in the programmer. Seems like that gives a lot of folks trouble. Can you shut that part down? It is not needed.Sorry, that was a wort, an unused hangover from the last program I wrote. Not needed or done with this PIC. (12F629's were giving trouble...)

mr.sneezy
- 25th May 2010, 13:38
Could you try those lines ???





@ Errorlevel -306

'-----------------------
' PIC Defines
' ===========
'Config bits

@ __CONFIG _CONFIG1H, _IESO_OFF_1H & _FSCM_OFF_1H & _INTIO2_OSC_1H
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_27_2L
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_32K_2H
@ __CONFIG _CONFIG3H, _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVR_OFF_4L
@ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
@ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
@ __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
@ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
@ __CONFIG _CONFIG7H, _EBTRB_OFF_7H

' Include "modedefs.bas" ' Include serial modes
' DEFINE OSC 8 '8Mhz clock used. Note - Set PIC config fuses on programmer to use Internal RC OSC
' Define some constants if needed

....
....


' Initialise Processor - check for each PIC type
' --------------------
ADCON1 = %11111111 'Turn off all AD's
OSCCON = %01100111 'set INTRC to 4 MHZ <<< I Think the error was here : define directly bits without ANY ORing ...
' OSCCON = %01110111 'set INTRC to 8 MHZ
' OSCTUNE = 0 'OSC trim set to Null



and comment your configs ... ( I cut and pasted from an old 1320 program of mine ... as you see I never believe in defaults !!! )

your OSCCON settings ... mmmhhhh, how to say, ... I do not like them !!!!

Alain
OK, we have success.

Your @ _Config text compiles with no errors. I also confirmed that my code slowed down as expected if there was a mismatch of DEFINE and OSC settings... All good.

Your OSCCON works too, but so does mine. Interesting, I read in another forum that the OR'd method was good because it allowed the other bits to not be altered. Maybe I misinterpreted when or why this was good.

So, anybody understand why the preferred Microchip config method gave me an error ?

Acetronics2
- 25th May 2010, 14:06
So, anybody understand why the preferred Microchip config method gave me an error ?

Like I was telling a friend of mine called ..." Skimask " ... ( coughing sounds around ??? Why ??? ) :eek:

"As a pilot, you know it works well and will not try to see if other ways could have been working ... :D

may be it is just a very little thing ... but I want to have an in-deep look before telling anything ...;)

BTW: do you have any link to this " new config way " ???

Alain

mackrackit
- 25th May 2010, 14:08
So, anybody understand why the preferred Microchip config method gave me an error ?
Nope, I do not understand it but there are lots of things I do not understand. I just know that the new way does not work well for me when I tried it a time or two so I figure why fight it. Use the way that has worked for years.

Maybe it is something for a later version of MPASM?

Acetronics2
- 25th May 2010, 14:47
Hi, Dave

Just found µChip writes :



@ CONFIG BOR = ON, PWRT = ON, BORV = 27



With spaces around " = " sign ...

too weak to give a decent conclusion... ;)

BTW ... I found a nice tool in the MPLAB Help ... Config values tables for the 18x series !!!
but none for 10,12 and 16 Series

Alain

mackrackit
- 25th May 2010, 15:13
Thanks Alain.
I will give it a try later. But as you mentioned to our masked friend.
If it is not broke do not try fixing it. :)

Looks like a cleaner way though...

Bruce
- 25th May 2010, 17:11
The new style config directives can't be inserted directly into your code. These only
work when in the default PBP device include files.

See post #3 in this thread; http://www.picbasic.co.uk/forum/showthread.php?t=9145&

Acetronics2
- 25th May 2010, 17:35
Hi, Bruce,

Thanks for the tip ...

[Humour ON]

So, If I understand it well ... ;)

When we want non-defaults Configs through PbP, we have to comment the .inc relevant lines ...

And if we want to use the new configs with PbP, we have to re-install them into those .inc files ...

Did I get It correctly ??? :D

[Humour OFF]

Regards
Alain

mackrackit
- 25th May 2010, 17:46
Thanks Bruce!
I like the configs in code space so it looks like the old way is the way for now.

mr.sneezy
- 26th May 2010, 07:40
Thanks Bruce!
I like the configs in code space so it looks like the old way is the way for now.
FWIW I like it in my code space too, I miss enough stuff now without hiding more info in INCs. So I guess it's the _config method for a while longer :-)
Martin

mr.sneezy
- 26th May 2010, 11:50
BTW: do you have any link to this " new config way " ???

AlainAlain, I just read the detailed comments right out of the bottom of the 18F1220.INC out of my late installation of MPASM. It list's the config 'directives' for both methods, but says we should be using the new type syntax...

Martin