第一次調(diào)CH579里面的Touch-Key,用的TKY_CH579庫,有沒有哪位大神用過,教教我調(diào)試的時候從哪一步開始調(diào)起?為啥我算的充電時間(0x25),跟平穩(wěn)時達到3000的充電時間(0x60)差這么多啊?
大家使用這個TKY_CH579時,初始化都是怎么處理的?沒有出現(xiàn)過上電基線值下降浮動導(dǎo)致觸發(fā)按鍵任務(wù)的情況嗎?急問?。?!
有沁恒技術(shù)人員給點技術(shù)支持嗎???
?
?/* 配置TouchKey功能檢測 */
?TKY_BaseInitStructure.filterMode = FILTER_MODE_2;
?TKY_BaseInitStructure.filterGrade = 4;
?TKY_BaseInitStructure.maxQueueNum = MAX_QUEUE_NUM;
?TKY_BaseInitStructure.baseRefreshOnPress = 0;
?//---基線更新速度,baseRefreshSampleNum和filterGrade,與基線更新速度成反比,基線更新速度還與代碼結(jié)構(gòu)相關(guān),可通過函數(shù)GetCurQueueBaseLine來觀察---
?TKY_BaseInitStructure.baseRefreshSampleNum = 250;
?TKY_BaseInitStructure.baseUpRefreshDouble = 0;
?TKY_BaseInitStructure.baseDownRefreshSlow = 1000;
?TKY_BaseInitStructure.tkyBufP = tkyBuf;
?TKY_BaseInit(TKY_BaseInitStructure);
?//--------對觸摸通道7進行初始化,并列為檢測隊列中第1位----------
?GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_Floating);
?TKY_ChannelInitStructure.queueNum = 0;
?TKY_ChannelInitStructure.channelNum = 7;
?TKY_ChannelInitStructure.threshold = 200;
?TKY_ChannelInitStructure.threshold2 = 150;
?TKY_ChannelInitStructure.chargeTime = 0x0B;
?TKY_ChannelInitStructure.baseLine = TKY_GetCurChannelMean(TKY_ChannelInitStructure.channelNum, TKY_ChannelInitStructure.chargeTime, 10000);
?TKY_CHInit(TKY_ChannelInitStructure);
?//--------對觸摸通道10進行初始化,并列為檢測隊列中第2位----------
?GPIOA_ModeCfg(GPIO_Pin_6, GPIO_ModeIN_Floating);
?TKY_ChannelInitStructure.queueNum = 1;
?TKY_ChannelInitStructure.channelNum = 10;
?TKY_ChannelInitStructure.threshold = 200;
?TKY_ChannelInitStructure.threshold2 = 150;
?TKY_ChannelInitStructure.chargeTime = 0x0A;
?TKY_ChannelInitStructure.baseLine = TKY_GetCurChannelMean(TKY_ChannelInitStructure.channelNum, TKY_ChannelInitStructure.chargeTime, 10000);
?TKY_CHInit(TKY_ChannelInitStructure);
提供的Touch LIB是完整的工程,可以直接燒進去跑一下,不過默認(rèn)用的2個通道是PA2 和PA6,如果用其他通道,參考上圖加就行或者參考
這個PDF的說明添加通道即可。
你的問題不是特別清楚,可以先用默認(rèn)參數(shù),測一下通道不按的時候的采樣值和按下時測試的通道采樣值。先排除硬件問題
用這個函數(shù)可以獲取通道的測量值,打印看下,可以貼出來
感謝您的技術(shù)支持以及回復(fù),我現(xiàn)在按照例程跑一個按鍵是可以的,每次按鍵按下與不按下時測量值差100以上,見圖1。但是使用FILTER_MODE_2跑5個按鍵用同樣的配置,基線差距好大見圖2。
圖1? ?
??
? ?圖2
請問調(diào)試的時候要5個 按鍵一起調(diào)嗎?
TKY_BaseInitStructure.baseRefreshOnPress?=?0; ?TKY_BaseInitStructure.baseRefreshSampleNum?=?250; ?TKY_BaseInitStructure.baseUpRefreshDouble?=?0; ?TKY_BaseInitStructure.baseDownRefreshSlow?=?1000; ?TKY_ChannelInitStructure.threshold?=?200; ?TKY_ChannelInitStructure.threshold2?=?150; ?TKY_ChannelInitStructure.chargeTime?=?0x0B;
以上這些參數(shù)的配置要獲取通道的測量值達到什么效果才算好哪?調(diào)試時,以上參數(shù)配置的優(yōu)先級是怎樣哪?比如我是先調(diào)試配置threshold的值還是先調(diào)試配置threshold2的值?
我今天調(diào)試的時候,發(fā)現(xiàn)一個問題,請各位大神解答一下。
以下是我調(diào)試的代碼:
/*?配置TouchKey功能檢測?*/? TKY_BaseInitStructure.filterMode?=?FILTER_MODE_2; TKY_BaseInitStructure.filterGrade?=?4; TKY_BaseInitStructure.maxQueueNum?=?MAX_QUEUE_NUM; TKY_BaseInitStructure.baseRefreshOnPress?=?0; //---基線更新速度,baseRefreshSampleNum和filterGrade,與基線更新速度成反比,基線更新速度還與代碼結(jié)構(gòu)相關(guān),可通過函數(shù)GetCurQueueBaseLine來觀察--- TKY_BaseInitStructure.baseRefreshSampleNum?=?250; TKY_BaseInitStructure.baseUpRefreshDouble?=?0; TKY_BaseInitStructure.baseDownRefreshSlow?=?1000; TKY_BaseInitStructure.tkyBufP?=?tkyBuf; TKY_BaseInit(TKY_BaseInitStructure); ???? ???? //--------對觸摸通道7進行初始化,并列為檢測隊列中第1位---------- GPIOA_ModeCfg(GPIO_Pin_3,?GPIO_ModeIN_Floating);? TKY_ChannelInitStructure.queueNum?=?0; TKY_ChannelInitStructure.channelNum?=?6; TKY_ChannelInitStructure.threshold?=?200; TKY_ChannelInitStructure.threshold2?=?200; TKY_ChannelInitStructure.chargeTime?=?0x0B;//0x25;//0x0B; TKY_ChannelInitStructure.baseLine?=?TKY_GetCurChannelMean(TKY_ChannelInitStructure.channelNum,?TKY_ChannelInitStructure.chargeTime,?10000); current_base_line[0]???=??TKY_ChannelInitStructure.baseLine;//獲取當(dāng)前基線值 TKY_CHInit(TKY_ChannelInitStructure); // current_base_line[0]???=??TKY_GetCurQueueBaseLine(0); //--------對觸摸通道8進行初始化,并列為檢測隊列中第2位---------- GPIOA_ModeCfg(GPIO_Pin_1,?GPIO_ModeIN_Floating); TKY_ChannelInitStructure.queueNum?=?1; TKY_ChannelInitStructure.channelNum?=?8; TKY_ChannelInitStructure.threshold?=?200;//20;//15;?// TKY_ChannelInitStructure.threshold2?=?200;//17;//10;?// TKY_ChannelInitStructure.chargeTime?=?0x0B;//0x30;//0x25; TKY_ChannelInitStructure.baseLine?=?TKY_GetCurChannelMean(TKY_ChannelInitStructure.channelNum,?TKY_ChannelInitStructure.chargeTime,?10000);//0x943;// current_base_line[1]???=??TKY_ChannelInitStructure.baseLine;//獲取當(dāng)前基線值 TKY_CHInit(TKY_ChannelInitStructure); // ???current_base_line[1]???=??TKY_GetCurQueueBaseLine(1); //--------對觸摸通道9進行初始化,并列為檢測隊列中第3位---------- GPIOA_ModeCfg(GPIO_Pin_0,?GPIO_ModeIN_Floating);? TKY_ChannelInitStructure.queueNum?=?2; TKY_ChannelInitStructure.channelNum?=?9; TKY_ChannelInitStructure.threshold?=?200;//20;//15;?//???主要是更改這個值來進行相應(yīng)的觸摸體驗。 TKY_ChannelInitStructure.threshold2?=?200;//17;//10;?// TKY_ChannelInitStructure.chargeTime?=?0x0B;//0x30;//0x25; TKY_ChannelInitStructure.baseLine?=?TKY_GetCurChannelMean(TKY_ChannelInitStructure.channelNum,?TKY_ChannelInitStructure.chargeTime,?10000);//0x949;// current_base_line[2]???=??TKY_ChannelInitStructure.baseLine;//獲取當(dāng)前基線值 TKY_CHInit(TKY_ChannelInitStructure); //current_base_line[2]???=??TKY_GetCurQueueBaseLine(2); //--------對觸摸通道10進行初始化,并列為檢測隊列中第4位---------- GPIOA_ModeCfg(GPIO_Pin_6,?GPIO_ModeIN_Floating);? TKY_ChannelInitStructure.queueNum?=?3; TKY_ChannelInitStructure.channelNum?=?10; TKY_ChannelInitStructure.threshold?=?200;//12;?//200?10?12 TKY_ChannelInitStructure.threshold2?=?200;//10;//3;?//150 TKY_ChannelInitStructure.chargeTime?=?0x0B;//0x30;//0x25; TKY_ChannelInitStructure.baseLine?=?TKY_GetCurChannelMean(TKY_ChannelInitStructure.channelNum,?TKY_ChannelInitStructure.chargeTime,?10000);//0x92C;// current_base_line[3]???=??TKY_ChannelInitStructure.baseLine;//獲取當(dāng)前基線值 TKY_CHInit(TKY_ChannelInitStructure); //current_base_line[3]???=??TKY_GetCurQueueBaseLine(3); //--------對觸摸通道11進行初始化,并列為檢測隊列中第5位---------- GPIOA_ModeCfg(GPIO_Pin_7,?GPIO_ModeIN_Floating);? TKY_ChannelInitStructure.queueNum?=?4; TKY_ChannelInitStructure.channelNum?=?11; TKY_ChannelInitStructure.threshold?=?200;//25;? TKY_ChannelInitStructure.threshold2?=?200;//10;//5;?//150 TKY_ChannelInitStructure.chargeTime?=?0x0B;//0x30;//0x25; TKY_ChannelInitStructure.baseLine?=?TKY_GetCurChannelMean(TKY_ChannelInitStructure.channelNum,?TKY_ChannelInitStructure.chargeTime,?10000);//0x8E6;// current_base_line[4]???=??TKY_ChannelInitStructure.baseLine;//獲取當(dāng)前基線值 TKY_CHInit(TKY_ChannelInitStructure); //current_base_line[4]???=??TKY_GetCurQueueBaseLine(4); ???????/*打印配置時的基線值*/ PRINT("current?base?line1?=?%04d\r\n",current_base_line[0]); PRINT("current?base?line2?=?%04d\r\n",current_base_line[1]); PRINT("current?base?line3?=?%04d\r\n",current_base_line[2]); PRINT("current?base?line4?=?%04d\r\n",current_base_line[3]); PRINT("current?base?line5?=?%04d\r\n",current_base_line[4]); mDelaymS(300);//延時300Ms PRINT("delay?300ms?\r\n"); ?/*重新獲取基線值*/ for(int?i=0;i<5;i++) { current_base_line[i]???=??TKY_GetCurQueueBaseLine(i); mDelaymS(5); } PRINT("current?base?line1?=?%04d\r\n",current_base_line[0]); PRINT("current?base?line2?=?%04d\r\n",current_base_line[1]); PRINT("current?base?line3?=?%04d\r\n",current_base_line[2]); PRINT("current?base?line4?=?%04d\r\n",current_base_line[3]); PRINT("current?base?line5?=?%04d\r\n",current_base_line[4]);
結(jié)果如下:
請問是哪里的問題,導(dǎo)致基線值在這么短的時間內(nèi)發(fā)生這么大的變化?
基線值建議調(diào)到3000左右,理論上這個值是測試的ADC的,應(yīng)該不會大于4095才對。
如果怎么都調(diào)不小,就是硬件寄生電容太大導(dǎo)致的(這個就跟畫法和PCB走線有關(guān)系)