ADC10 - PWM question

leftyretro

New Member
Hi Group;

Just acquired a picaxe stack 28X kit this week and got it assembled and going yesterday. I'm very impressed with the whole picaxe system and know I'm going to have a blast.
I've been exploring the features and learning the software. One quick experiment I did was to test out the ADC and PWM features. I wired a 20 turn trimmer pot from 5 volt vcc to ground and routed the wiper to the ADC channel 1 input. I wired a 5k ohm resistor from the PWM output and integrated it with a 2.2 mfd cap to ground. I then put the picaxe in a loop as follows:

main: rem loop back ADC to PWM
Readadc10 0,W0
pwmout 1,249,w0
goto main

This works fine but the measured results with a benchtop Fluke 45 DVM appears to have more resolution then I would expect.

My think is a 10 bit A to D with a 0-5v range should result in around 5 millivolt steps (5/1024) as I adjust my pot, however my readings after intergrating the PWM is more like 100 micro volts steps. It's touchy to try 100 uv steps but clearly I can set 1 millivolt steps with no problems.

So where is my thinking off. Why do I appear to have greater control of output voltage resolution then 10 bits ADC conversion would account for.

Thanks
 

BeanieBots

Moderator
With a 5v supply, you are correct to think about 5mV resolution. (5/1023).
What makes you think it is anything else?
Post more details of your setup, conditions and test results.
Try some obvious values such as 1, 255, 511, 1023. You should get 5mV, 1.25v, 2.5v and very close to 5v repectively.
There will be a slight error when calculating to the nearest mV but the overall resolution will be about 5mV.

Edited by - beaniebots on 25/03/2007 10:59:39
 

Dippy

Moderator
That is strange.
I've just knocked up an Excel and you should get 4000Hz with a %Duty of 0 to 100 (give or take).

Have you tried a test Sertxd to make sure W0 is OK?

I assume your capacitor is 2u2F and not 2.2milliFarad? (Of course it is). Try another capacitor, something a little smaller.

Check your meter connections/settings as well. And check you conenctions too. Obviously you are looking at the correct PICAXE leg?
 

leftyretro

New Member
Hi BeanieBots;

"With a 5v supply, you are correct to think about 5mV resolution. (5/1023).
What makes you think it is anything else?"

That was my expectation also, but the performance based on measuring the output resistor cap junction, I measure a total range of .5mv to 4.9146vdc as I turn my input 10 turn pot to the ADC pin, and I can set and stop the output to any 1 millivolt value easily, while I was expecting to see the output stable at only 5mv steps through it's range. Perhaps this is just an artifact of PWM and it's averaging between the W0 5mv steps? All I know is that I can set an output to say 2.500vdc and then by careful tweeking of the pot move it to 2.501vdc if I desire, and the value is rock stable only moving +/- .0001vdc and that is better then 5mv resolution, no?

"Post more details of your setup, conditions and test results."

Again just an adjustable 0-5vdc DC input to the ADC input pin and a 5k resistor from the PWM output pin wired to the + side of a 2.2MFD cap with the other cap lead to ground. I measure the + cap lead with a high quality DVM.

" Try some obvious values such as 1, 255, 511, 1023. You should get 5mV, 1.25v, 2.5v and very close to 5v repectively.
There will be a slight error when calculating to the nearest mV but the overall resolution will be about 5mV."

Yes I think something like that would work. I'll try just setting W0 to say 512 and pause for 30 sec, then set W0 to 513, wait another 30 sec and loop back to 512. The changed measured at the PWM intergrator output should reflect the resolution of a single bit change?

Thanks Retrolefty


Edited by - retrolefty on 25/03/2007 16:38:24
 

BeanieBots

Moderator
At the end of the day, it's only 10-bit resolution and you will only get 1023 discrete values on both the ADC side and the PWM side. What you are probably seeing is the effect of noise which can appear (and is sometimes done deliberately) to give higher resolution.
Imagine there is 10mV of noise on the analog input. Each time the ADC is used, it will sample the voltage plus the noise and give a range of values. If the avaerage of the noise is zero, then the average of the readings will be the true value.
If the voltage were to increase by 1mV, the odds on the reading being a bit value higher will increase. Hence, the average value will also increase.
The same applies in reverse with the PWM.
If you output N for 3 time periods and then N+1 for 1 time period you get an average of N+.25
Put a long time delay between ReadADC and PWMout and then see what happens to the resolution.
 

leftyretro

New Member
You are most correct. I coded the W0 =511 then 512 with 10 second delays delays and I see a rock steady 5mv step between those two W0 values sent to the PWM, so what I was seeing earlier was just a normal sample averaging on the ADC. I tested that by serial outputing W0 after reading ADC in a loop and could see it dithering between +/- one count. There is no dithering on the actual voltage into the ADC pin as my fluke shows a rock steady input down to hundreds of a uv, so just normal ADC conversion variation I guess.

Thanks for you insite.
 

BeanieBots

Moderator
DVMs are very good at averaging. Just because the DVM is steady doesn't mean there's no noise.
Also, the ADC value is a function of the power supply, so any noise or ripple there will also affect readings.
What you have observed earlier can be used to double the resolution of an ADC but it needs to be done very carefully with full understanding so as not to fall into the dangerous resolution/accuracy trap.
Anyway, glad you got it all sorted.
 

wilf_nv

Senior Member
Once more:

Although already explained by BeanieBots and retrolefty, I would emphasize the positive side of this remarkably useful method of extending dynamic range using "dithering".

While the ADC readings and PWM output have 10 bit resolution, superimposed low level input noise causes variations in adjacent ADC readings and PWM dutycycle values. When the PWM output voltage, dithering between two adjacent values, is measured with a multimeter, the PWM values are averaged to give a range of smaller "in between" readings.

A good explanation of dither is found here:

http://www.daqarta.com/tm05.htm



Edited by - wilf_nv on 27/03/2007 05:06:09
 
Top