View previous topic :: View next topic |
Author |
Message |
camgoo
Joined: 29 Jul 2011 Posts: 4
|
setup_adc selecting values from software |
Posted: Fri Jul 29, 2011 5:33 am |
|
|
Hi to all, first of all excuse for my english
I have my PIC18F2455 with this configuration:
setup_adc(VSS_VDD)
but for my project I need to configure my PIC in order to select the rank values of the ADC by software. Is it possible?
If it is possible, how I do it?
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Fri Jul 29, 2011 8:51 am |
|
|
I presume you mean the reference voltage, not the 'rank values'.
Not without extra hardware.
The ADC can have it's reference fed from the power supply lines, or from pins AN2/AN3. Figure 21-1 in the data sheet.
So you would select these pins with the setup_adc, and then feed the voltage you want into these pins. So you then need a way to set a voltage. Two choices then exist:
1) An external DAC.
2) Use the comparator Vref
For 1), there are quite a few I2C DAC's, and one of these would allow you to program a reasonably fine value for the Vref.
For 2), you can program the comparator Vref to be fed on on pin Vref-. You then _must_ buffer this (fig 23-2). The internal Vref does _not_ meet the drive requirements for the ADC Vref, unless buffered. You would then feed this back into the Vref+ pin, and can program a voltage on this, to set the full scale range of the ADC. However accuracy will be relatively poor, and there will only be 16 steps. You can only control the Vref+ this way, since the Vref- pin is then used to output the reference voltage.
Best Wishes |
|
|
camgoo
Joined: 29 Jul 2011 Posts: 4
|
|
Posted: Sat Jul 30, 2011 3:17 am |
|
|
Thanks for your answer!
I understand what you mean, and you're right, I've tried to use the function setup_vref and then setup_adc(VSS_VREF) but it didn't worked. After that I noticed that function setup_vref was only for comparators.
So I will choose your second option, can you reexplain with more details?
I mean, I think I have to do this:
1."you can program the comparator Vref to be fed on on pin Vref-"
So, first of all, I configure the registers which appear on page 273:
TRISA = 1111 1011; //only RA2 as output
CRVCON = 1111 0001; //I'm not sure of this because I've never worked with comparators
CMCON = ??;
When that registers are configured, then I've to put the Vref that I want:
setup_vref(vref_low|1); //1 because I need the minimum value possible
Can you help me with this registers? I'll continue reading the datasheet in order to find more information.
Another question that I haven't found on the datasheet: what is the accuracy of the ADC? I mean, what is the minimum rising on input signal that the AC will detect?
Thanks another time! |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sat Jul 30, 2011 6:04 am |
|
|
Quote: | Another question that I haven't found on the datasheet: what is the accuracy of the ADC? I mean, what is the minimum rising on input signal that the AC will detect?
|
The ADC step size is easily calculated from information in the datasheet. But the usable detection threshold is usually determined more by the system noise level than by the ADC. Tell us more about your application. What noise levels are you expecting? If you are using the digital supply as a voltage reference you will get much more noise there than the ADC step size. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
camgoo
Joined: 29 Jul 2011 Posts: 4
|
|
Posted: Sat Jul 30, 2011 8:47 am |
|
|
Thanks for your answer!
So, I'll explain my what I'm trying to do.
I'm doing a random numbers generator. To do it, I get a value using the ADC converter of PIC18F2455. This value that i get comes from another circuit. The fact is that I need to get a white noise in order to generate random numbers. So in this case the noise levels are important.
So I'm trying to get the lowest step size possible because my signal level is low. I can't amplify this signal because the amplifiers colour my white noise, and that's the cause I'm trying to had a level voltage between Vss and the smallest Vref that I can have. This last point is what I'm trying to do now.
So my answer is: yes, I was using the digital supply as a voltage reference, but now I want to use a voltage reference from Vss to my Vref. I need to minimize this Vref.
And now I'm trying to do what Ttelmah wrote before. So I've written the code lines that I posted before, and I expected that I could get a voltage of 0.208 mV on pin 2 of port A. I explain:
I've configured the registers as I wrote on last reply and I've also written this:
setup_vref(vref_low|1);
so in theory the voltage on pin 2 of port A would be Vdd*value/24=5V*1/24=0.208V
But when I measure I get a voltage of 1,86 V.
I'm sure that the error is at the part of code that I'm trying to write, on configuration this ports that I've posted or another thing that I don't know.
Any idea? Thanks for all!=) |
|
|
camgoo
Joined: 29 Jul 2011 Posts: 4
|
|
Posted: Sun Jul 31, 2011 4:24 am |
|
|
Hi! I reply myself:
It isn't possible to do what I'm trying to do. On datasheet, section of electrical characteristcs specifies that for a 10 bits ADC conversion you need a diference between Vref- and Vref+ that has to be a minimum of the 3V.
So thanks for your help! |
|
|
|