Page 1 of 1
Swap Vref to VCC and vice versa
Posted: Sun Jan 10, 2021 3:27 pm
by AbhijitR
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
Re: Swap Vref to VCC and vice versa
Posted: Mon Jan 11, 2021 11:35 pm
by chipfryer27
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
Re: Swap Vref to VCC and vice versa
Posted: Tue Jan 12, 2021 10:00 am
by AbhijitR
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
Re: Swap Vref to VCC and vice versa
Posted: Tue Jan 12, 2021 11:29 am
by Benj
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.
Code: Select all
FC_CAL_ADC_Enable(0, 3, 0, 40);
FCV_VALUE = FC_CAL_ADC_Sample(0);
FC_CAL_ADC_Disable();
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.
Re: Swap Vref to VCC and vice versa
Posted: Tue Jan 12, 2021 12:18 pm
by chipfryer27
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,
Re: Swap Vref to VCC and vice versa
Posted: Tue Jan 12, 2021 12:40 pm
by AbhijitR
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