View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: PIC12F675 A/D Config Problems by Al_Kohl |
Posted: Tue Nov 26, 2002 6:37 pm |
|
|
I was unable to reply to your original post. It didn't even
show me link for "Post Reply". Did you select the option
for "Disallow replies" ?
But regarding your question about the setup_adc() function:
The 12F675.H file says that the VREF constant is only used with
the setup_adc_ports() function. It's not used with setup_adc().
Here is part of that file:
// Constants used in SETUP_ADC_PORTS() are: (These may be ORed together)
#define NO_ANALOGS 0 // None
#define ALL_ANALOG 15 // AN0 AN1 AN2 AN3
#define AN0_ANALOG 1 // AN0
#define AN1_ANALOG 2 // AN1
#define AN2_ANALOG 4 // AN2
#define AN3_ANALOG 8 // AN3
#define VREF 64 // Use Vref pin
// Constants used for SETUP_ADC() are:
#define ADC_OFF 0
#define ADC_CLOCK_DIV_2 1
#define ADC_CLOCK_DIV_4 0x40
#define ADC_CLOCK_DIV_8 0x10
#define ADC_CLOCK_DIV_16 0x50
#define ADC_CLOCK_DIV_32 0x20
#define ADC_CLOCK_DIV_64 0x60
#define ADC_CLOCK_INTERNAL 0x30
___________________________
This message was ported from CCS's old forum
Original Post ID: 9472 |
|
|
Yann Guest
|
Re: PIC12F675 A/D Config Problems by Al_Kohl |
Posted: Wed Nov 27, 2002 7:37 am |
|
|
I suggest you to don't use the functions setup_adc_port() and setup_ADC() because I found some errors with this functions in the compiler (in my version) The best way is to set and clear each bit of register CMCON, ADCON0,VRCON, ANSEL by yourself.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9504 |
|
|
Al_Kohl Guest
|
Re: PIC12F675 A/D Config Problems by Al_Kohl |
Posted: Wed Nov 27, 2002 9:58 am |
|
|
:=I suggest you to don't use the functions setup_adc_port() and setup_ADC() because I found some errors with this functions in the compiler (in my version) The best way is to set and clear each bit of register CMCON, ADCON0,VRCON, ANSEL by yourself.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9509 |
|
|
Al_Kohl Guest
|
Re: PIC12F675 A/D Config Problems by Al_Kohl |
Posted: Wed Nov 27, 2002 9:59 am |
|
|
Started looking at these registers already. I was hoping I could be lazy. Can I still use the following command?
value=READ_ADC();
:=I suggest you to don't use the functions setup_adc_port() and setup_ADC() because I found some errors with this functions in the compiler (in my version) The best way is to set and clear each bit of register CMCON, ADCON0,VRCON, ANSEL by yourself.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9510 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: PIC12F675 A/D Config Problems by Al_Kohl |
Posted: Wed Nov 27, 2002 2:52 pm |
|
|
:=Started looking at these registers already. I was hoping I could be lazy. Can I still use the following command?
:=
:= value=READ_ADC();
:=
:=:=I suggest you to don't use the functions setup_adc_port() and setup_ADC() because I found some errors with this functions in the compiler (in my version) The best way is to set and clear each bit of register CMCON, ADCON0,VRCON, ANSEL by yourself.
---------------------------------------------------------
In PCM vs. 3.127, the following functions appear to be
compiled correctly for the 12F675:
main()
{
char value;
setup_comparator(NC_NC_NC_NC);
setup_adc_ports(AN0_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
value = read_adc();
while(1);
}
I checked them by looking at the .LST file. I don't have
a test board setup for the 12F675, so I can't absolutely say
they work for certain. This is for PCM vs. 3.127. If you have
an earlier version, they might work work. I don't know the
exact version in which CCS apparently fixed them.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9522 |
|
|
Al_Kohl Guest
|
Re: PIC12F675 A/D Config Problems by Al_Kohl |
Posted: Wed Nov 27, 2002 4:20 pm |
|
|
This gives me zero.
:=---------------------------------------------------------
:=In PCM vs. 3.127, the following functions appear to be
:=compiled correctly for the 12F675:
:=
:=main()
:={
:=char value;
:=
:=setup_comparator(NC_NC_NC_NC);
:=setup_adc_ports(AN0_ANALOG);
:=setup_adc(ADC_CLOCK_DIV_8);
:=set_adc_channel(0);
:=value = read_adc();
:=
:=while(1);
:=}
:=
However I get results when I do this:
setup_comparator(NC_NC_NC_NC);
setup_adc_ports(AN0_ANALOG);
//setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
Still doesn't fix the VREF which also gives me zero.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9531 |
|
|
Al_Kohl Guest
|
Re: PIC12F675 A/D Config Problems by Al_Kohl |
Posted: Wed Nov 27, 2002 5:03 pm |
|
|
Wait, should this work....because it gives me a result but I don't think it is using the VREF. In my design I have 2.6V on pin A2 when my sensor gets to 2.5v I figure my result should be near 0xFF. I had this working in a PIC12C672, with the appropriate header file.
Main()
{
setup_comparator(NC_NC_NC_NC);
setup_adc_ports(AN0_ANALOG);
setup_adc_ports(VREF);
setup_vref(VREF_A2);
//setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
___________________________
This message was ported from CCS's old forum
Original Post ID: 9533 |
|
|
Al_Kohl Guest
|
Re: PIC12F675 A/D Config Problems by Al_Kohl |
Posted: Wed Nov 27, 2002 5:17 pm |
|
|
Correction I have 2.6v on pin GP1/AN1/VREF (Pin 6)and my sensor is on GP0/AN0 (Pin 7). How do I use the VREF?
:=Wait, should this work....because it gives me a result but I don't think it is using the VREF. In my design I have 2.6V on pin A2 when my sensor gets to 2.5v I figure my result should be near 0xFF. I had this working in a PIC12C672, with the appropriate header file.
:=
:=Main()
:={
:=setup_comparator(NC_NC_NC_NC);
:=setup_adc_ports(AN0_ANALOG);
:=setup_adc_ports(VREF);
:=setup_vref(VREF_A2);
:=//setup_adc(ADC_CLOCK_DIV_8);
:=set_adc_channel(0);
___________________________
This message was ported from CCS's old forum
Original Post ID: 9534 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: PIC12F675 A/D Config Problems by Al_Kohl |
Posted: Wed Nov 27, 2002 5:23 pm |
|
|
:=Wait, should this work....because it gives me a result but I don't think it is using the VREF. In my design I have 2.6V on pin A2 when my sensor gets to 2.5v I figure my result should be near 0xFF. I had this working in a PIC12C672, with the appropriate header file.
:=
:=Main()
:={
:=setup_comparator(NC_NC_NC_NC);
:=setup_adc_ports(AN0_ANALOG);
:=setup_adc_ports(VREF);
The two lines above are not done correctly.
The parameters are intended to be OR'ed together.
This is stated in the 12F675.H file.
It should be done like this:
setup_adc_ports(AN0_ANALOG | VREF);
:=setup_vref(VREF_A2);
:=//setup_adc(ADC_CLOCK_DIV_8);
:=set_adc_channel(0);
I think you do need to specify an A/D clock rate.
It's going to be set to something, just due to the
power-up default settings of the PIC's registers.
You should specify it, rather than leaving it in some
unknown state.
If that line causes the program to fail, then you
should look at the .LST file and check the code
produced by the compiler against the data sheet.
Then if it's wrong, write your own low-level code
that directly writes to the PIC registers.
Use the #byte directive to define the register addresses.
I can't do any tests for you, because I don't have a test
board for this PIC.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9536 |
|
|
|