Hi, In My application I am sampling 3 phase current at sampling frequency of 800Hz, currently I am using the below code and could get a steady rms without any problem.. I am using a bipolar ADC with 2's complement output format with 12 bit resolution including the sign bit
if((rCurrent&0x0800)==0x0800) { ut =((~rCurrent)+1)&0x00000FFF; redInputCurrent[sampleCount]=(((float)ut)/2048)*-2.5; } else { ut = rCurrent&0x00000FFF; redInputCurrent[sampleCount]=((float)ut/2048)*2.5; } if((yCurrent&0x0800)==0x0800) { ut =((~yCurrent)+1)&0x00000FFF; yellowInputCurrent[sampleCount]=(((float)ut)/2048)*-2.5; } else { ut = yCurrent&0x00000FFF; yellowInputCurrent[sampleCount]=((float)ut/2048)*2.5; } if((bCurrent&0x0800)==0x0800) { ut =((~bCurrent)+1)&0x00000FFF; blueInputCurrent[sampleCount]=(((float)ut)/2048)*-2.5; } else { ut = bCurrent&0x00000FFF; blueInputCurrent[sampleCount]=((float)ut/2048)*2.5; } if((eCurrent&0x0800)==0x0800) { ut =((~eCurrent)+1)&0x00000FFF; earthInputCurrent[sampleCount]=(((float)ut)/2048)*-2.5; } else { ut = eCurrent&0x00000FFF; earthInputCurrent[sampleCount]=((float)ut/2048)*2.5; } sampleCount++; if(sampleCount>15) sampleCount=0; arm_rms_f32(&redInputCurrent[0], 16, &rCurrentValue); arm_rms_f32(&yellowInputCurrent[0], 16, &yCurrentValue); arm_rms_f32(&blueInputCurrent[0], 16, &bCurrentValue); arm_rms_f32(&earthInputCurrent[0], 16, &eCurrentValue); CurrentValue[RED_CURRENT_CHANNEL] = rCurrentValue * R_CURRENT_RATIO; red_i_index = (int)CurrentValue[RED_CURRENT_CHANNEL]/5; CurrentValue[RED_CURRENT_CHANNEL] = CurrentValue[RED_CURRENT_CHANNEL] + red_offset[red_i_index]; CurrentValue[YELLOW_CURRENT_CHANNEL] = yCurrentValue*Y_CURRENT_RATIO; yellow_i_index = (int)CurrentValue[YELLOW_CURRENT_CHANNEL]/5; CurrentValue[YELLOW_CURRENT_CHANNEL] += yellow_offset[yellow_i_index]; CurrentValue[BLUE_CURRENT_CHANNEL] = bCurrentValue*B_CURRENT_RATIO; blue_i_index = (int)CurrentValue[BLUE_CURRENT_CHANNEL]/5; CurrentValue[BLUE_CURRENT_CHANNEL] += blue_offset[blue_i_index]; CurrentValue[EARTH_CURRENT_CHANNEL] = eCurrentValue*E_CURRENT_RATIO; earth_i_index = (int)CurrentValue[EARTH_CURRENT_CHANNEL]/5; CurrentValue[EARTH_CURRENT_CHANNEL] += earth_offset[earth_i_index];
but the moment I try to convert these samples from float to q_15 format for filtering purposes the range reduces by half.. i.e. without conversion and filtering as above, I could measure current from 180mA to 43A with 1:1000 ratio CT.. but when I introduce FIR filtering the reading range reduces from 800mA to 19A... I have tried bypassing the filtering after the q15 conversion and calculating the rms of the signal and the problem still persists.. Can anybody help on this regard.