Author Topic: [AVR] ADC oversampling function  (Read 10668 times)

0 Members and 1 Guest are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] ADC oversampling function
« Reply #25 on: February 17, 2017, 09:03:18 pm »
As my thermistor is connected from ground to an ADC input and there is a pull up resistor (470 ohm) from the ADC input to 5V. My PWM frequency is around 240Hz and with a 12-13 bit oversample and 62.5-125KHz it would take at least a PWM cycle to take the measurements, so if I put a high value resistor of 10's to 100's of KOhm from the PWM output pin to the ADC input it would shake it about enough to drag the input up and down around the 1 bit level (4.8mV)
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 2082
Re: [AVR] ADC oversampling function
« Reply #26 on: February 17, 2017, 09:32:14 pm »
My last device that used a temperature to generate a pwm had the pwm jumping all over the place
So this is a proportional rather than bang-bang controller? If so, you ought to look at fixing the sampling/update rate because \$\Delta t\$ affects the gain of the loop and hence the stability.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] ADC oversampling function
« Reply #27 on: February 17, 2017, 09:44:52 pm »
My last device that used a temperature to generate a pwm had the pwm jumping all over the place
So this is a proportional rather than bang-bang controller? If so, you ought to look at fixing the sampling/update rate because \$\Delta t\$ affects the gain of the loop and hence the stability.

I don't know what you mean by gain in a proportional system. No I'm not doing bang bang. It's a case of take target temp +/- some degrees and ramping the fan from min to max from min to max temp. Yes there is no guarantee of an exact temperature but that is the idea of having a range. No gain to worry about. I could of course do a more precise mapping to create a bit of a curve to skew the response, for example I can have a sharper response around the temperature I'm hoping to acheive and have less of the PWM range in the highest or lowest range if I want more guarantee of hitting a centre target, or if I am trying to maximise efficiency and power consumption and don't mind not hitting the target too closely have a less steep reaction around the target and then hit it hard in the extremes hoping to never have to use it.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] ADC oversampling function
« Reply #28 on: February 17, 2017, 09:47:51 pm »
if I want to be a bit more accurate on the target I could have a proportion response but do something like

if ("new reading" > "last reading")
add some extra speed
else
just follow the straight line

Just to make it respond a bit more to a suddend increase of decrease in temperature.
 

Offline Avacee

  • Supporter
  • ****
  • Posts: 299
  • Country: gb
Re: [AVR] ADC oversampling function
« Reply #29 on: February 17, 2017, 10:10:45 pm »
Unless you are trying to maintain a set temperature to a very precise value just how quickly do you need the fan to respond to a change in temperature?

If you don't need the fan to have an instantaneous effect on the temperature then controlling the fan speed every fraction of a second is overkill.
Imho, a fan speed that changes frequently is rather annoying, even if it's only changing by a few RPM .. OCD FTW! :p
Have you considered slow,medium,fast fan speeds and set temperature points with some hystersis?

This could remove the need for the extra resolution as you are averaging the values over a longer timeframe so have more samples to average.
With regard to noise - you could store N samples then discard the X highest and lowest values and average the remaining values.

« Last Edit: February 17, 2017, 10:22:00 pm by Avacee »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] ADC oversampling function
« Reply #30 on: February 17, 2017, 10:22:19 pm »
The response time of the mechanical/thermal system is an unknown which is why I am looking at a fairly dumb linear response / look up table. So no I don't need to respond fast. As I said before if anything what I need most from this little function is a filtered value. If I gain resolution then that is nice but I'm not relying on it. As I said before the last system I did had its output PWM jumping all over the place as I was relying on a single measurement at a point in time no averaging, this was not a big problem as the input to the fan had its own lowpass filter anyway. So obviously I should do some averaging and the fan I am using now is cleverer and has a distal input rather than a low pass filtered input and it also does checks on the PWM input and only response to a change in speed if it sees a certain amount of identical PWM pulses.

A low medium and high fan speed is probably not appropriate. There won't be a problem with the fan ramping up and down quickly as I believe the thermal mass is quite high and should not be sharp responses in the system. If the fan needs to run hard it needs to run hard, if it does not need to it does not need to. If anything because I am using as many steps as possible in resolution speed change would never be rapid and hardly noticeable. If I were to jump from a low to medium speed and back again you would notice the fan ramp up and down as the fan has its own control system whereby it does not respond immediately. If I include more steps then the increase will be gradual.
 

Offline Avacee

  • Supporter
  • ****
  • Posts: 299
  • Country: gb
Re: [AVR] ADC oversampling function
« Reply #31 on: February 17, 2017, 11:14:55 pm »
Nod - understand now about the fan ramping up/down gently.



 

Offline Andreas

  • Super Contributor
  • ***
  • Posts: 3243
  • Country: de
Re: [AVR] ADC oversampling function
« Reply #32 on: February 18, 2017, 06:44:22 am »
if I want to be a bit more accurate on the target I could have a proportion response but do something like

if ("new reading" > "last reading")
add some extra speed
else
just follow the straight line

Just to make it respond a bit more to a suddend increase of decrease in temperature.

Hello,

I think that is the root of your problems.
You are adding some kind of D-Part which is not adjusted to the thermal mass control loop.

With best regards

Andreas
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] ADC oversampling function
« Reply #33 on: February 18, 2017, 08:22:15 am »
yes which is why I want to avoid doing that, if they want a stupid amount of nailing of the target then I probably need to put 80% of the fan performance into t+50% of max deviation, like an exponential curve. Obviously if you push that too hard you end up with bang bang control anyway which almost defeats the object. As things stand I'll probably work in T +/-1C because they are a bit clueless and in the clouds with how real life works. If this was over a wider range like 10C I'd have more mapping to play with to get a balance of power versus effectiveness of the cooling to their expectations.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] ADC oversampling function
« Reply #34 on: February 24, 2017, 09:30:06 pm »
Well I just tried out my new peice of code and I am very pleased with it. Some discussion of the analogue side of things ended up here: https://www.eevblog.com/forum/beginners/time-constant-involving-a-resistor-divider/25/ . Essentially with a 470 ohm pull up resistor and a thermistor with a resistance of not a lot less at my intended temperature I have a 470nF capacitor in parallel with the thermistor and used a PWM output to make some noise through a 1Mohm resistor. I set my function for 3 bits of oversampling and the result is quite pleasant. I would of had 10 b/C of resolution but the theoretical resolution in oversampling is not about 80b/C, infact the output PWM steps happen in about 0.5% increments instead of the 4% increments I'd be getting with the natural 10b resolution.
 

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7725
  • Country: ca
Re: [AVR] ADC oversampling function
« Reply #35 on: February 25, 2017, 05:53:46 am »
Can you specify the temperature accuracy you need over what range?

I achieved a 0.1 degree Celsius resolution with a 10 bit ADC from -20 to +120 degrees Celsius by only adding a transistor and a second resistor load for the thermosistor so when the light load on the thermosistor read too low a value on the ADC, I turned on the transistor, just like changing the range the range on an auto ranging ohm meter, to get that extra precision at lower temperatures.


Well, combined with oversampling, you now can get 0.025 degree precision.  I think your thermosistor wouldn't be that precise anyways..
« Last Edit: February 25, 2017, 05:55:28 am by BrianHG »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] ADC oversampling function
« Reply #36 on: February 25, 2017, 08:56:20 am »
Well accuracy and resolution are two different things. My sensor is actually 5% but I was looking for as many control steps as I could muster. This experiment was setup over 2C which means I'd have to pull the extra resolution out to see such small step changes in PWM which verifies that my oversampling is working. As the board I tried this on is already designed oversampling was the only option. If I designed a board again I'd use an instrumentation amplifier to extract the amount of range I require and amplify it to get more resolution.
 

Offline 0xPIT

  • Regular Contributor
  • *
  • Posts: 65
Re: [AVR] ADC oversampling function
« Reply #37 on: February 25, 2017, 01:38:02 pm »
I've implemented the oversampling and calibration concepts from the AVR datasheets here:

https://github.com/0xPIT/adc

Usage example in https://github.com/0xPIT/UltiDMM

After calibration, this works very well.

 - pit
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [AVR] ADC oversampling function
« Reply #38 on: February 25, 2017, 07:02:30 pm »
My C foo is not good enough yet to understand all of it (I'm just at the point where I can recognise what my own code does an hour after writing it). How does the calibration work ?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf