![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Moving average using interrupt for ST Nucleo F401RE. The number of average is controled by sw. This program displays the number of average on LCD device connected by I2C.
Dependencies: UITDSP_ADDA mbed UIT_ACM1602NI UIT_AQM1602
Diff: main.cpp
- Revision:
- 4:7635c95836a0
- Parent:
- 2:a19243a20882
- Child:
- 5:19e433ec0a20
--- a/main.cpp Sat Nov 15 06:29:27 2014 +0000 +++ b/main.cpp Thu Jul 09 13:15:15 2015 +0000 @@ -1,9 +1,10 @@ //-------------------------------------------------------------- -// 移動平均, 平均数:1, 2, 4, 8, 16, 32, 64:スイッチで選択 -// スイッチの状態を printf() で表示する +// 移動平均, 平均数:1, 2, 4, 8, 16, 32, 64:スイッチで選択 +// 平均するデータ数,スイッチの状態を LCD 表示器に表示する +// // Analog Input : A0 -// Analog Output: MCP4922 using SPI -// 2014/11/12, Copyright (c) 2014 MIKAMI, Naoki +// Analog Output: MCP4921 or 4922 using SPI +// 2015/07/09, Copyright (c) 2015 MIKAMI, Naoki //-------------------------------------------------------------- #include "mbed.h" @@ -13,14 +14,22 @@ using namespace Mikami; -const int FS_ = 12000; // Sampling frequency: 12 kHz -ADC_Intr adc_(A0, FS_); // for AD using interrupt -DAC_MCP4922 myDac_; // for DA +// ACM1602Ni を使う場合は次の define 文をコメントにすること +//#define AQM1602 -DigitalIn sw1_(D2, PullDown); -DigitalIn sw2_(D3, PullDown); -DigitalIn sw4_(D4, PullDown); -DigitalIn sw8_(D5, PullDown); +#ifdef AQM1602 +#include "AQM1602.hpp" +Aqm1602 Lcd_; +#else +#include "ACM1602NI.hpp" +Acm1602Ni Lcd_; +#endif + +const int FS_ = 12000; // Sampling frequency: 12 kHz +ADC_Intr adc_(A0, FS_); // for AD using interrupt +DAC_MCP4922 myDac_; // for DA + +BusIn sw_(D2, D3, D4, D5); // for switch const int M_ = 64; // Maximum of average count float xn_[M_]; @@ -47,16 +56,23 @@ int main() { myDac_.ScfClockTim3(500000); // cutoff frequency: 5 kHz - adc_.SetIntrVec(AdcIsr); // Assign ISR for ADC interrupt + sw_.mode(PullDown); + Lcd_.Clear(); + adc_.SetIntrVec(AdcIsr); // Assign ISR for ADC interrupt for (int n=0; n<M_; n++) xn_[n] = 0; while (true) { - int sw = (sw8_ << 3) | (sw4_ << 2) | (sw2_ << 1) | sw1_; + int sw = sw_.read(); nAv_ = 1 << sw; if (nAv_ > 64) nAv_ = 64; printf("\r\nnAv = %d, sw = %d", nAv_, sw); + char str[17]; + sprintf(str, "nAv : %2d", nAv_); + Lcd_.WriteStringXY(str, 0, 0); + sprintf(str, "sw : %2d", sw); + Lcd_.WriteStringXY(str, 0, 1); wait(0.5f); }