久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2817|回復: 0
打印 上一主題 下一主題
收起左側

我的第一次聲音定位之旅 廣義互相關算法 附MCU源程序

[復制鏈接]
跳轉到指定樓層
樓主
大二暑假的時候做了一次聲音定位項目,做成了一個聲音導向儀,在德州儀器的TI單片機上實現,運用了廣義互相關的算法,簡單地尋找了四個方向的角度,并用控制舵機來旋轉。

紀念一下。

制作出來的實物圖如下:


使用的M4核tm4c1294ncpdt芯片

單片機源程序如下:
  1. #include <stdbool.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include "inc/hw_memmap.h"
  6. #include "inc/hw_types.h"
  7. #include "inc/hw_gpio.h"
  8. #include "inc/tm4c1294ncpdt.h"
  9. #include "inc/hw_epi.h"
  10. //#include "inc/hw_ints.h"         //和"inc/tm4c1294ncpdt.h"里面的宏定義重復了
  11. #include "driverlib/epi.h"
  12. #include "driverlib/gpio.h"
  13. #include "driverlib/sysctl.h"
  14. #include "driverlib/rom.h"
  15. #include "driverlib/rom_map.h"
  16. #include "driverlib/pin_map.h"
  17. #include "driverlib/pwm.h"
  18. #include "driverlib/systick.h"
  19. #include "driverlib/interrupt.h"
  20. #include "driverlib/ssi.h"
  21. #include "driverlib/fpu.h"
  22. #include "driverlib/adc.h"
  23. #include "utils/uartstdio.h"
  24. #include "TFTinit/TFT_400x240_OTM4001A_16bit.h"
  25. //#include "TFTinit/picture.h"
  26. #include "TOUCHinit/TOUCH_TSC2046.h"
  27. #include "EPIinit/EPIinit.h"

  28. //Todo
  29. #include  "math.h"
  30. #include "driverlib/timer.h"
  31. #include "utils/uartstdio.h"

  32. //Todo
  33. /*項目分類*/
  34. typedef enum{
  35.         noun,//空
  36.         return_main,//返回
  37.         pj1,//顯示時鐘
  38.         pj2,//音樂播放器
  39.         pj3,//聲音定位
  40.         wrong,//錯誤選擇,
  41. } Project;

  42. /*自定義變量*/
  43. //Todo
  44. #define _NOP() _nop()
  45. #define SLAVE_ADDRESS_W 0x3A //寫ADXL345L時的從機地址
  46. #define SLAVE_ADDRESS_R 0x3B //讀ADXL345L時的從機地址

  47. double tem,tem_tmp;//溫度(*100)
  48. Project choose_pj = noun;

  49. volatile uint32_t show_flag=0;//是否顯示了時鐘
  50. volatile uint32_t start_flag=0;//是否進入主頁


  51. volatile uint32_t musicplay_once=0,musicplay_rotate=0;//單次演奏和循環演奏
  52. volatile uint32_t time = 0,time1=0,time2=0;;//時間
  53. volatile uint32_t mg[3]={0x00,0x00,0x00};
  54. volatile uint32_t touch_cnt=0;
  55. #define touch_cnt_max 5
  56. uint32_t page=1;
  57. uint32_t array_num;

  58. //*****************************************************************************
  59. //
  60. // System clock rate in Hz.
  61. //
  62. //*****************************************************************************
  63. uint32_t g_ui32SysClock;

  64. extern uint32_t GetData[21];

  65. uint32_t TouchXData[21];
  66. uint32_t TouchYData[21];

  67. //Todo
  68. /*舵機初始化*/
  69. void ServoInit()//對所有PWM generator進行初始化
  70. {
  71.             SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);//PWM0模塊使能

  72.             SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);//GPIOF模塊使能

  73.             GPIOPinConfigure(GPIO_PF1_M0PWM1);//設置引腳復用功能為PWM
  74. //            GPIOPinConfigure(GPIO_PK4_M0PWM6);
  75. //            GPIOPinConfigure(GPIO_PK5_M0PWM7);

  76.             GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);//配置相應引腳用于PWM功能
  77. //            GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_4);//外擴引腳
  78. //            GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_5);

  79.              PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN |PWM_GEN_MODE_NO_SYNC);//配置PWM發生器為減計數、立即更新方式
  80.              PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
  81. //             PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
  82. //             PWMGenConfigure(PWM0_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

  83.               PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 60000);//配置PWM工作頻率為120MHz/8/120000=125Hz
  84. //              PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 120000);
  85. //              PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, 50000);
  86. //              PWMGenPeriodSet(PWM0_BASE, PWM_GEN_3, 50000);
  87.               PWM0_CC_R = PWM_CC_USEPWM | PWM_CC_PWMDIV_8;

  88.             PWMOutputState( PWM0_BASE, PWM_OUT_1_BIT, true);
  89.             //PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_2_BIT | PWM_OUT_3_BIT, true);//使能PWM輸出信號
  90.             //PWMOutputState(PWM0_BASE, PWM_OUT_4_BIT | PWM_OUT_5_BIT | PWM_OUT_6_BIT, true);//使能PWM輸出信號

  91.             PWMGenEnable(PWM0_BASE, PWM_GEN_0);//使能相應PWN發生器模塊
  92. //            PWMGenEnable(PWM0_BASE, PWM_GEN_1);
  93. //            PWMGenEnable(PWM0_BASE, PWM_GEN_2);
  94. //            PWMGenEnable(PWM0_BASE, PWM_GEN_3);
  95. }

  96. //Todo
  97. //聲音定位

  98. /** * adc采集數據長度 */
  99. #define ADC_DATA_LEN    2048
  100. /* * adc采集完成標志位 */
  101. volatile uint8_t  AdcFinishFlag = 0;
  102. /* * adc雙buff緩沖區  緩沖完成的區域序號 */
  103. volatile uint8_t  AdcBuffIndex = 0;
  104. /** adc數組下標 */
  105. volatile uint32_t adcCount = 0;

  106. /* * ADC數據   adc0 1 2 3 采集麥克風信號
  107. *
  108. *     2     1
  109. *
  110. *     3     0    */
  111. __attribute__ ((aligned(256)))  volatile int16_t g_adc0Data[2][ADC_DATA_LEN];
  112. __attribute__ ((aligned(256)))  volatile int16_t g_adc1Data[2][ADC_DATA_LEN];
  113. __attribute__ ((aligned(256)))  volatile int16_t g_adc2Data[2][ADC_DATA_LEN];
  114. //__attribute__ ((aligned(256)))  volatile int16_t g_adc3Data[2][ADC_DATA_LEN];

  115. /* * 互相關結果 */
  116. float g_acor1[2][30];
  117. float g_acor2[2][30];
  118. //float g_acor3[2][30];
  119. //float g_acor4[2][30];

  120. /* * 聲音角度 */
  121. float g_Angle   = 0;
  122. /* * ADC數據   adc0 1 2 3 采集麥克風信號
  123. *
  124. *     2     1
  125. *
  126. *     3     0
  127. *
  128. *    PD2    PB5
  129. *
  130. *   (PK1)    PB4
  131. *     */
  132. //引腳對應通道、通道連接采樣序列、采樣序列使能
  133. void VoiceInit(void)
  134. {
  135.         // 初始化ADC0/       初始化PB4、PB5為TypeADC
  136.         SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
  137.         SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
  138.         GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);
  139.         GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_5);
  140.         // 初始化ADC1/      初始化PK0、PK1TypeADC
  141.         SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
  142.         SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
  143.         GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_2);
  144. //        GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_1);

  145.     // 配置ADC0的采集序列2給PB4        //配置ADC0采樣序列2的步驟0,PB4的模擬通道是AIN10(ADC_CTL_CH10)
  146.         ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
  147.         ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH10 | ADC_CTL_END | ADC_CTL_IE);

  148.         //配置ADC0的采集序列1給PB5        //配置ADC0采樣序列1的步驟0,PB5的模擬通道是AIN11(ADC_CTL_CH11)
  149.         ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
  150.         ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH11 | ADC_CTL_END | ADC_CTL_IE);
  151. //
  152. //    // 配置ADC1的采集序列2給PD2        //配置ADC1采樣序列2的步驟0,PK0的模擬通道是AIN13(ADC_CTL_CH13)
  153.         ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
  154.         ADCSequenceStepConfigure(ADC1_BASE, 0, 0, ADC_CTL_CH13 | ADC_CTL_END | ADC_CTL_IE);

  155. //        //配置ADC0的采集序列1給PK1        //配置ADC1的采樣序列1的步驟0,PK1的模擬通道是AIN17(ADC_CTL_CH17)
  156. //        ADCSequenceConfigure(ADC1_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
  157. //        ADCSequenceStepConfigure(ADC1_BASE, 1, 0, ADC_CTL_CH17 | ADC_CTL_END | ADC_CTL_IE);

  158.         // 使能ADC采集序列   //清中斷
  159.         ADCSequenceEnable(ADC0_BASE, 2);
  160.         ADCSequenceEnable(ADC0_BASE, 1);
  161.         ADCSequenceEnable(ADC1_BASE, 0);
  162. //        ADCSequenceEnable(ADC1_BASE, 1);

  163.         ADCIntClear(ADC0_BASE, 2);
  164.         ADCIntClear(ADC0_BASE, 1);
  165.         ADCIntClear(ADC1_BASE, 0);
  166. //        ADCIntClear(ADC1_BASE, 1);

  167. //        CCU6_InitConfig(CCU60, CCU6_Channel0, 100);  //100us進入一次中斷  中斷中采集adc數據

  168. }

  169. /*!  * @brief   采集中斷服務函數   聲音信號采集  * @date     2020/4/28  */
  170. void VoiceGetSample(void)
  171. {
  172.         static uint8_t adcIndex = 0;
  173.         if(adcCount >= ADC_DATA_LEN)
  174.         {
  175.                 adcCount = 0;
  176.                 AdcFinishFlag = 1;
  177.                 /* 切換buff緩沖區 */
  178.                 if(adcIndex == 0)
  179.                 {
  180.                         adcIndex = 1;
  181.                         AdcBuffIndex = 0;
  182.                 }
  183.                 else
  184.                 {
  185.                         adcIndex = 0;
  186.                         AdcBuffIndex = 1;
  187.                 }
  188.         }

  189.         // 觸發采集
  190.         ADCProcessorTrigger(ADC0_BASE, 2);
  191.         ADCProcessorTrigger(ADC0_BASE, 1);
  192.         ADCProcessorTrigger(ADC1_BASE, 0);
  193. //        ADCProcessorTrigger(ADC1_BASE, 1);
  194.         // 等待采集結束  // 獲取采集結果
  195.         while(!ADCIntStatus(ADC0_BASE, 2, false)) ;
  196.         ADCSequenceDataGet(ADC0_BASE, 2, &g_adc0Data[adcIndex][adcCount]);

  197.         while(!ADCIntStatus(ADC0_BASE, 1, false)) ;
  198.         ADCSequenceDataGet(ADC0_BASE, 1, &g_adc1Data[adcIndex][adcCount]);

  199.         while(!ADCIntStatus(ADC1_BASE, 0, false)) ;
  200.         ADCSequenceDataGet(ADC1_BASE, 0, &g_adc2Data[adcIndex][adcCount]);
  201. //
  202. //        while(!ADCIntStatus(ADC1_BASE, 1, false)) ;
  203. //        ADCSequenceDataGet(ADC1_BASE, 1, &g_adc3Data[adcIndex][adcCount]);

  204.         adcCount++;
  205. }
  206. /*!
  207.   * @brief        歸一化處理
  208.   *
  209.   * @param    x   : 要處理數據
  210.   * @param    len : 要處理數據長度
  211.   * @date     2020/4/28
  212.   */
  213. void Normal(int16_t *x, uint16_t len)
  214. {
  215.         float sum = 0;
  216.         int   i;
  217.         for(i = 0; i < len; i++)
  218.         {
  219.                 sum += x[i];
  220.         }
  221.         sum = sum / len;
  222.         for(i = 0; i < len; i++)
  223.         {
  224.                 x[i] -= sum;
  225.         }
  226. }
  227. /*!
  228.   * @brief         互相關
  229.   *
  230.   * @param    acor1:  y0 y1 互相關結果
  231.   * @param    acor2:  y1 y2互相關結果
  232.   * @param    acor3:  y0 y2互相關結果
  233.   * @param    acor4:  y1 y3互相關結果
  234.   * @param    y0   : 互相關數據 y0
  235.   * @param    y1   : 互相關數據 y1
  236.   * @param    y2   : 互相關數據 y2
  237.   * @param    y3   : 互相關數據 y3
  238.   * @param    len  : 互相關數據長度
  239.   * @date     2020/4/28
  240.   */
  241. //void Xcorr(float *acor1, float *acor2, float *acor3, float *acor4, int16_t *y0, int16_t *y1, int16_t *y2, int16_t *y3, uint16_t len)
  242. void Xcorr(float *acor1, float *acor2, int16_t *y0, int16_t *y1, int16_t *y2,  uint16_t len)
  243. {
  244. //        float sum3 = 0;
  245. //        float sum4 = 0;
  246.         float sum1 = 0;
  247.         float sum2 = 0;
  248.         int delay, i, j;
  249.         for(delay = -15; delay < 15; delay++)              //30個互相關的值
  250. //        for(delay = -len + 1; delay < len; delay++)       //len個互相關的值
  251.         {
  252.                 sum1 = 0;
  253.                 sum2 = 0;
  254. //                sum3 = 0;
  255. //                sum4 = 0;
  256.                 for(i = 0; i < len; i++)
  257.                 {
  258.                         j = i + delay;
  259.                         if((j < 0))
  260.                         {
  261.                                 sum1 += 0.0001f * y0[j + len] * y1[i];     //縮小一定倍數,防止溢出
  262.                                 sum2 += 0.0001f * y1[j + len] * y2[i];
  263. //                                sum3 += 0.0001f * y0[j + len] * y2[i];
  264. //                                sum4 += 0.0001f * y1[j + len] * y3[i];
  265.                         }
  266.                         else if ((j >= len))
  267.                         {
  268.                                 sum1 += 0.0001f * y0[j - len] * y1[i];
  269.                                 sum2 += 0.0001f * y1[j - len] * y2[i];
  270. //                                sum3 += 0.0001f * y0[j - len] * y2[i];
  271. //                                sum4 += 0.0001f * y1[j - len] * y3[i];
  272.                         }
  273.                         else
  274.                         {
  275.                                 sum1 += 0.0001f * y0[j] * y1[i];
  276.                                 sum2 += 0.0001f * y1[j] * y2[i];
  277. //                                sum3 += 0.0001f * y0[j] * y2[i];
  278. //                                sum4 += 0.0001f * y1[j] * y3[i];
  279.                         }
  280.                 }
  281.                 acor1[15 + delay] = (float)sum1;
  282.                 acor2[15 + delay] = (float)sum2;
  283. //                acor3[15 + delay] = (float)sum3;
  284. //                acor4[15 + delay] = (float)sum4;
  285.         }
  286. }



  287. /*!
  288.   * @brief    得到最大相關位置
  289.   *
  290.   * @param    acor1: 互相關結果
  291.   * @param    acor2: 互相關結果
  292.   * @param    acor3: 互相關結果
  293.   * @param    acor4: 互相關結果
  294.   * @param    len  : 數據長度  (與delay 對應)
  295.   * @param    index: 存放相關結果最大值下標
  296.   * @date     2020/4/28
  297.   */
  298. void SeekMaxAcor(float * acor1, float * acor2, int16_t len, int16_t *index)
  299. {
  300.         int16_t i = 0;

  301.         index[0] = 0;
  302.         index[1] = 0;
  303. //        index[2] = 0;
  304. //        index[3] = 0;
  305.         for(i = 1; i < len; i++)
  306.         {
  307.                 if(acor1[i] > acor1[index[0]])
  308.                 {
  309.                         index[0] = i;
  310.                 }
  311.                 if(acor2[i] > acor2[index[1]])
  312.                 {
  313.                         index[1] = i;
  314.                 }
  315. //                if(acor3[i] > acor3[index[2]])
  316. //                {
  317. //                        index[2] = i;
  318. //                }
  319. //                if(acor4[i] > acor4[index[3]])
  320. //                {
  321. //                        index[3] = i;
  322. //                }
  323.         }

  324.         index[0] = len/2 - index[0];                  //下標結果變成負數的關鍵!
  325.         index[1] = len/2 - index[1];
  326. //        index[2] = len/2 - index[2];
  327. //        index[3] = len/2 - index[3];
  328. }
  329. /*!
  330.   * @brief    麥克風數據處理  獲取角度信息
  331.   *
  332.   * @param    無
  333.   *
  334.   * @return   最大相關位置
  335.   *
  336.   * @note     無
  337.   *
  338.   * @see
  339.   *
  340.   * @date     2020/4/28
  341.   */
  342. void VoiceProcess(void)
  343. {
  344. //        if(AdcFinishFlag)
  345. //        {
  346. //                /* 數據處理    */
  347. //                Normal((int16_t *)g_adc0Data[AdcBuffIndex], ADC_DATA_LEN);
  348. //                Normal((int16_t *)g_adc1Data[AdcBuffIndex], ADC_DATA_LEN);
  349. //                Normal((int16_t *)g_adc2Data[AdcBuffIndex], ADC_DATA_LEN);
  350. //                Normal((int16_t *)g_adc3Data[AdcBuffIndex], ADC_DATA_LEN);
  351. //
  352. //                for(int i = 0; i < ADC_DATA_LEN; i ++)
  353. //                {
  354. //          /* 上報匿名上位機  看原始數據波形 */
  355. //                        ANO_DT_send_int16(g_adc0Data[AdcBuffIndex][i], g_adc1Data[AdcBuffIndex][i], g_adc2Data[AdcBuffIndex][i], g_adc3Data[AdcBuffIndex][i], 0, 0, 0, 0);
  356. //                }
  357. //
  358. //                AdcFinishFlag = 0;
  359. //        }
  360.         if(AdcFinishFlag)
  361.         {
  362.                 //存放相關峰值下標
  363.                 int16_t acorIndex[4];
  364.                 // 記錄時間
  365. //                uint32_t nowTime = STM_GetNowUs(STM0);
  366.                 // 數據處理
  367.                 Normal((int16_t *)g_adc0Data[AdcBuffIndex], ADC_DATA_LEN);
  368.                 Normal((int16_t *)g_adc1Data[AdcBuffIndex], ADC_DATA_LEN);
  369.                 Normal((int16_t *)g_adc2Data[AdcBuffIndex], ADC_DATA_LEN);
  370. //                Normal((int16_t *)g_adc3Data[AdcBuffIndex], ADC_DATA_LEN);
  371.                 // 互相關
  372.         Xcorr((float *)&g_acor1[AdcBuffIndex], (float *)&g_acor2[AdcBuffIndex], (int16_t *)&g_adc0Data[AdcBuffIndex], (int16_t *)&g_adc1Data[AdcBuffIndex], (int16_t *)&g_adc2Data[AdcBuffIndex], ADC_DATA_LEN);
  373.         //  g_acor1:  麥克風0 麥克風1 互相關結果
  374.         //  g_acor2:  麥克風1 麥克風2 互相關結果

  375.                 // 獲取最大相關峰值
  376.                 SeekMaxAcor((float *)&g_acor1[AdcBuffIndex], (float *)&g_acor2[AdcBuffIndex], 30, acorIndex);
  377.                 //acorIndex[0]存放g_acor1峰值的下標
  378.                 //acorIndex[1]存放g_acor1峰值的下標
  379.                 //acorIndex[2]存放g_acor1峰值的下標
  380.                 //acorIndex[3]存放g_acor1峰值的下標
  381. //                pidVoice_error=acorIndex[1];//下標偏差

  382.                 // 四組相關數據 最大最小結果下標
  383.                 uint8_t IndexMax = 0, IndexMin = 0;

  384.                 //找到絕對值最小和最大的值下標
  385.                 uint8_t i = 0;
  386.                 for(i = 1; i < 2; i++)
  387.                 {
  388.                         if(abs(acorIndex[i]) >= abs(acorIndex[IndexMax]))    //絕對值最小
  389.                         {
  390.                                 IndexMax = i;
  391.                         }
  392.                         if(abs(acorIndex[i]) <= abs(acorIndex[IndexMin]))
  393.                         {
  394.                                 IndexMin = i;
  395.                         }
  396.                 }
  397.                 // 判斷大致方位
  398.                 if(IndexMin == 0)
  399.                 {
  400.                         if(acorIndex[1] > 0)
  401.                         {g_Angle = 0;}
  402.                         else
  403.                         {g_Angle = 180;}
  404.                 }

  405.                 else if(IndexMin == 1)
  406.                 {
  407.                         if(acorIndex[0] > 0)
  408.                         {g_Angle = 270 ;}
  409.                         else
  410.                         {g_Angle = 90;}
  411.                 }

  412. //                else if(IndexMin == 2)
  413. //                {
  414. //                        if(acorIndex[3] > 0)
  415. //                        {g_Angle = 45;}
  416. //                        else
  417. //                        {g_Angle =225;}
  418. //                }
  419. //
  420. //                else if(IndexMin == 3)
  421. //                {
  422. //                        if(acorIndex[2] > 0)
  423. //                        {g_Angle =315;}
  424. //                        else
  425. //                        {g_Angle=135;}
  426. //                }

  427. //                nowTime = STM_GetNowUs(STM0) - nowTime;
  428. //                VoiceCalculatorTime=nowTime;
  429. //                TFTLCD_ShowData(138,90,(int)g_Angle,WHITE,BLACK);//
  430.                 AdcFinishFlag = 0;
  431.         }
  432. }

  433. /****用于聲音采集,0.1ms一次****/
  434. void Timer2BIntHandler()
  435. {
  436.         unsigned long Status;
  437.         TimerDisable(TIMER2_BASE, TIMER_B);
  438.         Status=TimerIntStatus(TIMER2_BASE,true);

  439.         if(Status==TIMER_TIMB_TIMEOUT)
  440.         {
  441.                 VoiceGetSample();
  442.         }
  443.         TimerIntClear(TIMER2_BASE, Status);//計時清零
  444.         TimerLoadSet(TIMER2_BASE, TIMER_B, 0.1*g_ui32SysClock/1000);//控制計時器的計時長度100us,0.1ms
  445.         TimerEnable(TIMER2_BASE, TIMER_B);//定時器使能
  446. }



  447. void Timer3BIntHandler()
  448. {
  449.         unsigned long Status;
  450.         TimerDisable(TIMER3_BASE, TIMER_B);
  451.         Status=TimerIntStatus(TIMER3_BASE,true);

  452.         if(Status==TIMER_TIMB_TIMEOUT)
  453.         {
  454.                 if(g_Angle==0)
  455.                 {
  456.                         PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1,7500);
  457.                         PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1,36500);
  458. ……………………

  459. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有代碼51hei提供下載:
Final最終版本工程.rar (334.72 KB, 下載次數: 36)

評分

參與人數 1黑幣 +100 收起 理由
admin + 100 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产高清视频一区 | 国产成人精品视频在线观看 | 亚洲精品成人av久久 | 久久曰视频 | 午夜丰满少妇一级毛片 | 综合精品| 亚洲一区二区三区视频 | 伊人影院99 | 亚洲一区二区成人 | 久久久久久久久久久久久久久久久久久久 | 日韩欧美在线视频观看 | 影视一区 | 欧美激情a∨在线视频播放 成人免费共享视频 | 亚洲成人免费av | 成人啊啊啊 | 台湾佬久久 | 色吧综合 | 免费亚洲婷婷 | 日韩午夜网站 | 99精品九九 | 国产高清在线观看 | 亚洲一区自拍 | 美女张开腿露出尿口 | 日本免费视频在线观看 | 超碰美女在线 | 一级片视频免费观看 | 成人精品福利 | 激情五月激情综合网 | 天天干天天插天天 | 亚洲高清在线 | 精品欧美一区免费观看α√ | 91精品一区 | 成人精品一区二区 | 不卡一区二区三区四区 | 久久久久成人精品亚洲国产 | 午夜精品久久久久久久星辰影院 | 欧美精品一区三区 | 欧美性生交大片免费 | 亚洲+变态+欧美+另类+精品 | 国产日本精品视频 | 一区二区在线不卡 |