Author Topic: Adjusting the range for the Current Ranger  (Read 952 times)

Frederik Madsen

  • NewMember
  • *
  • Posts: 1
Adjusting the range for the Current Ranger
« on: February 19, 2021, 08:48:30 AM »
Hello,
Since the currents I am measuring are between 1-30mA, I would like to change the resolution so I get 50mV/mA.
I know how to change the resistors, but I am unclear on which part of the software is needed to be changed in order for the OLED screen to display the right current.

Thanks in advance.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Adjusting the range for the Current Ranger
« Reply #1 on: February 19, 2021, 09:32:24 AM »
The key is in this function:

void readVOUT()

Specifically readDiff is the result of the ADC reading. Its a 12bit value that is then adjusted depending on the reference - either full or half of the 3.3V VDDANA. You will see several places in code doing something like this, calculating the actual VOUT based on the assumed reference value:

VOUT = readDiff*ldoOptimized*(BIAS?1:OUTPUT_CALIB_FACTOR);

Here the readDiff is the value from the ADC, then it is multiplied by ldoOptimized which is the 3300 (represents LDO value 3.3v adjusted by calibration and stored in EEPROM), or roughly half of that if the ADC reference is half VDDANA. This ldoOptimized is adjusted during the operation of CR, based on the mode and reference, in this function:

Code: [Select]
void ldoOptimizeRefresh() {
  if (analog_ref_half)
    ldoOptimized = (ldoValue*500)/ADCFULLRANGE;
  else
    ldoOptimized = (ldoValue*1000)/ADCFULLRANGE;
}

I hope this helps you, but make sure you know what you are doing  ;D

Also since this is qualifies as hacking .. while cool and interesting to watch ... no real support or warranty can be offered against any issues  ;)
Of course, always save your current.uf2 firmware from the bootloader before you change anything (see guide)! Then you can revert if things go wrong.