Current sense analog offset

Hi,

So I finally reached the point where I have to configure the sensors. Using these current sensor amplifiers : https://www.maximintegrated.com/en/products/analog/amplifiers/MAX40056F.html

The sensors are bi-directional, has a 1.5 voltage output at no load/current. So the analog values goes down when current flows one direction and up when flowing the opposite.

Does the foc-lib take these reading?

mkay,

I see there are something going on in the src.

"* Function finding zero offsets of the ADC
*/
void calibrateOffsets();
float offset_ia; //!< zero current A voltage value (center of the adc reading)
float offset_ib; //!< zero current B voltage value (center of the adc reading)
float offset_ic; //!< zero current C voltage value (center of the adc reading)

};"

And agein, here:

// Function finding zero offsets of the ADC
void InlineCurrentSense::calibrateOffsets(){
const int calibration_rounds = 1000;

// find adc offset = zero current voltage
offset_ia = 0;
offset_ib = 0;
offset_ic = 0;
// read the adc voltage 1000 times ( arbitrary number )
for (int i = 0; i < calibration_rounds; i++) {
    offset_ia += _readADCVoltageInline(pinA);
    offset_ib += _readADCVoltageInline(pinB);
    if(_isset(pinC)) offset_ic += _readADCVoltageInline(pinC);
    _delay(1);
}
// calculate the mean offsets
offset_ia = offset_ia / calibration_rounds;
offset_ib = offset_ib / calibration_rounds;
if(_isset(pinC)) offset_ic = offset_ic / calibration_rounds;

}

Guess this answers that.

Hey @Juan-Antonio_Soren_E
Yep the library will do it automatically when you init your current sense.
But if you prefer to set these values yourself, you can override them afterwards and set the cs.offset_ia = your_value.

@Antun_Skuric

By experimenting with my LED setup, I found these lines helpfull :

 analogWriteResolution(12);
 analogWrite(10,  map(10, 0, 16380, 0, 4095));

Does the FOCinit(); do something similar. I think for low resistance motors, the benefit of analogWrite resolution is good to have, when taming high loads.

Huh, we did not expose this to the API but we do set PWM resolution in the hardware specific code directly. So if you wish to increase it that’s the way to go. For most of the architectures we have a #define _PWM_RANGE or something like that.

Ah, I see… It must be this you are referring to:


#ifndef SIMPLEFOC_SAMD_PWM_RESOLUTION
#define SIMPLEFOC_SAMD_PWM_RESOLUTION 1000
#define SIMPLEFOC_SAMD_PWM_TC_RESOLUTION 250
#endif

Is there a reason for the different resolutions for TCC and TC.
[Edid] I see the TC variables is only used by SAMD21.

Could you give a brief explanation on those variables?

there is a lot to take in…

I believe the sporadic behavior of my motor test, was because the hardware specific code, assigned wrong pin configuration, and thereby did not do a proper setup of the pin, which was assigned to TC. That left two pins with synchronized resolution and one pin (the TC pin) on standard resolution.

Yeah, I went back to the analog sensors, and see there is something wrong with the readings. My voltmeter shows a stable and good value, centered on 1.5v (no load) coming from the current sensors. When I turn op the LED´s (on a corresponding pin), I am able to read 1.25v on my voltmeter, but the readings from the analog pin are off target and are not responsive to small changes.

Will have to run the SAMD_analog correction example and see if it helps.

I found the hardware avaring function to solve above analogRead() issues.

Now the readings are much more stable and gives a usable reading in reference to AREF (3.6v) and the measured voltage on the sensor output pin.

 ADC1->SAMPCTRL.reg = 5;   
  while( ADC1->SYNCBUSY.reg & ADC_SYNCBUSY_SAMPCTRL ); //wait for sync
// Averaging (see datasheet table in AVGCTRL register description)
		ADC1->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_32 |    // 32 samples
							ADC_AVGCTRL_ADJRES(0x4);   // Setting ADJ bit
		while( ADC1->SYNCBUSY.reg & ADC_SYNCBUSY_AVGCTRL );  //wait for sync

Edit: I might be comparing apples and bananas here. I think the issue might just be the PWM duty cycle and the fact that I was testing on LED´s.