Hi,
I need to use voltage reference input (just Vref+, not Vref- ).
As i understand the chips pdf the register (ADCON1) must be set as "00000001" for all the analog inputs and Vref+ enabled.
how can i do this in the GCB?
is it ok to use this line:
set adcon1=1 'eg: adcon1=5 for 00000101
or
set adcon1=b´00000001´
i have another silly question:
which quotation mark must be used to write b´00000001´ ?
i have at least 3 ( ' ` ´ ) of them which i know and use only one for comment lines ( ' )
btw i am using GCB version of 27/02/2016 with a turkish keyboard (https://en.wikipedia.org/wiki/QWERTY#Turkish_.28Q-keyboard.29)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not quite done yet. In order to not confuse the include a-d.h file, the functions "ReadAD(ANx)" and "ReadAD10(ANx)" must be renamed in the new RVA2D.h include file, and referenced in the main code. So for instance; the ReadAD10(ADReadPort) function name could be RVAD10(ADReadPort) and would be called in Main like:
Volts = RVAD10(AN0)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i am trying to understand where to insert/replace these lines, especially the lines beginning with ";"
if i understand correctly from the microchips pdf file (page 128), for my needs (all 7 analog pins for analog input and Vref+ enabled) PCFG bits must be "0001".
so in your example, this line should be:
... SET ADCON1.PCFG2 OFF
...
right?
however, i wish to set for Vref simpler...
have a nice day
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The code with ";" is just commenting out the old code that is being replaced. I find it useful sometimes to leave the original code in to form a reference point in case I need to go back to it if the new code does not work.
I wish their was an easy way to get the Vref+ to work for you. The a-d.h file is kind of hard to follow, and the changes could be done to just that file. Lets work on that then. Here is something to try. Lets start by making a define for the 16f877A Vref+ and then testing that define if it is true or not, and if true set the PFG <0-3> bits to "0001" enabling all the a-d pins and Vref+ on RA3.
In main program initialization:
#define Vref_plus
Open a-d.h and copy and paste changes to the 16f877A code below and then "save" file.
Careful with the H file. Not all PIC chips use the same register bits to set Vref+/Vref-. If we are going to add features then I suggest a concise & deliberate method that works not only on 877A but across the board. There are also internal VREF settings to consider on the less archaic chips. This stuff is not trivial. AD-H is complex and can be easily broken.
Here's how I have done it in source with PIC chips like 877a that use PCFG bits in the same manner.
ADCON1 = ADCON1 AND b'11110000' OR b'00000001'
Last edit: William Roth 2016-06-02
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Agreed William on messing with the a-d.h file; it is a real can of worms. Doing a Vref+ across the board is going to be a real time consumer. Well the next question is Vref- compatibility and so forth.
Took me forever, but my Vref+ code seems compatible (by inspection) for the following device(s) or device families.
Not compatible with following devices. Which are also not reccommended for new designs.
14000 (10-16 bit a-d, mystery device for me).
16c773_774 (12bit a-d, and uses VCFG2:VCFG0 for Vref+ and Vref-).
My methodology used command line findstr VCFG3 across the .dat files to find those devices, and then deducted those devices that in turn had either the ADCON2 register or PCFG4 bit.
No testing done. Comments welcome.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@kent
it works, thanks a lot.
i backed up the original a-d.h file and saved new one with your lines. i hope i won't forget to replace it with the original in the future.
@all
You guys, doing great job with the GCB but your kindness and patience is more precious in my opinion.
have a nice day
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@fisyon
Glad it worked. I'll let Anobium and others decide if worthy of inclusion in trunk, or if more work is required to include other devices. Microchip has too darn many PIC's to keep track of .....haha.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I need to use voltage reference input (just Vref+, not Vref- ).
As i understand the chips pdf the register (ADCON1) must be set as "00000001" for all the analog inputs and Vref+ enabled.
how can i do this in the GCB?
is it ok to use this line:
set adcon1=1 'eg: adcon1=5 for 00000101
or
set adcon1=b´00000001´
i have another silly question:
which quotation mark must be used to write b´00000001´ ?
i have at least 3 ( ' ` ´ ) of them which i know and use only one for comment lines ( ' )
btw i am using GCB version of 27/02/2016 with a turkish keyboard (https://en.wikipedia.org/wiki/QWERTY#Turkish_.28Q-keyboard.29)
What I did was copy the adc.h include file and renamed to my project "xxxxadc.h" In my particular case I used RVA2D.h
Then I dug down to where the 16f877A is affected in the initialization, and changed there. With the newest GreatCowBasic folder/include/lowlevel:
So to set up with two available a2d's (AN0, AN1) and Vref+ in ADCON1, then do like you say, and comment out the old code and insert the new like:
Now you should be good to go with the Vref+. Be sure to add the include file during initialization like:
I don't know specifically how the bin numbers are parsed, but the straight apostrophe is what I use like b'00001111'.
Not quite done yet. In order to not confuse the include a-d.h file, the functions "ReadAD(ANx)" and "ReadAD10(ANx)" must be renamed in the new RVA2D.h include file, and referenced in the main code. So for instance; the ReadAD10(ADReadPort) function name could be RVAD10(ADReadPort) and would be called in Main like:
thank you for your detailed answer.
i am trying to understand where to insert/replace these lines, especially the lines beginning with ";"
if i understand correctly from the microchips pdf file (page 128), for my needs (all 7 analog pins for analog input and Vref+ enabled) PCFG bits must be "0001".
so in your example, this line should be:
...
SET ADCON1.PCFG2 OFF
...
right?
however, i wish to set for Vref simpler...
have a nice day
The code with ";" is just commenting out the old code that is being replaced. I find it useful sometimes to leave the original code in to form a reference point in case I need to go back to it if the new code does not work.
I wish their was an easy way to get the Vref+ to work for you. The a-d.h file is kind of hard to follow, and the changes could be done to just that file. Lets work on that then. Here is something to try. Lets start by making a define for the 16f877A Vref+ and then testing that define if it is true or not, and if true set the PFG <0-3> bits to "0001" enabling all the a-d pins and Vref+ on RA3.
In main program initialization:
Open a-d.h and copy and paste changes to the 16f877A code below and then "save" file.
Report back if that works for you.
@Kent. If this works I can lift into the main distribution. Let me know how this progress in terms of results.
Careful with the H file. Not all PIC chips use the same register bits to set Vref+/Vref-. If we are going to add features then I suggest a concise & deliberate method that works not only on 877A but across the board. There are also internal VREF settings to consider on the less archaic chips. This stuff is not trivial. AD-H is complex and can be easily broken.
Here's how I have done it in source with PIC chips like 877a that use PCFG bits in the same manner.
ADCON1 = ADCON1 AND b'11110000' OR b'00000001'
Last edit: William Roth 2016-06-02
Agreed William on messing with the a-d.h file; it is a real can of worms. Doing a Vref+ across the board is going to be a real time consumer. Well the next question is Vref- compatibility and so forth.
Took me forever, but my Vref+ code seems compatible (by inspection) for the following device(s) or device families.
16f818_819
16f87X
16f87XA
16c925_926
18cXX2
18fXX2
18fXX8
18fXX39
Not compatible with following devices. Which are also not reccommended for new designs.
14000 (10-16 bit a-d, mystery device for me).
16c773_774 (12bit a-d, and uses VCFG2:VCFG0 for Vref+ and Vref-).
My methodology used command line findstr VCFG3 across the .dat files to find those devices, and then deducted those devices that in turn had either the ADCON2 register or PCFG4 bit.
No testing done. Comments welcome.
@kent
it works, thanks a lot.
i backed up the original a-d.h file and saved new one with your lines. i hope i won't forget to replace it with the original in the future.
@all
You guys, doing great job with the GCB but your kindness and patience is more precious in my opinion.
have a nice day
@fisyon
Glad it worked. I'll let Anobium and others decide if worthy of inclusion in trunk, or if more work is required to include other devices. Microchip has too darn many PIC's to keep track of .....haha.