Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG BUTTON_GROUP LCD_DISCO_F746NG TS_DISCO_F746NG UIT_FFT_Real mbed
MyClasses/Sampler.cpp
- Committer:
- MikamiUitOpen
- Date:
- 2015-12-18
- Revision:
- 6:b27ef8d98edc
- Parent:
- 5:98ec9dd54144
- Child:
- 7:6598a9b70e5a
File content as of revision 6:b27ef8d98edc:
//-----------------------------------------------------------
// Class for sampling input signal
//
// 2015/12/18, Copyright (c) 2015 MIKAMI, Naoki
//-----------------------------------------------------------
#include "Sampler.hpp"
namespace Mikami
{
Sampler::Sampler(PinName pin, int fs, int nData,
int16_t* const buffer)
: TS_(1000000/fs), N_DATA_(nData), aIn_(pin),
buffer_(buffer)
{
Set(false);
Rd[0] = &Sampler::ReadNorm; // inphase
Rd[1] = &Sampler::ReadInv; // out-of-phase
sw_ = 0;
for (int n=0; n<nData; n++)
buffer_[n] = 32767;
}
void Sampler::IntrEnable()
{
count_ = 0;
timer_.attach_us(this, &Sampler::Isr, TS_);
}
void Sampler::Set(bool tf)
{
timer_.detach();
trigger_ = false;
xnM1_ = 32767;
filled_ = tf;
}
// Interrupt service routine for Ticker
void Sampler::Isr()
{
if (!trigger_)
{
int16_t xn = (this->*Rd[sw_])();
// Detect rising edge
if ((xn > (xnM1_+512)) && (xn > 2048))
trigger_ = true;
else
xnM1_ = xn;
return;
}
buffer_[count_] = (this->*Rd[sw_])(); // Read from A0
if (++count_ >= N_DATA_)
Set(true); // Permits spectrum analysis
}
}