RMS Voltage Calculation for AC input

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello there,

I am having PSOCEVAL 1 CY3210 Kit with me. I need to measure the max and min voltages for the ac input signal that i am giving. The signal is a sinusoidal with pk to pk of 3 volts, oscillating in 0.5 to 3.5 volts at frequency 500 Hz. I am using a signal generator to give the input so i am at liberty to set the frequency. I have varied the DC offset as for the voltage input to be only in positive.

I need to calculate the Vmax and Vmin peak values of the signal. Then Vpeak= (Vmax- Vmin)/2

Vrms=Vpk*0.7071

This what i am aiming to acheive. I am now using a voltmeter project that i got form the cypress and i am trying to edit the program to be suitable to my need.

The project is using the input to go through a PGA with 1 gain. Then it is sent through ADCINCVR with 12 bit resolution.

I am using a simple method to get Vmax and Vmin as follows. I am trying to display both on the LCD.

if(fVolts>temp1){

temp1=fVolts; //Vmax

}

else if(fVolts<temp2){ //Vmin

temp2=fVolts;

}

The problem is that both values shown are DC bias values and both are same.

I am attaching the project here. Please help me with this.

Regards

Shravan

0 Likes
1 Solution
SampathS_11
Moderator
Moderator
Moderator
250 sign-ins 250 solutions authored 5 questions asked

Hello Shravan,

The function ftoa uses the same static buffer for every call. Hence, it would contain the latest conversion result. You can declare two separate buffers for minimum and maximum. After calling ftoa, you can copy the ftoa buffer to the buffer you have declared for minimum and maximum,

Thanks,

Sampath

View solution in original post

0 Likes
3 Replies
SampathS_11
Moderator
Moderator
Moderator
250 sign-ins 250 solutions authored 5 questions asked

Hello Shravan,

The function ftoa uses the same static buffer for every call. Hence, it would contain the latest conversion result. You can declare two separate buffers for minimum and maximum. After calling ftoa, you can copy the ftoa buffer to the buffer you have declared for minimum and maximum,

Thanks,

Sampath

0 Likes
Anonymous
Not applicable

Thank you for the reply Sampath.

I am a novice at coding and stuff. Can you tell me as to how to declare and use different buffers for the ftoa command ?

Regards

Shravan

0 Likes

You can declare buffers like this

char strMaximum[8];

char strMinimum[8];

// Copy ftoa buffer to the declared buffers.

pResult1 = ftoa(temp1,&iStatus1);

strcpy(strMaximum, pResult1);

pResult2 = ftoa(temp1,&iStatus2);

strcpy(strMinimum, pResult2);

0 Likes