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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

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

arm心率計源代碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:504670 發(fā)表于 2019-4-4 11:16 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
心率計可以將連接到板子上的心率傳感器數(shù)據(jù)采集下來并使用算法計算心率值,并通過串口傳輸?shù)街付ǖ慕K端設(shè)備。可以直接接USB-TLL模塊傳輸?shù)絇C端或者通過藍牙模塊傳輸?shù)绞謾C端。

單片機源程序如下:
  1.    //******************************說明********************************/



  2. #include "stdio.h"
  3. #include "common.h"
  4. #include "heartRateProcess.h"
  5. #define false 0
  6. #define true 1
  7. #define FOSC 11059200L                //系統(tǒng)時鐘
  8. #define BAUD 115200                                //波特率
  9. #define T0MS (65536-FOSC/12/500)                //500HZ in 12T MODE
  10. #define         BUFFER_SIZE 10

  11. #define ADC_POWER 0x80                        //ADC POWER CONTROL BIT
  12. #define ADC_FLAG 0x10                        //ADC COMPLETE FLAG
  13. #define ADC_START 0x08;                        //ADC START CONTROL BIT
  14. #define ADC_SPEEDLL 0x00                //540 CLOCKS
  15. #define ADC_SPEEDL 0x20                        //360 CLOCKS
  16. #define ADC_SPEEDH 0x40                        //180 CLOCKS
  17. #define ADC_SPEEDHH 0x60                //90 CLOCKS
  18. #define ADC_MASK 0x01

  19. #define BLUE_SHIFT (1U << 5)
  20. #define BLUE_ON (GPIOD_PCOR = BLUE_SHIFT)
  21. #define BLUE_OFF (GPIOD_PSOR = BLUE_SHIFT)
  22. #define BLUE_TOGGLE (GPIOD_PTOR = BLUE_SHIFT)



  23. unsigned int BPM;                   // 用于保存脈沖速率
  24. unsigned int Signal;                // 持有傳入的原始數(shù)據(jù)
  25. unsigned int IBI = 600;             // 保持心跳之間的空隙,必須種子!
  26. unsigned char Pulse = false;     // 當脈沖波高時真,低為假
  27. int rate[10];                    // 數(shù)組來保存最后十IBI值
  28. unsigned long sampleCounter = 0;          // used to determine pulse timing用于確定脈沖定時
  29. unsigned long lastBeatTime = 0;           // used to find IBI
  30. int Peak =255;                      // used to find peak in pulse wave, seeded用來尋找峰值脈沖波,播種
  31. int Trough = 10;                     // used to find trough in pulse wave, seededsed中找到谷底脈搏波,播種
  32. int thresh = 60;                // used to find instant moment of heart beat, seeded查找心跳的瞬間
  33. int amp = 100;                   // used to hold amplitude of pulse waveform, seeded用于保存脈沖波形的振幅,接種
  34. unsigned char firstBeat = true;        // used to seed rate array so we startup with reasonable BPM用于種子率陣列,所以我們啟動與合理的BPM
  35. unsigned char secondBeat = false;      // used to seed rate array so we startup with reasonable BPM用于種子率陣列,所以我們啟動與合理的BPM


  36. // Timer 0中斷子程序,每2MS中斷一次,讀取AD值,計算心率值
  37. //采樣率500Hz
  38. unsigned char heartRateCalc(unsigned char buf,uint16* ratte)
  39. {                       
  40.   int N;
  41.   unsigned char i,j;

  42. unsigned char QS = false;                 // becomes true when 51 finds a beat.
  43. char cmd[100];
  44. uint16 len;

  45.         // keep a running total of the last 10 IBI values保持過去10 個心跳間隙值運行總數(shù)
  46.   unsigned int runningTotal = 0;                  // clear the runningTotal variable 清除正在運行的總變量  
  47.         j=0;
  48.         
  49.   Signal = buf;              // read the Pulse Sensor 讀取脈搏傳感器
  50.   sampleCounter += 2;                         // keep track of the time in mS with this variable追蹤這個變量在毫秒級
  51.   N = sampleCounter - lastBeatTime;       // monitor the time since the last beat to avoid noise因為最后一次心跳監(jiān)測時間可避免噪音
  52.   

  53.     //  找到脈搏波的波谷
  54.   if(Signal < thresh && N > (IBI/5)*3)
  55.   {       // 避免重脈噪聲最后IBI等待4/5
  56.     if (Signal < Trough)
  57.         {                        // T is the trough;T是波谷
  58.       Trough = Signal;                         // 跟蹤最低點的脈沖波
  59.     }
  60.   }

  61.   //  找到脈搏波的波峰

  62.   if(Signal > thresh && Signal > Peak)
  63.   {          // thresh condition helps avoid noise閾值條件有助于避免噪音
  64.     Peak = Signal;                             // P is the peak; P是峰
  65.   }                                        // keep track of highest point in pulse wave跟蹤最高點的脈沖波


  66.   //  NOW IT'S TIME TO LOOK FOR THE HEART BEAT 現(xiàn)在是時候去尋找心跳
  67.   // signal surges up in value every time there is a pulse每次有一個脈沖信號涌起的價值
  68.   if (N > 250)
  69.   {                                   // avoid high frequency noise 避免了高頻噪音
  70.     if ( (Signal > thresh) && (Pulse == false) && (N > (IBI)*0.6) )
  71.         {        
  72.       Pulse = true;                               // set the Pulse flag when we think there is a pulse當我們認為有脈沖時設(shè)置脈沖標志
  73.     //  blinkPin=0;               // turn on pin 13 打開LED引腳
  74.       IBI = sampleCounter - lastBeatTime;         // measure time between beats in mS
  75.       lastBeatTime = sampleCounter;               // keep track of time for next pulse


  76.       if(secondBeat)
  77.           {                        // if this is the second beat, if secondBeat == TRUE
  78.         secondBeat = false;                  // clear secondBeat flag清零第二拍標志
  79.       //  for(i=0; i<=9; i++)
  80.                         //        {             // seed the running total to get a realisitic BPM at startup在啟動時獲得真實BPM運行總數(shù)
  81.       //    rate[9] = IBI;                     
  82.       //  }
  83.       }


  84.       if(firstBeat)
  85.           {                         // if it's the first time we found a beat, if firstBeat == TRUE
  86.         firstBeat = false;                   // clear firstBeat flag 清零第一拍標志
  87.         secondBeat = true;                   // set the second beat flag設(shè)置第二拍標志
  88.       //  EA=1;                               // enable interrupts again再次啟用中斷
  89.       Pulse = false;
  90.         return QS;                              // IBI value is unreliable so discard itIBI值是不可靠的,所以將其丟棄
  91.       }   

  92.                 BLUE_ON;
  93. //程序運行到這里表示已經(jīng)找到第二個節(jié)拍
  94.                         //存放節(jié)拍的數(shù)組依次往前移位,留下最后一個來裝新得到的節(jié)拍周期
  95.       for(i=0; i<=8; i++)
  96.           {                // shift data in the rate array移動數(shù)組中的數(shù)據(jù)
  97.         rate[i]= rate[i+1];                  // and drop the oldest IBI value 并刪除最舊的IBI值
  98.         runningTotal += rate[i];              // add up the 9 oldest IBI values將9個最古老的IBI值加起來
  99.       }

  100. //存放最新的節(jié)拍周期
  101.       rate[9] = IBI;                          // add the latest IBI to the rate array添加最新IBI的速度陣列
  102.       runningTotal += rate[9];                // add the latest IBI to runningTotal加上最新的IBI運行數(shù)
  103.       runningTotal /= 10;                     // average the last 10 IBI values 平均最近10個IBI值
  104.       BPM = 60000/runningTotal;               // how many beats can fit into a minute? that's BPM!有多少心跳可以放入一分鐘?這是BPM的!
  105.             if(BPM>200)BPM=200;                        //限制BPM最高顯示值
  106.             if(BPM<30)BPM=30;                                //限制BPM最低顯示值
  107.       QS = true;                              // set Quantified Self flag 設(shè)置量化自我標志
  108.         len=sprintf(cmd,"Peak=%d,thresh=%d,Trough=%d,amp=%d,IBI=%d,N=%d,BPM=%d\r\n",Peak,thresh,Trough,amp,IBI,N,BPM);
  109. //        IntfWrite(0,cmd,len);
  110.       // QS FLAG IS NOT CLEARED INSIDE THIS ISR;  QS標志不會被清除這里面中斷服務(wù)程序
  111.     }                       
  112.   }

  113. //檢測下降
  114.   if (Signal < thresh && Pulse == true) // when the values are going down, the beat is over當值正在下降,節(jié)拍結(jié)束
  115.   {  
  116.           BLUE_OFF;// turn off pin 13 LED
  117.     Pulse = false;                         // reset the Pulse flag so we can do it again復(fù)位脈沖標志,所以我們可以再做一次
  118.     amp = Peak - Trough;                           // get amplitude of the pulse wave得到的脈搏波的振幅
  119.     thresh = amp/2 + Trough;                    // set thresh at 50% of the amplitude設(shè)定閾值的幅度的50%
  120.     Peak = thresh;                            // reset these for next time為下一次復(fù)位
  121.     Trough = thresh;
  122.         len=sprintf(cmd,"fall edge:Peak=%d,thresh=%d,Trough=%d,amp=%d,IBI=%d,N=%d,BPM=%d\r\n",Peak,thresh,Trough,amp,IBI,N,BPM);
  123. //        IntfWrite(0,cmd,len);
  124.   }

  125. //重新初始化
  126.   if (N > 2500)  // if 2.5 seconds go by without a beat 如果2.5秒去,沒有一個節(jié)拍
  127.   {                        
  128.     thresh = 50;                          // set thresh default設(shè)置默認的閾值
  129.     Peak = 155;                               // set P default默認設(shè)置P
  130.     Trough = 10;                               // set T default默認設(shè)置T
  131.     lastBeatTime = sampleCounter;          // bring the lastBeatTime up to date     最后一拍的時間   
  132.     firstBeat = true;                      // set these to avoid noise
  133.     secondBeat = false;                    // when we get the heartbeat back
  134.     Pulse = false;
  135.   }


  136.   //EA=1;                                   // enable interrupts when youre done!允許中斷時,大功告成!
  137.   *ratte=BPM;
  138.   return QS;
  139. }// end isr
  140. void filter(uint8* buf,unsigned char len)
  141. {

  142. static uint8 x0=50,x1=50;
  143. uint8 i,temp;
  144. uint8 k=1,throd=10;
  145. uint8 Buff[BUFFER_SIZE+2];
  146.          uint8 buffback[BUFFER_SIZE];
  147.         memcpy(Buff+2,buf,len);
  148. //for(i=0;i<len;len++)
  149. //        Buff[i+2]=buf[i];
  150. Buff[0]=x0;
  151. Buff[1]=x1;

  152. for(i=0;i<len;len++)
  153.         if(abs(Buff[i+1]-Buff[i])>throd)
  154.                 buffback[i]=(Buff[i+2]+Buff[i])/2;
  155.         else
  156.                 buffback[i]=Buff[i+1];
  157. x0=Buff[BUFFER_SIZE];
  158. x1=Buff[BUFFER_SIZE+1];



  159. }
復(fù)制代碼

所有資料51hei提供下載:
HeartRateTestPrj.7z (428.99 KB, 下載次數(shù): 9)



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

使用道具 舉報

沙發(fā)
ID:1 發(fā)表于 2019-4-5 03:50 | 只看該作者
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 91免费电影 | 国产精品网址 | 成av在线 | 玖玖在线精品 | 久久亚洲一区 | 超碰在线网站 | 欧美性一级 | 天天天天天操 | 欧美 日韩 中文 | 综合一区二区三区 | 91亚洲一区| 亚洲精品粉嫩美女一区 | 99热精品在线观看 | 成人免费看电影 | 91九色在线观看 | 久久99蜜桃综合影院免费观看 | 91精品国产综合久久久久久蜜臀 | 91在线免费观看 | 亚州毛片 | 91精品国产高清久久久久久久久 | 毛片国产| 一级黄色毛片a | 羞视频在线观看 | 羞羞视频免费观 | 亚洲高清在线 | 久久久久久999 | 久久久国产一区二区三区四区小说 | 一级做a爰片久久毛片免费看 | 欧美成人自拍 | 亚州精品天堂中文字幕 | 中文字幕第十一页 | 国产在线资源 | 伊人性伊人情综合网 | 国产97色 | 欧美激情啪啪 | 国产成人91视频 | 国产精品视频播放 | 国产精品久久国产精品久久 | av一级久久 | 精品久久久久一区二区国产 | 蜜月aⅴ免费一区二区三区 99re在线视频 |