hello,
is there a way how to to set 16bit number from analogRead function on Arduino Uno? I know, ADC here has only 10bit resolution...
how to to set 16bit number from analogRead
Please explain what you mean by this.
oh, it should be "how to get 16bit number from analogread"
I have potentiometer connected to analog pin of arduino uno and I need to get number between 0-65535
sorry for my english.
thanks
I am trying to use SID 6581 sound chip as a generator. There are two 8bits registers for setting generated frequency. And I want to do that with one potentiometer only.
here is a table that show the chip registers:
http://www.waitingforfriday.com/index.php/File:SID_Registers.PNG
You can scale so that instead of ranging from 0 - 1023 it will range from 0 - 65535:
unsigned int val = ((unsigned long) analogRead(A0) * 65535 + 1023/2)/ 1023
This isn't actually going to improve your resolution, however, since 1024 distinct codes between 0-1023 will still result in 1024 distinct codes between 0-65535. Instead of them being uniformly spaced, however, you'll have non-uniform spacings between codes were uniformly spaced at the A/D pin.
If you don't mind spending a lot of time reading this pot, you could do this instead
unsigned int val = 0;
for(uint8_t read_num; read_num < (1 << 6); read_num++)
{
val += analogRead(A0);
}
That will give you a value between 0-65535, with the potential for 65536 distinct codes.
This is actually a useful trick to get extra resolution out of cheap ADCs. For example, say you had a voltage at the pin that was 50% of the way between 511 and 512. If you read it 64 times, you're likely to get 511 half the time and 512 half the time (Honestly, you're probably going to have more than 1 bit of noise in your reading, but I'm just trying to demonstrate the concept). When you sum up all of the samples you can effectively get a value of 511.5.
Delta_G:
Well you can't get 16 bit resolution from a 10 bit ADC. The best you could hope for is to multiply your analogRead results by 64 to scale them to 0 - 65535 and you'll have steps of 64. If you want more resolution, you may need to invest in an ADC chip that you can control from Arduino to read your pot.
Sorry to nitpick, but that'd give you a range of 0-65472. It sounds like he really needs 1023 to translate into 65535.
Delta_G:
But you can't get there with only 10 bits. When you shift them left you leave zeroes behind.
See my reply two up. It contains two different methods to translate the 10bit A/D value into a number between 0-65535.
Although 64 reads in my 2nd method is excessive, multiple sampling on cheap A/Ds is a pretty commonly used trick. I once made a starter battery for airplanes that needed a huge range for measuring current as the engines take >1000A when starting. At the same time, however, I needed the battery to be reasonably accurate when it was just powering the standby loads. Even though I had 4A/bit of resolution from my signal, I was able to measure down to 1A of resolution through multiple sampling and seeing the bits-between-the-bits.
http://www.atmel.com/images/doc8003.pdf
4N where N is the number of additional bits. Six in this case. 4096 samples are needed to add six bits.
There are specific restrictions for the technique to work. None of which have been mentioned. Purchasing a 16 bit converter is very likely much cheaper and much more effective. "Don't spit in the wind" comes to mind.
BigBobby:
Sorry to nitpick, but that'd give you a range of 0-65472. It sounds like he really needs 1023 to translate into 65535.
If that were the case, downstream calculations would have to use a measurement scaling factor of (64+1/1024). It hardly seems worth the effort, when you can use 64. I doubt that the OP "needs" it to go to 65535. It's more likely that they haven't considered the math. So it makes more sense to use:
unsigned int val = analogRead(A0) * 64;
Both, because it is easier to calculate there, and because subsequent calculations can easily and accurately be derived from it.
I probably wouldn't use a potentiometer. I would probably use a 2 bit gray code rotary encoder .
stowite:
I probably wouldn't use a potentiometer. I would probably use a 2 bit gray code rotary encoder .
It would be nice to provide a link for the OP if you've had good luck with a particular part.
aarg:
I doubt that the OP "needs" it to go to 65535. It's more likely that they haven't considered the math.
Well, it's tough to know, but all the OP has said so far is:
yoopee:
I have potentiometer connected to analog pin of arduino uno and I need to get number between 0-65535
I'm envisioning that this pot value is getting input into code that expects 65535 when the pot is at max value. If that's true, then just multiplying by 64 would be a problem. I agree the best way for the OP to deal with this is to change whatever code is using the pot value so that it expects a max of 1023 instead. If that's not possible for some reason, then scaling by 65535/1023 is really all he can do.
Heh...and not to nitpick myself, but sampling 64 times is only going to have a range of 0-65472 as well. I'd delete the brainfart, but it seems to have generated some discussion.
BigBobby:
Well, it's tough to know, but all the OP has said so that is:I'm envisioning that this pot value is getting input into code that expects 65535 when the pot is at max value. If that's true, then just multiplying by 64 would be a problem. I agree the best way for the OP to deal with this is to change whatever code is using the pot value so that it expects a max of 1023 instead. If that's not possible for some reason, then scaling by 65535/1023 is really all he can do.
Heh...and not to nitpick myself, but sampling 64 times is only going to have a range of 0-65472 as well. I'd delete the brainfart, but it seems to have generated some discussion.
I doubt that 1/4 of a degree of resolution is going to matter, especially at the ends with most pots, where there is often a resistance non-linearity.
The OP's perceived need is based on a misconception. If the goal is accurate readings across the range, then a straighforward multiply by 64 is absolutely correct. The ADC is not capable of reading 1024.
If however, the goal is complete coverage from 0-65535 then the other methods will work at the cost of inaccuracy across the range.
But since the resolution and non-linearity of the pot (even an expensive one) itself is so bad, the question is moot.
Even though I wish I could delete my suggestion of oversampling (seeing as how it doesn't change the range from 0-65472 at all), thanks for posting this app note.
I'll read it later, as I'd be interested in knowing where 4N comes from. In the example I gave before, I actually did read the ADC 16 times to get 1A resolution out of the 4A/bit signal. I just sampled until I got reliable results at the time.
What are the restrictions on the noise? It seems like the only restrictions would be that there must be noise and it must be random?
aarg:
It would be nice to provide a link for the OP if you've had good luck with a particular part.
stowite:
I probably wouldn't use a potentiometer. I would probably use a 2 bit gray code rotary encoder .
+1
Maybe one for fine, one for coarse adjustment. With an LED display.
aarg:
+1
Maybe one for fine, one for coarse adjustment. With an LED display.
That is what I do but I use an LCD display rather than LEDs. I have experimented with using a single Gray encoder with slow movement for fine adjustment and rapid movement for coarse but have yet to find the best way to do this.
BigBobby:
What are the restrictions on the noise?
Must be random in the mathematical sense as apposed to the "looks random to me" sense. The usual method is to include a hardware based random number generator that fiddles the voltage.
It seems like the only restrictions would be that there must be noise and it must be random?
Must be >= 1 LSB.
Signal must be very stable. The noise has to be independent of the signal.
Section 3.2 Noise has the details.
I bought 2 of these, haven't tested them yet...