找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 5632|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

TSC觸摸感應(yīng)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主

七步走,
第一步:給CS放電,S3開(kāi),
第二步:所有開(kāi)關(guān)關(guān)閉,
第三步:S2開(kāi)啟,給CX充電。
第四步:所有開(kāi)關(guān)關(guān)閉
第五步:開(kāi)啟S1給CS充電
第六步:所有開(kāi)關(guān)關(guān)閉
第七步:S1和S3開(kāi)啟,給CX和CS放電
重復(fù)上面的7個(gè)步驟,直到CS電壓到高電平(有觸摸時(shí)重復(fù)次數(shù)將減少)


在第六步后采集到I/0端口電平是否超過(guò)閥值。


void Configure_TSC(void)
{
          RCC->AHBENR |= RCC_AHBENR_TSEN;       
          TSC->CR = TSC_CR_PGPSC_2 | TSC_CR_PGPSC_0                 // fPGCLK = fHCLK/32
| TSC_CR_CTPH_0 | TSC_CR_CTPL_0                    // pulse high = 2xtPGCLK,Master
| TSC_CR_MCV_2 | TSC_CR_MCV_1                    // Max count value = 16383 pulses
| TSC_CR_TSCE;                                                    // Enable TSC
          TSC->IOHCR &= (uint32_t)(~(TSC_IOHCR_G2_IO4 | TSC_IOHCR_G2_IO3)); // 默認(rèn)使能,去除不要的端口
          TSC->IER = TSC_IER_EOAIE;                                                 // 轉(zhuǎn)換系列結(jié)束中斷
          TSC->IOSCR = TSC_IOSCR_G2_IO4;                                         // 采樣端口電容接在 G2IO4上
          TSC->IOCCR = TSC_IOCCR_G2_IO3;                                         // 觸摸按鍵設(shè)在G2IO3上
          TSC->IOGCSR |= TSC_IOGCSR_G2E;                                         // 使能組2
  
          NVIC_SetPriority(TSC_IRQn, 0);
          NVIC_EnableIRQ(TSC_IRQn);
}
void TSC_IRQHandler(void)
{
if((TSC->ISR & TSC_ISR_EOAF) == TSC_ISR_EOAF)                //系列結(jié)束否
{
TSC->ICR = TSC_ICR_EOAIC;                         /* Clear flag */
AcquisitionValue = TSC->IOGXCR[1];                 /* Get G2 counter value */
}
}
void Process(void)
{
static uint32  NumberOfCalibration=0;
uchar RefIndex=0;
static uchar RefIndexStatic=0;
static uint32  ReferenceTab[REFERENCE_TAB_SIZE];
if(AcquisitionValue)                 //有數(shù)據(jù)到來(lái)
{
if(CalibrationDone)         //是否矯正完成
{
if((AcquisitionValue + THRESHOLD) < Reference) /* Touch detected */
{
Activities = 1;
}
else if(AcquisitionValue > (Reference + THRESHOLD))
{
Activities = 1;
CalibrationDone = 0;                         /* restart calibration */
Reference = 0;                                 /* Reset reference */
}
else /* no touch detected */
{
if(ReferenceAdaptation)
{
ReferenceAdaptation=0;
RefIndexStatic%=REFERENCE_TAB_SIZE;
ReferenceTab[RefIndexStatic++] = AcquisitionValue;
for(RefIndex=0;RefIndex<REFERENCE_TAB_SIZE;RefIndex++)
{
Reference += ReferenceTab[RefIndex];
}
Reference /= (REFERENCE_TAB_SIZE + 1);
}
}
}
else /* Calibration */
{
if(NumberOfCalibration < NUMBER_OF_CALIBRATION)
{
Reference += AcquisitionValue;
NumberOfCalibration++;
}
else if(NumberOfCalibration == NUMBER_OF_CALIBRATION)
{
Reference += AcquisitionValue;
Reference /= (NUMBER_OF_CALIBRATION + 1); /* Compute reference */
NumberOfCalibration = 0; /* Reset number of calibration for nex time */
CalibrationDone = 1;                 /* Calibration Completed */
for(RefIndex=0;RefIndex<REFERENCE_TAB_SIZE;RefIndex++)
{
ReferenceTab[RefIndex] = Reference;
}
}
}
AcquisitionValue = 0;         //復(fù)位count值
TSC->CR |= (1<<1) ;                // 開(kāi)始新的系列
}
}

void main()
{
Configure_TSC();
TSC->CR |= (1<<1);                                         // 開(kāi)始轉(zhuǎn)換
while(1)
{
Process();
}
}


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:248882 發(fā)表于 2018-7-10 19:02 | 只看該作者
研究很長(zhǎng)時(shí)間TSC ,不成功,能分享一下TSC工程供我學(xué)習(xí)嗎? 謝謝! feiyun_zhu@163.com
回復(fù)

使用道具 舉報(bào)

板凳
ID:158903 發(fā)表于 2018-7-11 23:41 | 只看該作者
TSC觸摸感應(yīng) 馬克
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表