首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > WinCE >

ARM板开发触摸屏程序,出现飘屏!求解决方法

2012-04-03 
ARM板开发触摸屏程序,出现飘屏!急求解决办法!我用ARM板测试一个触摸屏程序,偶尔出现飘屏!源码如下:C/C++ c

ARM板开发触摸屏程序,出现飘屏!急求解决办法!
我用ARM板测试一个触摸屏程序,偶尔出现飘屏!
源码如下:

C/C++ code
#include "def1.h"#include "2440addr.h"#include "2440lib.h"#include "config.h"#define REQCNT 30#define ADCPRS 9    //YH 0627#define LOOP 1void  AdcTsAuto(void);int TouchPanelCnt=0;  // 触摸屏次数的记录struct TouchLocation{    volatile int x;    volatile int y;}TPxyLocation = {0,0};volatile int test_x;    volatile int test_y; INT8U ts_status;//触摸屏的状态(校准还是测试)//static U16 ts_lefttop_x,ts_lefttop_y,ts_rightbot_x,ts_rightbot_y,ts_leftbot_x,           //ts_leftbot_y,ts_righttop_x,ts_righttop_y; struct TouchLocation TestPoint[8] = {0};extern void AdcTsAuto_Handler(void);extern OS_EVENT  *TP_m_box;//extern OS_EVENT  *Cal_m_box;           //extern OS_EVENT  *Lag_m_box; //unsigned int buf[3][2];U16 Ptx[6],Pty[6],tmp[6] = {0,0,0,0,0,0};//U8 index = 0;void AdcTsAuto(void){     int i;    U32 saveAdcdly;    if(rADCDAT0&0x8000)    {        //Uart_Printf("\nStylus Up!!\n");        rADCTSC&=0xff;    // Set stylus down interrupt bit    }    //else             //    Uart_Printf("\nStylus Down!!\n");    rADCTSC=(1<<3)|(1<<2);         //Pull-up disable, Seq. X,Y postion measure.    saveAdcdly=rADCDLY;    rADCDLY=40000;                 //Normal conversion mode delay about (1/50M)*40000=0.8ms    rADCCON|=0x1;                   //start ADC      for(i=0;i<5;i++)    {       // rADCTSC  = (1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);                    rADCTSC=(1<<3)|(1<<2);         //Pull-up disable, Seq. X,Y postion measure.    saveAdcdly=rADCDLY;    rADCDLY=40000;                 //Normal conversion mode delay about (1/50M)*40000=0.8ms              rADCCON |= 0x1;             //Start Auto conversion        while(rADCCON & 0x1);       //Check if Enable_start is low        while(!(0x8000&rADCCON));   //Check ECFLG      while(!(rSRCPND & (BIT_ADC)));  //check if ADC is finished with interrupt bit              Pty[i] = (0x3ff&rADCDAT1);        Ptx[i] = (0x3ff&rADCDAT0);                       //OSPrintf("----- ========(%04d,%04d)=======\n",Ptx[i], Pty[i]);      }   // buf[3][0] =((buf[0][0] + buf[1][0] + buf[2][0])/3)*10;    //buf[3][1] =((buf[0][1] + buf[1][1] + buf[2][1])/3)*10;    Ptx[5]=(Ptx[0]+Ptx[1]+Ptx[2]+Ptx[3]+Ptx[4])/5;    Pty[5]=(Pty[0]+Pty[1]+Pty[2]+Pty[3]+Pty[4])/5;    OSPrintf(" ========(%04d,%04d)=======\n",Ptx[5], Pty[5]);                   //OSPrintf("----- ========(%04d,%04d)=======\n",TPxyLocation.x,TPxyLocation.y);     TPxyLocation.x=Ptx[5]*10;     TPxyLocation.y=Pty[5]*10;     //TPxyLocation.x=TPxyLocation.x*10;    // TPxyLocation.y=TPxyLocation.y*10;             //OSMboxPost(TP_m_box,(void*)1);     //YH 0627, To check Stylus Up Interrupt.     rSUBSRCPND|=BIT_SUB_TC;     ClearPending(BIT_ADC);     rINTSUBMSK&=~(BIT_SUB_TC);     rINTMSK&=~(BIT_ADC);                  rADCTSC =0xd3;    //Waiting for interrupt     rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.            while(1)        //to check Pen-up state            {             if(rSUBSRCPND & (BIT_SUB_TC))    //check if ADC is finished with interrupt bit                 {                    //Uart_Printf("Stylus Up Interrupt~!\n");                                        break;    //if Stylus is up(1) state                }            }                    //Uart_Printf("count=%03d  XP=%04d, YP=%04d\n", TouchPanelCnt++, TPxyLocation.x, TPxyLocation.y);    //X-position Conversion data                OSMboxPost(TP_m_box,(void*)1);    rADCDLY=saveAdcdly;     rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal.    rSUBSRCPND|=BIT_SUB_TC;    rINTSUBMSK &=~(BIT_SUB_TC);    // Unmask sub interrupt (TC)         ClearPending(BIT_ADC);}void Test_Touchpanel(void){    //OSPrintf("ADC touch screen test\n");    //OSPrintf("[1] calibration touch screen \n");   // OSPrintf("Please touch the location of left top \n");    //ts_status = TS_JUSTIFY_LEFTTOP;        rADCDLY=50000;                  //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms    rADCCON=(1<<14) | (ADCPRS<<6);//| (0<<3) | (0<<2) | (0<<1) | (0);       //ADCPRS En, ADCPRS Value       rADCTSC=0xd3;  //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En   // pISR_ADC = (uint32)AdcTsAuto_Handler;   pISR_ADC = (int)AdcTsAuto;    rINTMSK &= ~BIT_ADC;       //ADC Touch Screen Mask bit clear    rINTSUBMSK &= ~(BIT_SUB_TC);} 



谁能帮我看看这段代码有问题麽!

[解决办法]
仅仅是多次采样求平均还是不够的,
在求平均之前最好先去除一个最大值和一个最小值,
特别是在轻按时这个差值会很大,从而导致楼主所说的问题。
[解决办法]
每次采样时,需要与前几次的平均值比较,差别很大的叫“野点”,应该去除。这个叫滤波;当前后两次的差值小于某个值时,这个值也不能要,这个叫去抖动。
一般来说,触摸屏 应该做 去抖动 和 滤波。
一般来说, 去抖动 和 滤波需要在驱动层做。但如果你是用linux的话,请搜索下libts,它已经在应用层帮你做得很好了。
[解决办法]
最好先检查一下硬件,看ADC的参考电压是否稳,还是说参考电压上面有毛刺出现.
[解决办法]
你说的漂屏,不知有多严重,如果是开发板,用别人的程序看一下,有没有这个问题,一般都是硬件问题造成的,也就是AD采样不稳定。软件能做的,也就是数字滤波,比如采8次,回来放到一个数据,去掉最大值,去掉最小值,然后求平均值,三星官方BSP里面的TOUCH驱动,也都是这样做的。

热点排行