|
/*P1.1检测VPP,最小可采40HZ*/
#include "msp430g2553.h"
unsigned int table_Valu[128] = {0}; //存放ADC10采样数据
float y,vpp;
void ADC10_WaveSample(unsigned char inch);
void ADC10_init();
void main(void)
{ int k=0,max,min;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_12MHZ; // Set range
DCOCTL = CALDCO_12MHZ; // Set DCO step + modulation
DCOCTL = DCOCTL&0xE0; //关闭混频器,得到纯净频率
ADC10_init();
WDTCTL = WDT_ADLY_1000; // WDT 1000ms, ACLK, interval timer
IE1 |= WDTIE;
_enable_interrupts();
while(1)
{
ADC10_WaveSample(1);
max=table_Valu[1];
min=table_Valu[1];
for( k=0;k<128;k++)
{ if(table_Valu[k]>max)
max=table_Valu[k];
if(table_Valu[k]
min=table_Valu[k];
}
y=(max-min)*3.58/1023;
vpp=y/0.748-0.877;
}
}
/******************采128个点********************************/
void ADC10_WaveSample(unsigned char inch)
{
int j=0,i=0;
for( j=0;j<128;j++) //循环采样64次
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
for(i=0;i<200;i++); //延时采样
table_Valu[j]=ADC10MEM;
}
}
//-----ADC10 初始化-----
void ADC10_init(void)
{ int m=0;
ADC10CTL0 &= ~ENC;
ADC10CTL0 =SREF_0 + ADC10SHT_3 +ADC10ON;//电源电压为参考电压
ADC10CTL1 = INCH_1+CONSEQ_0;
ADC10AE0 |= BIT1;
for(m=0;m<350;m++);
ADC10CTL0 |= ENC;
}
|
|