a simple digital peak detector will give a reasonable result,
eg
2v p-p input offset to approx 1.5v for a vcc of 3.3v for adc

[arduino ide serial plotter]
at a 200us sample rate

at 1000us sample rate , its still not bad

Code:
'****************************************************************'* Name : peak_detector_ADC_16F18446.pbp
'* Author : richard
'* Notice :
'* : All Rights Reserved
'* Date :
'* Version : 1.0
'* Notes :
'====== PIC 16F18446 FUSES ========================================================================
#CONFIG
__config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
__config _CONFIG2, _MCLRE_ON & _PWRTS_PWRT_64 & _LPBOREN_OFF & _BOREN_SBOREN & _BORV_LO & _ZCDDIS_OFF & _PPS1WAY_OFF & _STVREN_ON
__config _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
__config _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTD_OFF & _WRTSAF_OFF & _LVP_OFF
__config _CONFIG5, _CP_OFF
#ENDCONFIG
' ====== REGISTERS =================================================================================
ANSELA = % 00100000
ANSELC = % 00000000
TRISC = % 11101111
ADCON0 = % 10000100 'ADC is ON, RIGHT justified result
' ====== DEFINES ===================================================================================
DEFINE OSC 32
DEFINE ADC_BITS 12 'Number of bits in ADCIN result
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
'DEFINE HSER_SPBRG 138 ' 57600 Baud @ 32MHz, -0.08%
DEFINE HSER_SPBRG 68 ' 115200 Baud @ 32MHz, 0.64%
SP1BRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
pause 500
RC3PPS = 15 ;tx PORTC.3
RA0PPS = 15 ;tx PORTA.0 ;PK3
RC4PPS = 0 ;rx unused
LED VAR LATC.4
clear
new_read var word
State Var BYTE 'serial Bd (baud per second)
peak var word
last var word
' ====== setup PROGRAM =============================================================================
led = 1
ADCIN 5, last
pause 1000
HSEROUT ["ready ",13,10]
led = 0
;707 -3670
' ====== MAIN PROGRAM =============================================================================
MAIN:
ADCIN 5, new_read ' ADC
gosub getpeak
HSerout ["ADC:",dEC new_read,",peak:",dEC peak,13,10] ' PLOTTER
pauseus 200 ; sample rate
GOTO MAIN
getpeak:
if state==0 then ;rising
if new_read < last then
state = 1;falling
peak = last
endif
else ;falling
if new_read > last then
state = 0;rising
peak = last
endif
ENDif
last = new_read
return
Bookmarks