找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3598|回复: 3
打印 上一主题 下一主题
收起左侧

FDC2214/STM32F103设计源码+电路图pcb封装库

[复制链接]
跳转到指定楼层
楼主
FDC2214原理图手册源码封装库等相关资料下载
1. Schematic design
2. Firmware



单片机源程序如下:
  1. /*******************************************************************************
  2.   * @file    Project/fdc2214.c
  3.   * @author  T.D.NGUYEN
  4.   * @version V1.1.0
  5.   * @date    05/24/2018
  6.   * @brief   STM32F1-FDC2214 using I2C1-CAN to PC.
  7.   ******************************************************************************
  8.   *(C) COPYRIGHT 2018 @DV1985a
  9.   */

  10. /* Includes ------------------------------------------------------------------*/
  11. #include "stm32f10x.h"
  12. #include "stm32f10x_conf.h"
  13. #include "platform_config.h"
  14. #include "fdc2214.h"
  15. #include <stdio.h>
  16. #include "stdlib.h"
  17. #include "string.h"   
  18. #include <stdbool.h>
  19. #include "led.h"
  20. #include "i2c.h"
  21. #include "stm32f10x_exti.c" // External interrupt

  22. //*****************************************************************************
  23. //*****************************************************************************
  24. // #defines
  25. //*****************************************************************************
  26. #define PROX_INTEGRAL_THRESHOLD         200
  27. #define PROX_INTEGRAL_HYS                        1.2
  28. #define B1_INTEGRAL_THRESHOLD            90000
  29. #define B2_INTEGRAL_THRESHOLD                90000
  30. #define B1_INTEGRAL_CAP                            300000
  31. #define B2_INTEGRAL_CAP                                300000
  32. #define PROX_DERIVATIVE_THRESHOLD        0
  33. #define B1_DERIVATIVE_THRESHOLD                3000
  34. #define B2_DERIVATIVE_THRESHOLD                 3000
  35. #define LEAKAGE_FACTOR_PROX                0.99
  36. #define LEAKAGE_FACTOR_BUTTON         0.9

  37. #define DELAY_1_MS        8000                        //delay for 1ms based on 8Mhz clock
  38. #define DELAY_1_SEC        8000000                        //delay for 1sec based on 8Mhz clock

  39. /********PROXIMITY PROCESSING VARIABLES************/
  40. uint32_t proxMeasSample = 0;
  41. uint32_t movingAvgProx = 0;
  42. uint32_t prevMovingAvgProx = 0;
  43. int32_t derivativeProx = 0;
  44. int32_t integralProx = 0;
  45. int32_t prevIntegralProx = 0;

  46. uint16_t integralProxHys = 0;

  47. /*********BUTTON1 PROCESSING VARIABLES***************/
  48. uint32_t b1MeasSample = 0;
  49. uint32_t movingAvgB1 = 0;
  50. uint32_t prevMovingAvgB1 = 0;
  51. int32_t derivativeB1 = 0;
  52. int32_t integralB1 = 0;
  53. int32_t prevIntegralB1 = 0;

  54. /*********BUTTON2 PROCESSING VARIABLES***************/
  55. uint32_t b2MeasSample = 0;
  56. uint32_t movingAvgB2 = 0;
  57. uint32_t prevMovingAvgB2 = 0;
  58. int32_t derivativeB2 = 0;
  59. int32_t integralB2 = 0;
  60. int32_t prevIntegralB2 = 0;

  61. /*******OTHER VARIABLES********/
  62. bool flagINTB = false;
  63. bool initCal = true;
  64. bool proxOn = false;

  65. /*****FUNCTION DECLARATIONS*****/
  66. void initMovingAvgVars(void);

  67. //*****************************************************************************
  68. // Interrupt Service Routines
  69. //*****************************************************************************
  70. void EXTI1_IRQHandler(void)
  71. {
  72.     //FDC2214 Data Ready bit INTB pin
  73.     flagINTB = true;
  74.     EXTI_ClearITPendingBit(EXTI_Line0);
  75.     NVIC_ClearPendingIRQ(EXTI0_IRQn);
  76. }

  77. /**
  78. * @brief  Main program.
  79. * @param  None
  80. * @retval None
  81. */

  82. int main(void)
  83. {

  84.     SystemInit();
  85.     CLOCK_Configuration();
  86.     RCC_Configuration();
  87.     NVIC_Configuration();
  88.     GPIO_Configuration();
  89.     USART_Configuration();
  90.     TIM_Configuration();
  91.     I2C_Configuration();  //Init I2C1
  92.     CAN_Configuration();
  93.     __enable_interrupt();
  94.    
  95. //   configureDebugLEDs();
  96. //    setAllDebugLEDs();
  97. //    GPIO_SetBits(GPIOA, GREEN_LED);
  98. //    delay(10);
  99. //    GPIO_SetBits(GPIO_LED, GPIO_Pin_7);
  100. //    delay(1000);
  101.     GPIO_SetBits(GPIO_LED, GPIO_Pin_7);
  102.     GPIO_SetBits(GPIO_LED, GPIO_Pin_6);
  103.     GPIO_ResetBits(GPIO_LED, GPIO_Pin_5);
  104.     GPIO_ResetBits(GPIO_LED, GPIO_Pin_4);
  105.         delay(1000);  
  106.    
  107. //Delays to get user hand out of proximity of sensor (if pressed reset SW)
  108. //    delay(1000);
  109. //    delay(1000);

  110.     FDC2214_init(); //Initialize and configure FDC2214
  111.     FDC2214_enableINTB();

  112.     //Initialize and stabilize moving average variables
  113.     initMovingAvgVars();
  114.     clearAllDebugLEDs();

  115.    
  116. while(1)
  117.     {

  118.         //Collect FDC measurements
  119.         if(flagINTB)
  120.         {
  121.             proxMeasSample = FDC2214_readMeasProxSensor();
  122.             b1MeasSample = FDC2214_readMeasButton1();
  123.             b2MeasSample = FDC2214_readMeasButton2();
  124.             flagINTB = false;      

  125.             //Process Data using Derivative/Integration Algorithm
  126.             //Moving Average using IIR filter of 8 samples
  127.             prevMovingAvgProx = movingAvgProx;
  128.             prevMovingAvgB1 = movingAvgB1;
  129.             prevMovingAvgB2 = movingAvgB2;
  130.                         movingAvgProx = ((movingAvgProx << 2) - movingAvgProx + proxMeasSample) >> 2;
  131.                         movingAvgB1 = ((movingAvgB1 << 2) - movingAvgB1 + b1MeasSample) >> 2;
  132.                         movingAvgB2 = ((movingAvgB2 << 2) - movingAvgB2 + b2MeasSample) >> 2;

  133.                         derivativeProx = movingAvgProx - prevMovingAvgProx;
  134.                         derivativeB1 = movingAvgB1 - prevMovingAvgB1;
  135.                         derivativeB2 = movingAvgB2 - prevMovingAvgB2;

  136.                         /******************************************/
  137.                         /**************CH0 = Proximity ************/
  138.                         /******************************************/
  139.                         if((abs(derivativeProx) > PROX_DERIVATIVE_THRESHOLD))
  140.                         {
  141.                                 integralProx = prevIntegralProx + derivativeProx;
  142.                         }
  143.                         else
  144.                         {
  145.                                 integralProx = prevIntegralProx;
  146.                         }

  147.                         if(proxOn)
  148.                                 integralProxHys = PROX_INTEGRAL_THRESHOLD / PROX_INTEGRAL_HYS;
  149.                         else
  150.                                 integralProxHys = PROX_INTEGRAL_THRESHOLD * PROX_INTEGRAL_HYS;


  151.                         if(integralProxHys <= -(integralProx))
  152.                         {
  153.                                 //Object detected for Proximity Sensor
  154.                                 prevIntegralProx = integralProx;
  155.                                 setProxLED();
  156.                                 proxOn = true;
  157.                         }
  158.                         else
  159.                         {
  160.                                 //Object not detected
  161.                                 prevIntegralProx = integralProx * LEAKAGE_FACTOR_PROX;
  162.                                 clearProxLED();
  163.                                 proxOn = false;
  164.                         }

  165.                         /******************************************/
  166.                         /*****CH1 = Cap touch Button1******/
  167.                         /******************************************/
  168.                         if(abs(derivativeB1) > B1_DERIVATIVE_THRESHOLD)
  169.                         {
  170.                                 integralB1 = prevIntegralB1 + derivativeB1;
  171.                                 // Set integral cap for B1
  172.                                 if (-integralB1 > B1_INTEGRAL_CAP)                //Cap integral for more responsiveness
  173.                                 {
  174.                                         integralB1 = -(B1_INTEGRAL_CAP);
  175.                                 }
  176.                         }
  177.                         else
  178.                         {
  179.                                 integralB1 = prevIntegralB1;
  180.                                 // Set integral cap for B2
  181.                                 if (-integralB1 > B1_INTEGRAL_CAP)                //Cap integral for more responsiveness
  182.                                 {
  183.                                         integralB1 = -(B1_INTEGRAL_CAP);
  184.                                 }
  185.                         }

  186.                         if(B1_INTEGRAL_THRESHOLD <= -(integralB1))
  187.                         {
  188.                                 //Object detected
  189.                                 prevIntegralB1 = integralB1;
  190.                                 setButton1LED();
  191.                         }
  192.                         else
  193.                         {
  194.                                 //Object not detected
  195.                                 prevIntegralB1 = integralB1 * LEAKAGE_FACTOR_BUTTON;
  196.                                 clearButton1LED();
  197.                         }

  198.                         /******************************************/
  199.                         /*****CH2 = Cap touch Button2******/
  200.                         /******************************************/
  201.                         if(abs(derivativeB2) > B2_DERIVATIVE_THRESHOLD)
  202.                         {
  203.                                 integralB2 = prevIntegralB2 + derivativeB2;
  204.                                 // Set integral cap for B2
  205.                                 if (-integralB2 > B2_INTEGRAL_CAP)                //Cap integral for more responsiveness
  206.                                 {
  207.                                         integralB2 = -(B2_INTEGRAL_CAP);
  208.                                 }
  209.                         }
  210.                         else
  211.                         {
  212.                                 integralB2 = prevIntegralB2;
  213.                                 // Set integral cap for B2
  214.                                 if (-integralB2 > B2_INTEGRAL_CAP)                //Cap integral for more responsiveness
  215.                                 {
  216.                                         integralB2 = -(B2_INTEGRAL_CAP);
  217.                                 }
  218.                         }

  219.                         if(B2_INTEGRAL_THRESHOLD <= -(integralB2))
  220.                         {
  221.                                 //Object detected
  222.                                 prevIntegralB2 = integralB2;
  223.                                 setButton2LED();
  224.                         }
  225.                         else
  226.                         {
  227.                                 //Object not detected
  228.                                 prevIntegralB2 = integralB2 * LEAKAGE_FACTOR_BUTTON;
  229.                                 clearButton2LED();
  230.                         }

  231. //                        debugUART_4(movingAvgProx, proxMeasSample, derivativeProx, integralProx);                //UART to debug for variables

  232.             //Clear DRDY bit by reading STATUS REGISTER
  233.                         FDC2214_clearDRDY();
  234.         }
  235.     }
  236. }


  237. //*****************************************************************************
  238. ……………………

  239. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
STM32-FDC_FINAL.rar (72.53 KB, 下载次数: 55)
STM32F1-FDC2214 - manual.7z (1.34 MB, 下载次数: 72)




分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶1 踩
回复

使用道具 举报

沙发
ID:195464 发表于 2019-7-29 10:56 | 只看该作者
多谢楼主分享,研究一下
回复

使用道具 举报

板凳
ID:746619 发表于 2020-5-8 09:48 | 只看该作者
请问没有完整的PCB图吗
回复

使用道具 举报

地板
ID:748161 发表于 2020-5-10 10:14 | 只看该作者
多谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表