第一次调CH579里面的Touch-Key,用的TKY_CH579库,有没有哪位大神用过,教教我调试的时候从哪一步开始调起?为啥我算的充电时间(0x25),跟平稳时达到3000的充电时间(0x60)差这么多啊?
大家使用这个TKY_CH579时,初始化都是怎么处理的?没有出现过上电基线值下降浮动导致触发按键任务的情况吗?急问!!!
有沁恒技术人员给点技术支持吗???
/* 配置TouchKey功能检测 */
TKY_BaseInitStructure.filterMode = FILTER_MODE_2;
TKY_BaseInitStructure.filterGrade = 4;
TKY_BaseInitStructure.maxQueueNum = MAX_QUEUE_NUM;
TKY_BaseInitStructure.baseRefreshOnPress = 0;
//---基线更新速度,baseRefreshSampleNum和filterGrade,与基线更新速度成反比,基线更新速度还与代码结构相关,可通过函数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是完整的工程,可以直接烧进去跑一下,不过默认用的2个通道是PA2 和PA6,如果用其他通道,参考上图加就行或者参考
这个PDF的说明添加通道即可。
你的问题不是特别清楚,可以先用默认参数,测一下通道不按的时候的采样值和按下时测试的通道采样值。先排除硬件问题
用这个函数可以获取通道的测量值,打印看下,可以贴出来
感谢您的技术支持以及回复,我现在按照例程跑一个按键是可以的,每次按键按下与不按下时测量值差100以上,见图1。但是使用FILTER_MODE_2跑5个按键用同样的配置,基线差距好大见图2。
图1
图2
请问调试的时候要5个 按键一起调吗?
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;
以上这些参数的配置要获取通道的测量值达到什么效果才算好哪?调试时,以上参数配置的优先级是怎样哪?比如我是先调试配置threshold的值还是先调试配置threshold2的值?
我今天调试的时候,发现一个问题,请各位大神解答一下。
以下是我调试的代码:
/* 配置TouchKey功能检测 */ TKY_BaseInitStructure.filterMode = FILTER_MODE_2; TKY_BaseInitStructure.filterGrade = 4; TKY_BaseInitStructure.maxQueueNum = MAX_QUEUE_NUM; TKY_BaseInitStructure.baseRefreshOnPress = 0; //---基线更新速度,baseRefreshSampleNum和filterGrade,与基线更新速度成反比,基线更新速度还与代码结构相关,可通过函数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;//获取当前基线值 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;//获取当前基线值 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; // 主要是更改这个值来进行相应的触摸体验。 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;//获取当前基线值 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;//获取当前基线值 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;//获取当前基线值 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]);
结果如下:
请问是哪里的问题,导致基线值在这么短的时间内发生这么大的变化?
基线值建议调到3000左右,理论上这个值是测试的ADC的,应该不会大于4095才对。
如果怎么都调不小,就是硬件寄生电容太大导致的(这个就跟画法和PCB走线有关系)