Hello!
I am trying to change the "Vref Option" in the settings option of the ADC, i want to know if it is possible to swap the Vref option from VDD to Vref+ and vice versa in the real hardware while running the chart (real time), is there any option of using some "C" code or something else.
Thank you.
Abhi
Swap Vref to VCC and vice versa
Moderator: Benj
-
- Valued Contributor
- Posts: 740
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 185 times
- Been thanked: 204 times
- Contact:
Re: Swap Vref to VCC and vice versa
Hi Abhi
Interesting question (at least for me <s>) as I'm curious as to why would you need to do this?
What is your target chip?
Not being a C expert I can only guess, but worth a try I suppose. From a PIC data sheet for a chip I'm using at present it would seem that it could be possible to do as you wish under software control by changing a bit(s) within a register. For this chip it is the ADCON1 register but yours could be different.
Bit 5 (VCFG1)
1 = Vref -Ref (port AN2)
0 = VSS
Bit 4 (VCFG0)
1 = Vref +Ref (port AN3)
0 = VDD
I'm guessing that if you configured the ADC for VDD in the properties box, later on you could use a line of C to change to Vref and vice-versa.
For this PIC that would be (but please double check my "C"):-
set_bit(ADCON1,4); this would set it to use Vref + (AN3) as the reference
clear_bit(ADCON1,4); this would set it to use VDD
No expert, but it won't hurt to try until someone more knowledgeable comes along.
Regards
Interesting question (at least for me <s>) as I'm curious as to why would you need to do this?
What is your target chip?
Not being a C expert I can only guess, but worth a try I suppose. From a PIC data sheet for a chip I'm using at present it would seem that it could be possible to do as you wish under software control by changing a bit(s) within a register. For this chip it is the ADCON1 register but yours could be different.
Bit 5 (VCFG1)
1 = Vref -Ref (port AN2)
0 = VSS
Bit 4 (VCFG0)
1 = Vref +Ref (port AN3)
0 = VDD
I'm guessing that if you configured the ADC for VDD in the properties box, later on you could use a line of C to change to Vref and vice-versa.
For this PIC that would be (but please double check my "C"):-
set_bit(ADCON1,4); this would set it to use Vref + (AN3) as the reference
clear_bit(ADCON1,4); this would set it to use VDD
No expert, but it won't hurt to try until someone more knowledgeable comes along.
Regards
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 283 times
- Been thanked: 80 times
- Contact:
Re: Swap Vref to VCC and vice versa
Hello! CF
Good morning
You spot absolutely right, actually I wanted to use only one ADC pin to manage 2 different analog signals with 2 different reference voltages, and I wanted to change the setting in actual running.
I am going to test your suggestion and keep you posted.
Many thanks, I appreciate.
Abhi
Good morning
You spot absolutely right, actually I wanted to use only one ADC pin to manage 2 different analog signals with 2 different reference voltages, and I wanted to change the setting in actual running.
I am going to test your suggestion and keep you posted.
Many thanks, I appreciate.
Abhi
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Swap Vref to VCC and vice versa
Hi Abhi,
If you change the register via a C icon then it will get overwritten when you call the ADC sample routine.
It's probably better to do the ADC CAL cal using a C icon as you then get access to the Vref setting.
First double click the VRef option in the ADC component properties. This will give you the numeric value for each setting. Do the same for the conversion speed property and make a note of the numeric value you want for each.
The code to call the ADC routines looks like this to store the result into a global variable named value.
So the Enable function is the one that sets everything up.
Here are the meanings of the parameters.
FC_CAL_ADC_Enable(ADC Channel, Conversion Speed, VREF Option, Precharge Time)
hope this helps.
If you change the register via a C icon then it will get overwritten when you call the ADC sample routine.
It's probably better to do the ADC CAL cal using a C icon as you then get access to the Vref setting.
First double click the VRef option in the ADC component properties. This will give you the numeric value for each setting. Do the same for the conversion speed property and make a note of the numeric value you want for each.
The code to call the ADC routines looks like this to store the result into a global variable named value.
Code: Select all
FC_CAL_ADC_Enable(0, 3, 0, 40);
FCV_VALUE = FC_CAL_ADC_Sample(0);
FC_CAL_ADC_Disable();
Here are the meanings of the parameters.
FC_CAL_ADC_Enable(ADC Channel, Conversion Speed, VREF Option, Precharge Time)
hope this helps.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Valued Contributor
- Posts: 740
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 185 times
- Been thanked: 204 times
- Contact:
Re: Swap Vref to VCC and vice versa
Hi Benj
I knew someone with far better knowledge than I would soon assist <s>
I haven't used FC for a while (but will be later this week) so had completely forgotten about those components, and your detailed explanation of the ADC is most helpful.
Many thanks,
I knew someone with far better knowledge than I would soon assist <s>
I haven't used FC for a while (but will be later this week) so had completely forgotten about those components, and your detailed explanation of the ADC is most helpful.
Many thanks,
- AbhijitR
- Posts: 300
- Joined: Fri Nov 07, 2014 12:48 pm
- Location: Pune, India
- Has thanked: 283 times
- Been thanked: 80 times
- Contact:
Re: Swap Vref to VCC and vice versa
Hello! Ben
Perfect, as Chipfryer also said, always better from the expert. I check the result following your suggestion and keep you posted too.
Thank you again.
Abhi
Perfect, as Chipfryer also said, always better from the expert. I check the result following your suggestion and keep you posted too.
Thank you again.
Abhi