LAUNCHXL-F28379D: RMS Value calculation

Part Number: LAUNCHXL-F28379D
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Hello Team, 

I am working on a sine wave input from an adc pin on the launchxlf28379d. For my application i need to find a peak for that sine wave. Now i can either rely on a simple if else loop to find the instantaneous peak which is not working as the resolution keeps on varying as the sine wave. I thought of calculating the RMS value for the sine wave but i am wondering how do i sample my sine wave. I can use adc pins comfortably and i know how to take inputs. 

The main problem is when i increase the voltage i.e. the maximum amplitude of the sine wave my peak value is updated perfectly as i can use the ascending order comparison (if loop) but when i decrease my voltage i.e. the peak amplitude of the sine wave, the peak value concept does not work as comparing values in descending order will send me to 0 every time. this is why i thought of calculating and using rms value as my peak. 

for example the initial peak is 3000, and we increase the peak to 3500, my new peak is updated beautifully. but when its reduced to lets say 2000, no logic seems to work. as all the instantaneous points have some resolution value, the peak value also keeps on increasing and decreasing with the instantaneous amplitude value of the sine wave.  

Can anyone please provide me a snippet that i could take reference from to sample my sine wave from lets say adcina3 and find its peak or rms? (peak preferred) I have tried multiple techniques but i am not able to do what i need. 

Any type of support will be helpful

Best

Chirag