As I said in another thread there seems to be an unnecessary delay in the ADC.
I am now seeing what is going on. The delay between ADON being set and GO_NOT_DONE being set is the aquisition time (charging the ADC capacitor). The conversion starts when the GO_NOT_DONE is set.
Now this delay is currently set at 20us, which for most applications is far too long (the examples in the datasheet give typical values of about 2-5 us depending mainly on the input impedance).
On the 18F25K80 the aquistion time can be set in a register so there is no need for the delay introduced by GCBasic.
There also seems to be incorrect setting of the ANCON registers on the 18F25K80.
Here is the INITSYS I get
~~~~~~~
INITSYS
nop
bsf OSCCON,IRCF2,ACCESS
bsf OSCCON,IRCF1,ACCESS
bsf OSCCON,IRCF0,ACCESS
bsf OSCTUNE,PLLEN,ACCESS
clrf BSR,ACCESS
clrf TBLPTRU,ACCESS
bcf ADCON2,ADFM,ACCESS
bcf ADCON0,ADON,ACCESS
banksel ANCON0
bcf ANCON0,ANSEL0,BANKED
bcf ANCON0,ANSEL1,BANKED
bcf ANCON0,ANSEL2,BANKED
bcf ANCON0,ANSEL3,BANKED
bcf ANCON0,ANSEL4,BANKED
bcf ANCON1,ANSEL9,BANKED
bcf ANCON1,ANSEL9,BANKED
bcf ANCON1,ANSEL10,BANKED
clrf PORTA,ACCESS
clrf PORTB,ACCESS
clrf PORTC,ACCESS
clrf PORTE,ACCESS
banksel 0
return
~~~~~~~~~~
First obvious problem is ANSEL9 is set twice. The pin diagram suggest there should be 0-4,8-10 can be selected as analogue.
I am using AN0 for the ADC so ther should be a BSF ANCON0,ANSEL0 to convert this pin to analogue input.
{edited out mistakes oops!}
Last edit: David Stephenson 2017-08-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You appear to still be using an outdated version of GCB, The AD9 issue was resolved in version .97.01. (system.h).
User analog configs are not set in "initsys" They will be somewhere after BASEPROGRAMSTART. in your ASM file.
Please update to GCB .97.02, then post your entire GCB source code (BASIC and ASM) as attachments. The ASM "initsys" alone is rather meaningless for debugging.
Last edit: William Roth 2017-08-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've downloaded 97.01 (can't find 97.02).
Attached is the ASM file.
Again ANCON is not set for AN0.
The conversion clock divider is not set properly for the chip clock rate (ADCON2 bits).
Below is the test file that has been compiled.
The total time for an ADC conversion I have measured to be 22 us (so 20us for the aquisition and 2 us for the conversion)
~~~~~~
chip 18F25k80,64
config mclre=off, OSC=INTIO2, xinst=off, cpd=off
dir porta.0 in
dir portc.0 out
dim x1 as word
do
set portc.0 on
x1=readad12(an0)
set portc.0 off
wait 1 sec
loop
~~~~~~~
I have removed the hashes as this messes with the font size when posting.
"I've downloaded 97.01 (can't find 97.02)"...True,where is it? It's not here. https://sourceforge.net/projects/gcbasic/?source=typ_redirect
vorboss.dl.sourceforge.net took too long to respond.
Otherwise it's 97.01. I couldn't download latest chip files from sourceforge either,just went in a circle,it just loads a help text with a link to where I just came from.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cannot test the speed as my entire lab is packed up in preparation for a move tomorrow. After today, I will be offline for 3 or 4 days unitl I am settled in my new place. .
"Initsys" in the ASM only runs once and will have no effect on ADC speed. . The speed is mainly determined by the AD Clock & AD Delay. WIth GCB, the AD module is turned on / off with each read/ acquisition. This adds overhead and I am not sure that this is necessaery. I asked about this but have not received an answer.
The A-D.h library tries to strike a balance between reliability and speed as it must support about 600 PIC chips. It is not a failure of the library if some extra time is allowed for stability/ reliability. This does not mean it cannot be improved.
@David
It may be that for your particular application where you want every nanosecond of speed, that you will need to write your own ASM ADC code. As I read the datasheet, for reliable 12 bit reads the 18F25K80 needs an acquisition delay of 15us. However, a while back I reduced this to 10us and the readings "seemed" ok. Your mileage may vary.
It seems odd to me that a barcode reader would need to use ADC at a sampling rate of 200K samples per second. Are you sure this is the correct path for using this device?
It only requires 15us aquisition when reading the fixed Vref. During normal reading from a pin Taq will depend on the parameters listed in the datasheet (mainly impedance of the source voltage).
Yes I have written my own ASM I was merely pointing out some of the issues I had noticed in the GCB generated code such as:
the incorrect conversion clock setting (at least at 64MHz clock speed)
ANCON not being set (maybe this does not matter, but it should).
The fixed aquistion time which is too long for many applications (and too short for some) maybe this could be a user selected parameter.
The bar code reader will underclock so I may get it to work without an external ADC.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As I said in another thread there seems to be an unnecessary delay in the ADC.
I am now seeing what is going on. The delay between ADON being set and GO_NOT_DONE being set is the aquisition time (charging the ADC capacitor). The conversion starts when the GO_NOT_DONE is set.
Now this delay is currently set at 20us, which for most applications is far too long (the examples in the datasheet give typical values of about 2-5 us depending mainly on the input impedance).
On the 18F25K80 the aquistion time can be set in a register so there is no need for the delay introduced by GCBasic.
There also seems to be incorrect setting of the ANCON registers on the 18F25K80.
Here is the INITSYS I get
~~~~~~~
INITSYS
nop
bsf OSCCON,IRCF2,ACCESS
bsf OSCCON,IRCF1,ACCESS
bsf OSCCON,IRCF0,ACCESS
bsf OSCTUNE,PLLEN,ACCESS
clrf BSR,ACCESS
clrf TBLPTRU,ACCESS
bcf ADCON2,ADFM,ACCESS
bcf ADCON0,ADON,ACCESS
banksel ANCON0
bcf ANCON0,ANSEL0,BANKED
bcf ANCON0,ANSEL1,BANKED
bcf ANCON0,ANSEL2,BANKED
bcf ANCON0,ANSEL3,BANKED
bcf ANCON0,ANSEL4,BANKED
bcf ANCON1,ANSEL9,BANKED
bcf ANCON1,ANSEL9,BANKED
bcf ANCON1,ANSEL10,BANKED
clrf PORTA,ACCESS
clrf PORTB,ACCESS
clrf PORTC,ACCESS
clrf PORTE,ACCESS
banksel 0
return
~~~~~~~~~~
First obvious problem is ANSEL9 is set twice. The pin diagram suggest there should be 0-4,8-10 can be selected as analogue.
I am using AN0 for the ADC so ther should be a BSF ANCON0,ANSEL0 to convert this pin to analogue input.
{edited out mistakes oops!}
Last edit: David Stephenson 2017-08-10
Please test against the latest library. We have improved this TAD timing in latest library.
You appear to still be using an outdated version of GCB, The AD9 issue was resolved in version .97.01. (system.h).
User analog configs are not set in "initsys" They will be somewhere after BASEPROGRAMSTART. in your ASM file.
Please update to GCB .97.02, then post your entire GCB source code (BASIC and ASM) as attachments. The ASM "initsys" alone is rather meaningless for debugging.
Last edit: William Roth 2017-08-10
I've downloaded 97.01 (can't find 97.02).
Attached is the ASM file.
Again ANCON is not set for AN0.
The conversion clock divider is not set properly for the chip clock rate (ADCON2 bits).
Below is the test file that has been compiled.
The total time for an ADC conversion I have measured to be 22 us (so 20us for the aquisition and 2 us for the conversion)
~~~~~~
chip 18F25k80,64
config mclre=off, OSC=INTIO2, xinst=off, cpd=off
dir porta.0 in
dir portc.0 out
dim x1 as word
do
set portc.0 on
x1=readad12(an0)
set portc.0 off
wait 1 sec
loop
~~~~~~~
I have removed the hashes as this messes with the font size when posting.
Last edit: David Stephenson 2017-08-10
"I've downloaded 97.01 (can't find 97.02)"...True,where is it? It's not here.
https://sourceforge.net/projects/gcbasic/?source=typ_redirect
vorboss.dl.sourceforge.net took too long to respond.
Otherwise it's 97.01. I couldn't download latest chip files from sourceforge either,just went in a circle,it just loads a help text with a link to where I just came from.
Please take the required files from this folder. Update your local folder please manually.
https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/
I will release the next release soon.
@Stan - You are on 0.97.02 RC4 So , I am puzzled by your posting.
Attached is the latest A-D.h with some speed inprovement and FVR support. This was downloaded from SF SVN .
https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/a-d.h
Below is a link to 18F25K80 Errata Sheet, See Item1 for ADC errata.
http://ww1.microchip.com/downloads/en/DeviceDoc/80000519M.pdf
I cannot test the speed as my entire lab is packed up in preparation for a move tomorrow. After today, I will be offline for 3 or 4 days unitl I am settled in my new place. .
"Initsys" in the ASM only runs once and will have no effect on ADC speed. . The speed is mainly determined by the AD Clock & AD Delay. WIth GCB, the AD module is turned on / off with each read/ acquisition. This adds overhead and I am not sure that this is necessaery. I asked about this but have not received an answer.
The A-D.h library tries to strike a balance between reliability and speed as it must support about 600 PIC chips. It is not a failure of the library if some extra time is allowed for stability/ reliability. This does not mean it cannot be improved.
@David
It may be that for your particular application where you want every nanosecond of speed, that you will need to write your own ASM ADC code. As I read the datasheet, for reliable 12 bit reads the 18F25K80 needs an acquisition delay of 15us. However, a while back I reduced this to 10us and the readings "seemed" ok. Your mileage may vary.
It seems odd to me that a barcode reader would need to use ADC at a sampling rate of 200K samples per second. Are you sure this is the correct path for using this device?
It only requires 15us aquisition when reading the fixed Vref. During normal reading from a pin Taq will depend on the parameters listed in the datasheet (mainly impedance of the source voltage).
Yes I have written my own ASM I was merely pointing out some of the issues I had noticed in the GCB generated code such as:
the incorrect conversion clock setting (at least at 64MHz clock speed)
ANCON not being set (maybe this does not matter, but it should).
The fixed aquistion time which is too long for many applications (and too short for some) maybe this could be a user selected parameter.
The bar code reader will underclock so I may get it to work without an external ADC.