基于FDC2214的手势识别

基于FDC2214的手势识别

1、本次题目来源于2018年全国电子设计大赛D题,要求实现对石头、剪刀、布以及数字12345的识别;同时在上述基础上实现对手势的学习。

2、硬件实现:

硬件主要采用STM32F103以及TI公司的FDC2214芯片,同时FDC2214芯片按照官方文档进行接线,其接线原理图如下:

其中CLKIN引脚为接地引脚;ADDR引脚需要外接上拉电阻;SD引脚需要外接下拉电阻;右侧为芯片外接测量数据输入端口。

同时SCL、SDA、VDD以及GND进行了接线处理,其具体接线如下:

 

实现对接线的VDD和GND之间的处理,实现和STM32f103之间的连接,实现对FDC2214芯片的供电和接地处理以及I2C通信的接口。

另外,对数据输入端子进行数据读入,加入LC稳定滤波,其接线原理如下:

 

3、软件实现,不多说,先贴上FDC2214配置代码:

#include "fdc2214.h"

#include "delay.h"

#include "led.h"

void FDC_IIC_Delay(void)

{

       delay_us(2);

}

 

void FDC_GPIO_Init(void)

{

      

}

 

void FDC_IIC_Init(void)

{                                      

  GPIO_InitTypeDef  GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);       

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;           

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;             

GPIO_Init(GPIOC, &GPIO_InitStructure);                               

      

  GPIO_SetBits(GPIOC,GPIO_Pin_4|GPIO_Pin_5);                         

}

 

void FDC_IIC_Start(void)

{

       FDC_SDA_OUT();  

       FDC_IIC_SDA=1;            

       FDC_IIC_SCL=1;

       FDC_IIC_Delay();

      FDC_IIC_SDA=0;

       FDC_IIC_Delay();

       FDC_IIC_SCL=0;

}       

void FDC_IIC_Stop(void)

{

       FDC_SDA_OUT();

       FDC_IIC_SCL=0;

       FDC_IIC_SDA=0;

      FDC_IIC_Delay();

       FDC_IIC_SCL=1;

       FDC_IIC_SDA=1;

       FDC_IIC_Delay();                                                  

}

u8 FDC_IIC_Wait_Ack(void)

{

       u8 ucErrTime=0;

       FDC_SDA_IN();     

       FDC_IIC_SDA=1;FDC_IIC_Delay();   

       FDC_IIC_SCL=1;FDC_IIC_Delay();

       while(FDC_READ_SDA)

       {

              ucErrTime++;

              if(ucErrTime>250)

              {

                     FDC_IIC_Stop();

                     return 1;

              }

       }

       FDC_IIC_SCL=0;  

       return 0; 

}

void FDC_IIC_Ack(void)

{

       FDC_IIC_SCL=0;

       FDC_SDA_OUT();

       FDC_IIC_SDA=0;

       FDC_IIC_Delay();

       FDC_IIC_SCL=1;

       FDC_IIC_Delay();

       FDC_IIC_SCL=0;

}

          

void FDC_IIC_NAck(void)

{

       FDC_IIC_SCL=0;

       FDC_SDA_OUT();

       FDC_IIC_SDA=1;

       FDC_IIC_Delay();

       FDC_IIC_SCL=1;

       FDC_IIC_Delay();

       FDC_IIC_SCL=0;

}                                                                 

               

void FDC_IIC_Send_Byte(u8 txd)

{                       

  u8 t;  

       FDC_SDA_OUT();     

    FDC_IIC_SCL=0;

    for(t=0;t<8;t++)

    {             

        FDC_IIC_SDA=(txd&0x80)>>7;

        txd<<=1;        

                  FDC_IIC_SCL=1;

                  FDC_IIC_Delay();

                  FDC_IIC_SCL=0;   

                  FDC_IIC_Delay();

    }     

}         

u8 FDC_IIC_Read_Byte(unsigned char ack)

{

       unsigned char i,receive=0;

       FDC_SDA_IN();

    for(i=0;i<8;i++ )

       {

        FDC_IIC_SCL=0;

        FDC_IIC_Delay();

              FDC_IIC_SCL=1;

        receive<<=1;

        if(FDC_READ_SDA)receive++;  

              FDC_IIC_Delay();

    }                          

    if (!ack)

        FDC_IIC_NAck();//·¢ËÍnACK

    else

        FDC_IIC_Ack(); //·¢ËÍACK  

    return receive;

}

u8 Set_FDC2214(u8 reg,u8 MSB,u8 LSB)                         

{

    FDC_IIC_Start();

       FDC_IIC_Send_Byte((FDC2214_ADDR<<1)|0);

       if(FDC_IIC_Wait_Ack()) 

       {

              FDC_IIC_Stop();           

              return 1;        

       }

    FDC_IIC_Send_Byte(reg);

    FDC_IIC_Wait_Ack();           

       FDC_IIC_Send_Byte(MSB);

       if(FDC_IIC_Wait_Ack()) 

       {

              FDC_IIC_Stop();    

              return 1;        

       }            

       FDC_IIC_Send_Byte(LSB);

       if(FDC_IIC_Wait_Ack()) 

       {

              FDC_IIC_Stop();    

              return 1;        

       }     

    FDC_IIC_Stop();    

       return 0;

}

u16 FDC_Read(u8 reg)

{

       u16 res;

   FDC_IIC_Start();

       FDC_IIC_Send_Byte((FDC2214_ADDR<<1)|0);

       FDC_IIC_Wait_Ack();           

    FDC_IIC_Send_Byte(reg);     

    FDC_IIC_Wait_Ack();           

    FDC_IIC_Start();

       FDC_IIC_Send_Byte((FDC2214_ADDR<<1)|1);

    FDC_IIC_Wait_Ack();           

       res=FDC_IIC_Read_Byte(1)<<8;

        

       res|=FDC_IIC_Read_Byte(0);

    FDC_IIC_Stop();                  

       return res;            

}

 

 

u32 FCD2214_ReadCH(u8 index)

{

       u32 result;

       switch(index)

       {

              case 0:

                result = FDC_Read(DATA_CH0)&0x0FFF;

                result = (result<<16)|(FDC_Read(DATA_LSB_CH0));

                     break;

              case 1:

                     result = FDC_Read(DATA_CH1)&0x0FFF;

                result = (result<<16)|(FDC_Read(DATA_LSB_CH1));

                     break;

              case 2:

                     result = FDC_Read(DATA_CH2)&0x0FFF;

                result = (result<<16)|(FDC_Read(DATA_LSB_CH2));

                     break;

              case 3:

                     result = FDC_Read(DATA_CH3)&0x0FFF;

                result = (result<<16)|(FDC_Read(DATA_LSB_CH3));

                     break;

              default:break;

       }

       result =result&0x0FFFFFFF;

       return result;

}

 

u8 FDC2214_Init(void)

{

       u16 res;

       FDC_GPIO_Init();

      

      

       FDC_IIC_Init();

      

       res=FDC_Read(MANUFACTURER_ID);

       if(res==0x5449)

       {

              Set_FDC2214(RCOUNT_CH0,0x34,0xFB);                  Set_FDC2214(RCOUNT_CH1,0x34,0xFB);

              Set_FDC2214(RCOUNT_CH2,0x34,0xFB);

              Set_FDC2214(RCOUNT_CH3,0x34,0xFB);

             

Set_FDC2214(SETTLECOUNT_CH0,0x00,0x1B);                               Set_FDC2214(SETTLECOUNT_CH1,0x00,0x1B);

              Set_FDC2214(SETTLECOUNT_CH2,0x00,0x1B);

              Set_FDC2214(SETTLECOUNT_CH3,0x00,0x1B);

             

       Set_FDC2214(CLOCK_DIVIDERS_C_CH0,0x10,0x01);        Set_FDC2214(CLOCK_DIVIDERS_C_CH1,0x10,0x01);        Set_FDC2214(CLOCK_DIVIDERS_C_CH2,0x10,0x01);        Set_FDC2214(CLOCK_DIVIDERS_C_CH3,0x10,0x01);

Set_FDC2214(DRIVE_CURRENT_CH0,0x78,0x00);                            Set_FDC2214(DRIVE_CURRENT_CH1,0x78,0x00);

       Set_FDC2214(DRIVE_CURRENT_CH2,0x78,0x00);

       Set_FDC2214(DRIVE_CURRENT_CH3,0x78,0x00);

       Set_FDC2214(ERROR_CONFIG,0x00,0x00);

       Set_FDC2214(MUX_CONFIG,0xC2,0x0D);

       Set_FDC2214(CONFIG,0x14,0x01);

       }

       else return 1;

      

       return 0;

}

 

float Cap_Calculate(u8 index)

{

       u32 Data_FDC;

       Data_FDC = FCD2214_ReadCH(index);

       return (Data_FDC);

}

 

       上述为本次设计中较为核心的FDC2214传感器芯片用到的配置代码,其中包括对I2C通信的代码引脚配置、时序配置、数据读入读出、读取FDC2214对应通道数值的程序编写。

4、其中,自学习功能,本人使用每三次采集数据均值周边的正负20作为数据参考基准,,实现对手势的学习,增强自学习性的可以自己编写相关算法程序。

if(page_fl==22&&posi==6)

{

if( (data>n1_data[0]-20)&&(data<n1_data[0]+20) )

{

POINT_COLOR=BLACK;

LCD_ShowNum(190,400,1,1,24);

}

 

if( (data>n2_data[0]-20)&&(data<n2_data[0]+20) )

{

POINT_COLOR=BLACK;

LCD_ShowNum(190,400,2,1,24);

}

 

if( (data>n3_data[0]-20)&&(data<n3_data[0]+20) )

{

POINT_COLOR=BLACK;

LCD_ShowNum(190,400,3,1,24);

}

 

if( (data>n4_data[0]-20)&&(data<n4_data[0]+20) )

{

POINT_COLOR=BLACK;

LCD_ShowNum(190,400,4,1,24);

}

 

if( (data>n5_data[0]-20)&&(data<n5_data[0]+20) )

{

POINT_COLOR=BLACK;

LCD_ShowNum(190,400,5,1,24);

}

}

5、综上,为本次D题,此外还做了2018年E题方案和程序,有兴趣后续可了解学习,诸多不足,诸位见谅

 

 

 

 

 

 

 

 

 

 

­

 

posted @ 2018-07-25 10:56  zhuhongzhous  阅读(11954)  评论(1编辑  收藏  举报