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.
Diff: DSinGenerator.h
- Revision:
- 0:6400e338266f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DSinGenerator.h Wed Nov 27 23:03:42 2019 +0000
@@ -0,0 +1,96 @@
+/** Defining Discretized Sinusoidal Wave Generator
+ *
+ * \file DSinGenerator.h
+ * \author Akifumi Takahashi
+ * \date 2019/Nov/28 ver.1 publish
+ * \version 1.0.2019.Nov
+ */
+
+#ifndef DISCRETIZED_SINUSOIDAL_WAVE_GENERATOR_H
+#define DISCRETIZED_SINUSOIDAL_WAVE_GENERATOR_H
+#define _USE_MATH_DEFINES
+#include <cmath>
+
+#ifndef M_PI
+#define M_PI 3.141592
+#endif
+
+#include "mbed.h"
+/** \Class DISCRETIZED SINUSOIDAL WAVE GENERATOR
+ *
+ * Generate a discretized sinusoidal wave whose value type is float,
+ * and the range is from (-1.0f * ampl) to (1.0f * ampl).
+ *
+ */
+class DSinGenerator
+{
+private:
+ /// Amplitude of sinusoidal wave (mA)
+ float ampl;
+
+ /// Frequency of the wave (Hz)
+ uint16_t freq;
+
+ /// Pulse width fineness of dicretization (us)
+ /// pwth = 1000000 / freq / resolution_ofsin;
+ uint16_t pwth;
+
+ float* discretized_sin;
+ int32_t* discretized_sin_p16m16;
+
+ void init();
+
+public:
+ float const ampl_max;
+ uint16_t const freq_max;
+ uint16_t const resolution_ofsin; // = arg_resolution_ofsin below
+
+ DSinGenerator(
+ uint16_t const arg_resolution_ofsin = 20
+ );
+ DSinGenerator(
+ float const arg_ampl,
+ uint16_t const arg_freq,
+ uint16_t const arg_resolution_ofsin = 20
+ );
+
+ void setParam(
+ float const arg_ampl,
+ uint16_t const arg_freq
+ );
+
+ void setAmplitude(
+ float const arg_ampl
+ );
+
+ void setFrequency(
+ uint16_t const arg_freq
+ );
+
+ float getValue();
+ int32_t getValue_p16m16();
+
+ void getValueofSamplePoints(float[]);
+
+ float getAmplitude(); //inline
+ uint16_t getFrequency(); //inline
+ uint16_t getPulseWidth(); //inline
+
+};
+
+
+inline float DSinGenerator::getAmplitude()
+{
+ return ampl;
+}
+
+inline uint16_t DSinGenerator::getFrequency()
+{
+ return freq;
+}
+
+inline uint16_t DSinGenerator::getPulseWidth()
+{
+ return pwth;
+}
+#endif
\ No newline at end of file