Changing adcresolution of spark core

Is there anyway to change the default 12 bit resolution in spark core…i cant seem to use analogReadresolution() function…gives error

That is an Arduino Due extension that is not available elsewhere, including Spark.

The actual ADC in the STM32 ARM is 12-bits and cannot be changed that I know of.

If you say what you are trying to do by changing the resolution, we can probably help you.


I have a few questions on this topic I’ve been wanting to ask -

  1. The STM32 documentation around the ADC discusses reference voltages of ref + and ref -. From what I can tell are these internally connected to +3.3* and GND. In other words what is the valid analog input range on the Spark?

  2. The 12 bit resolution gives us 4096 steps. If my first assumption (0 - 3.30V) is correct then each step is equal to 0.8mV - correct?

  3. What can we expect the input current to be? Maybe that is not the correct question, but if I’m designing a circuit where I want to measure a voltage from a voltage divider what should I use in the design as the equivalent resistance and capacitance of the analog input on the Spark?

Hi @mtnscott

The range you give 0-3.3V is correct (unless you meant the absolute min/max voltages to avoid damage which are slightly different). The step is approximately 3.3V / 4096 ~ 0.8mV/step but the 3.3* voltage is not exactly 3.300V and every core is a bit different. The ADC reference voltage can vary over time and temperature and with Vin or 3.3V voltage too.

The input current is a more nuanced question to answer since the converter is a switched capacitor ADC and current will flow in or out of the pin depending on the voltage being measured. Inside the part is a sample-and-hold capacitor of around 8pF (max) that they charge to 3.3V/2=1.65V which is then switched to connect to the input pin and allowed to settle. Current can flow in or out of the part while sampling. Then the input pin is switched off and that S/H cap is drained into another ADC cap whose voltage is then measured, bringing the cap to 0Vin the process typically. The input also has leakage current of +/- 1uA presumably to the substrate. See Figure 38 on page 78 of the PDF in the Spark hardware github area.

So a better question might be what is the impedance of the ADC inputs: it varies with sampling speed and mode but I believe is currently around 40k ohm for the settings used in the Spark firmware. Going slower will raise the effective input impedance.

If you are designing something with a very low quiescent current or high impedance that you want to connect to the ADC, you should probably buffer the signal with an op-amp to be safe. There are other tricks you can play like the small capacitor to ground–it depends on how hackish you want to be.

1 Like

Thanks for the clarification… I was able to find a way around it by tweaking the code…
Also the reference voltage for spark core avr chip is 3.3 v right?

Yes the reference is approximately 3.3V. It is a filtered version of the 3.3V supply to the core.