历史上的今天
今天是:2025年05月07日(星期三)
2019年05月07日 | MSP430的ADC转化+均值滤波
2019-05-07 来源:eefocus
由于各种干扰,MSP430在进行ADC转化时总会出现波动,为了提高数据的可靠性,可以进行软件滤波,其中均值滤波操作简单,效果良好:
//******************************************************************************
// MSP-FET430P140 Demo - ADC12, Using the Internal Reference
//
// Description:
//
//
// MSP430F149
// ---------------
// | |
// Vin -->|P6.0/A0 |
// | |
//
//
// M. Mitchell
// Texas Instruments Inc.
// Feb 2005
// Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************
#include #include"lcd.h" #include"adc.h" int meanValueFilter(void); void DelayXms(unsigned int i); //delay about x ms void int2charsLcdshow1(int value); //LCD show a value from 0 to 9999 void int2charsLcdshow2(int value); //LCD show a value from 0 to 9999 void main(void) { int adcValue1,adcValue2; WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer LcdReset(); //initialize the lac1602 while (1) { adcValue1 = meanValueFilter(); adcValue2 = GetAdcValue2(); int2charsLcdshow1(adcValue1); int2charsLcdshow2(adcValue2); DelayXms(500); } } void DelayXms(unsigned int i){ unsigned int j; for( ; i>0; i--){ for(j=0;j<200;j++); } } /**************************************************************************** *函数名: int2charsLcdshow1(void) / *作用 :将AD转化的结果,在LCD1602上进行显示 / *返回值:无 / *参数 :int / *作者 :Zhenhua Liu / *时间 :2017.12.08 / *******************************************************************************/ void int2charsLcdshow1(int value){ int bits=0,ten = 0,hundred = 0,thousand = 0; thousand = value/1000; hundred = value%1000/100; ten = value%100/10; bits = value%10; Disp1Char(0,0,thousand+'0'); Disp1Char(1,0,hundred+'0'); Disp1Char(2,0,ten+'0'); Disp1Char(3,0,bits+'0'); } void int2charsLcdshow2(int value){ int bits=0,ten = 0,hundred = 0,thousand = 0; thousand = value/1000; hundred = value%1000/100; ten = value%100/10; bits = value%10; Disp1Char(0,1,thousand+'0'); Disp1Char(1,1,hundred+'0'); Disp1Char(2,1,ten+'0'); Disp1Char(3,1,bits+'0'); } /**************************************************************************** *函数名: meanValueFilter(void) / *作用 :启动ADC转化之后,将采集到的10次AD数据进行求和平均,均值滤波 / *返回值:int型 / *参数 :无 / *作者 :Zhenhua Liu / *时间 :2017.12.08 / *****************************************************************************/ int meanValueFilter(void){ unsigned int i; float sum=0; int meanvalue=0; for(i=0;i<10;i++){ sum+=GetAdcValue1(); } meanvalue = sum/10.0; //隐式类型转化,flozt->int return meanvalue; }
史海拾趣
|
我单位发生一起越级跳闸。低压和高压都跳了,检查结果现场发现是一台75KW的电机角形开路所至。控制该电机电子开关发现进线空开有大量弧光烧黑。可控硅电源和阻容吸收电路炸断。电路绝缘全部破坏。请教一下各位同仁。是否是电机在运行过程中。外控没 ...… 查看全部问答> |
|
当本人把以下代码嵌入到C文件中 __asm { MRC p15,0,r10,c0,c0,0; } 编译出错的信息为: War ...… 查看全部问答> |
|
我的代码如下: if(uVirKey == VK_NUMPAD0 ) { int i = GetKeyState(VK_MENU) ; if( i < 0 ) dosomething(); } 为什么不能截取组合键?谢谢!… 查看全部问答> |




