Jump to content

Problem using Arduino code in Energia

Recommended Posts

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

What about my my code? It just works I don't think you really need the sampling intervals to be spot on accuracy that you need a timer. If you really want it to be better just do   // Very simple

Yes and remove all the timer stuff from setup So something like this   // Very simple Arduino Lithium-ion battery capacity tester // from electronicsblog.net   #define LED 13 #define resistor 6.9

Your code is ATmega specific (you're directly addressing the timer peripheral of the Arduino), and hence cannot be run at the MSP430/launchpad. You could translate this code to work for the Launchpad.

I just got some feedback on my story about getting rid of floating-points. (I posted it on my blog)

Instead of multiplying by 4, you could also take 4 samples and add them up, this is called oversampling.

For every doubling in the number of samples, you're effectively adding one bit to the ADC resolution.

So for our 10-bit ADC:

2 samples summed up results in 11-bit resolution.

4 samples summed up results in 12-bit resolution.

8 samples summed up results in 13-bit resolution.

n samples summed up results in (10 + log2(n))-bit resolution.

Take into account that this can only be used for slow signals and slow measurements. If your signal changes rapidly, you'd be smoothing the signal out and effectively miss information (if the change is faster than twice your sampling time). E.g.: you measure your ADC every 10ms, but the signal changes within 15ms; you'll not be able to see the real change in your values. This is not really an issue in displaying, but when you're logging values it becomes a problem (you cannot make graphs of it anymore).

For every doubling in oversampling, you're sacrificing time. If you have an ADC that can sample at 10Hz, but you want an update of your value every second, you cannot oversample more than 10 times (13.322-bit resolution), because you'd drop below the effective sampling frequency of 1Hz.

Link to post
Share on other sites

Even with proper dither (noise), the performance is limited by ADC INL, DNL, and other sources of imprecision. The theory that says the ENOB can be increased by log2(N) by oversampling N times assumes a perfect ADC and perfect dither. Neither exist in real circuits.

Link to post
Share on other sites

Imperfect dither should work just as good, the inherent non-linearity of the ADC is still existing, so it doesn't solve that.


@semicolo: Why do I need to oversample 4 times AND shift once to get 1 extra bit? I don't get it, adding up 4 samples saves me the multiplication, and since I average over multiple samples I increase precision (in theory). I don't see how I'd need to double the oversampling and shift again to get extra bits.

Link to post
Share on other sites

Hard to explain the real maths on a forum and it's been more than 10 years I've learned about it and never really used for real.

Adding more samples and shifting is supposed to lower the SNR too, if you just keep adding samples, the noise adds too and you don't really gain any precision.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...