Overclocking the ATtiny 2 ADC. With graphs and stuff. #1292
burnsb
started this conversation in
Show and tell
Replies: 2 comments
0 replies
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment






Uh oh!
There was an error while loading. Please reload this page.
Per the data sheet, the ADC on the tiny 2s (and I would assume the other post Microchip AVRs) is rated for 375ksps max. However, if you set:
ADC0.CTRLB = 0; // prescaler div/2ADC0.CTRLE = 0; // sample duration of 1/2clock 0.25us @20mHzYou can get an ADC rate of around 615kHz. Which gives a 300kHz or so max frequency of a sampled wave given Nyquist, not that I'm any sort of expert on Nyquist.
So far, I have looked at 125kHz triangle waves. (not very triangular, my function generator is a AD9833 chip ran through a LM358 op amp with a couple of pots to adjust amplification and offset. I have also looked at a 10k pot. I think that the pot measurements are probably going to be the most useful, and to those ends I've ordered a pot assortment from 100ohms and up. I imagine that values from 10k and lower will be most useful as I expect impedance to quickly make any results past 10k not very useful.
My tests have been done on the same ATtiny3224. I'm using a Rigol DS1202Z-E scope for my reference measurements. My power supply is just the 5V rail off a Uno clone that is running the AD9833. So, these are definitely less than optimal test conditions/equipment. However, I'm getting meaningful results.
Also, I'm looking at measuring SMPS output, so impedance isn't going to be a big problem anyhow. My application will also tolerate errors of several percent, probably 5% error won't be too much.
The sketch running on the ATtiny 3224 takes 100 freerunning samples as well as count from TCB1.
I used a 125kHz wave as the lm358 couldn't keep up with 300kHz and give me the amplitude I wanted. A typical result (2990mV avg with 1010mV peak to peak):

And here are the results tabulated with a nice curve representing error:

So, 1v is the sweet spot. It measures less than 1% deviation around 1V. This is also backed up by the test series on just a 10K pot. (more on that in a minute). At 3000mV error has grown to more than -17%. Strangely, at levels below 1V, the ADC error quickly grows in a positive direction. I.E. it reads higher than what it's measuring.
Anyhow, A 10k pot gave results that were remarkably consistent with the triangle wave error. Here's a typical series, 2500mV:
The following results page has two charts, the larger chart is results from 1V and up, At 59mV the deviation was 360%. The smaller chart shows all the results and you can see it going to the moon as the voltage gets small. So, I think I can pretty conclusively say that an overclocked ADC isn't going to give you usable results below 1V. Sample duration maybe?
Now, a flat 3v voltage gives an error of -18.6%. Pretty close to the -17.6% of a triangle wave with an average of 3V. With that wave being 1V peak to peak, I bet it accounts for the 1% difference as error is growing more negative as the voltage increases.
If anyone wants it, I can share the sketch used for sampling or my spreadsheets. I think I'm going to test a 100ohm pot at 1/4V increments. I may do some other series on higher value dividers.
I think it will be possible to create a lookup table for ADC correction at max overclock and get usable results if the source is low impedance and high accuracy isn't needed. I'll probably find the curve that best fits the data and generate the table from it, doing math with only 28 cycles is probably not going to work. If you want to use this data at these speeds, it needs to be simple and quick.
I welcome questions/comments/suggestions!
All reactions