#chip 18F1220,8
#config OSC = Int
……
Wait until SENSORon
wait SnapTiming1 us
Set COIL1 Off
Set COIL2 On
wait SnapTiming1 us
Repeat 4
wait SnapTiming1 us
End repeat
……
GCBASIC compile with a warning for each wait
Warning: Inaccurate microsecond delay due to use of variable at the current clock speed
but the clock speed is 8Mhz for this PIC not 4Mhz !
;Program compiled by Great Cow BASIC (0.9 10/9/2010)
LIST p=18F1220, r=DEC
#include <P18F1220.inc>
CONFIG LVP = OFF, MCLRE = OFF, WDT = OFF, OSC = INTIO2
What is wrong ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
With an 8MHz clock the instruction cycle time is 0.5us but the shortest decrement and loop code you can write in assembly takes 3 cycles or 1.5us so a microsecond delay controlled by a variable cannot be made microsecond accurate at that speed. There are also some cycles spent preparing to run the delay loop which adds a few microseconds to the total.
SnapTiming1 is a variable not a define I'm assuming?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you Nobody,
SnapTiming is a variable the value comes from a CCP1 handler.alias CCPR1H,CCPR1L
Do you thik 10us unit will be ok ?
Which clock speed must be choosen to be microsecond accurate ?
I suppose an external cristal will not help ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
An external crystal will help, it will be more accurate, and provide increased resolution (i.e. speedier instruction cycles) for the capture routine. I would suggest a 10Mhz crystal (18f and 4xPLL for 40Hhz), and it never hurts to have a few others around like a 20Mhz (generic purposes), and a 12Mhz (for USB). The new 18fxxKxx series allows the 4xPLL to be used on the external OSC AND the HSINTOSC, for clocking the fastest of all 8bit PICS at 16MIPS.
Here is the 18f14k22 initialized for 16Mhz INTOSC and 4xPLL (Similar steps required for other 18f series). It's been awhile and haven't checked if the HSPLL is now being handled by GCBasic? Easy enought to handle it manually, as I did in code below.
'Chip model
#chip 18lf14k22,64
#config FOSC = IRC, WDTEN=Off, PLLEN = ON ;, PCLKEN = ON
'GCBasic recognizes LATX,x as output
#define Led LATC0
#define Led1 LATC1
#define HZout LATC4 'ccp1 pin
#define HZ1out LATC5
dir PortC out 'Led's and CCP1 as output
'T1CON = b'00000000' 'Enable 16bit read/write mode operation, and T1OSC enable bit
'SET T3CCP1 OFF 'Make sure TMR1 is used as capture/compare source
CCP1CON = b'00000010' 'Compare mode, toggle output on match
'dir PortC.1 out
'dir LATC0 out
'dir LATC1 out
'set internal osc to 16mhz '111', 8mhz '110', 4mhz '101'
'GCBasic does not recognize PLL timing aspects of 4x multiplier
IRCF2=1
IRCF1=1
IRCF0=1
NotStable:
If HFIOFS=0 Then goto NotStable 'wait for HFIOSC to stablize
...
...
...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
GCBASIC config statement, and code
#chip 18F1220,8
#config OSC = Int
……
Wait until SENSORon
wait SnapTiming1 us
Set COIL1 Off
Set COIL2 On
wait SnapTiming1 us
Repeat 4
wait SnapTiming1 us
End repeat
……
GCBASIC compile with a warning for each wait
Warning: Inaccurate microsecond delay due to use of variable at the current clock speed
but the clock speed is 8Mhz for this PIC not 4Mhz !
;Program compiled by Great Cow BASIC (0.9 10/9/2010)
LIST p=18F1220, r=DEC
#include <P18F1220.inc>
CONFIG LVP = OFF, MCLRE = OFF, WDT = OFF, OSC = INTIO2
What is wrong ?
With an 8MHz clock the instruction cycle time is 0.5us but the shortest decrement and loop code you can write in assembly takes 3 cycles or 1.5us so a microsecond delay controlled by a variable cannot be made microsecond accurate at that speed. There are also some cycles spent preparing to run the delay loop which adds a few microseconds to the total.
SnapTiming1 is a variable not a define I'm assuming?
Thank you Nobody,
SnapTiming is a variable the value comes from a CCP1 handler.alias CCPR1H,CCPR1L
Do you thik 10us unit will be ok ?
Which clock speed must be choosen to be microsecond accurate ?
I suppose an external cristal will not help ?
An external crystal will help, it will be more accurate, and provide increased resolution (i.e. speedier instruction cycles) for the capture routine. I would suggest a 10Mhz crystal (18f and 4xPLL for 40Hhz), and it never hurts to have a few others around like a 20Mhz (generic purposes), and a 12Mhz (for USB). The new 18fxxKxx series allows the 4xPLL to be used on the external OSC AND the HSINTOSC, for clocking the fastest of all 8bit PICS at 16MIPS.
Here is the 18f14k22 initialized for 16Mhz INTOSC and 4xPLL (Similar steps required for other 18f series). It's been awhile and haven't checked if the HSPLL is now being handled by GCBasic? Easy enought to handle it manually, as I did in code below.