This makes Amplitude Modulated Pulse Train, which can be regarded as the discretized wave of the signal. Pulse Train can be defined by frequency and duty cycle, which can be temporarily changed, referring to PWM.

Dependents:   Interference_Simple

Committer:
aktk
Date:
Mon Jan 06 21:37:20 2020 +0000
Branch:
35e9675a
Revision:
5:77ac0df7c3a1
Parent:
1:19c3a52c80c3
Child:
7:5eae3f90d161
Complicated branch revision :'(

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aktk 1:19c3a52c80c3 1 /** Defining Amplide Modulated Pulse Train Model
aktk 1:19c3a52c80c3 2 *
aktk 1:19c3a52c80c3 3 * \file PulseTrain.h
aktk 1:19c3a52c80c3 4 * \author Akifumi Takahashi
aktk 1:19c3a52c80c3 5 * \date 2019/12/02 -
aktk 1:19c3a52c80c3 6 * \version 1.0.2019.Dec
aktk 1:19c3a52c80c3 7 */
aktk 1:19c3a52c80c3 8
aktk 1:19c3a52c80c3 9 #ifndef PULSE_TRAIN_H
aktk 1:19c3a52c80c3 10 #define PULSE_TRAIN_H
aktk 1:19c3a52c80c3 11
aktk 1:19c3a52c80c3 12 #include "mbed.h"
aktk 1:19c3a52c80c3 13 /** \Class Pulse Train Model
aktk 1:19c3a52c80c3 14 *
aktk 1:19c3a52c80c3 15 * Pulse Train Model which clock is defined in scale of [us];
aktk 1:19c3a52c80c3 16 * You can define the carrier pulse train's freq and duty cycle like PWM.
aktk 1:19c3a52c80c3 17 * Kinds of Frequency is dealed as unsigned 32bit int
aktk 1:19c3a52c80c3 18 * For the other int vars, allocated is 32bit.
aktk 1:19c3a52c80c3 19 */
aktk 1:19c3a52c80c3 20 class PulseTrain
aktk 1:19c3a52c80c3 21 {
aktk 1:19c3a52c80c3 22 public:
aktk 1:19c3a52c80c3 23 /** Constractor
aktk 1:19c3a52c80c3 24 */
aktk 1:19c3a52c80c3 25 PulseTrain(
aktk 1:19c3a52c80c3 26 /// Initial carrier pulse frequency
aktk 1:19c3a52c80c3 27 uint32_t const arg_freq = 4000,
aktk 1:19c3a52c80c3 28 /// Initial carrier pulse duty cycle
aktk 1:19c3a52c80c3 29 float const arg_duty = 0.5,
aktk 1:19c3a52c80c3 30 /// Initialize FREQ_MAX
aktk 1:19c3a52c80c3 31 uint32_t const arg_freq_max = 8000
aktk 1:19c3a52c80c3 32 );
aktk 1:19c3a52c80c3 33 /** Increment the clock to let go ahead the wave state
aktk 1:19c3a52c80c3 34 *
aktk 1:19c3a52c80c3 35 * If callback as rising/falling is also called,
aktk 1:19c3a52c80c3 36 * this "asClock" is called earlier
aktk 1:19c3a52c80c3 37 */
aktk 1:19c3a52c80c3 38 void incrementClock();
aktk 1:19c3a52c80c3 39
aktk 1:19c3a52c80c3 40 /** Executes a callback fanction called as clock is incremented
aktk 1:19c3a52c80c3 41 *
aktk 1:19c3a52c80c3 42 * If callback as rising/falling is also called,
aktk 1:19c3a52c80c3 43 * this "asClock" is called at the last.
aktk 1:19c3a52c80c3 44 */
aktk 1:19c3a52c80c3 45 void attachCallback_asClock(
aktk 1:19c3a52c80c3 46 /** Called back as clock incremented
aktk 1:19c3a52c80c3 47 *
aktk 1:19c3a52c80c3 48 * \arg <pulsestate> indicate whther pulse
aktk 1:19c3a52c80c3 49 * (not clock pulse but one of pulse train) has risen/fallen
aktk 1:19c3a52c80c3 50 */
aktk 1:19c3a52c80c3 51 Callback<void(bool)> arg_callback
aktk 1:19c3a52c80c3 52 );
aktk 1:19c3a52c80c3 53
aktk 1:19c3a52c80c3 54 void attachCallback_asPulseEdge(
aktk 1:19c3a52c80c3 55 /** Called back as a pulse rising/falling
aktk 1:19c3a52c80c3 56 *
aktk 1:19c3a52c80c3 57 * \arg <pulsestate> indicate whther pulse has risen/fallen
aktk 1:19c3a52c80c3 58 */
aktk 1:19c3a52c80c3 59 Callback<void(bool)> arg_callback
aktk 1:19c3a52c80c3 60 );
aktk 1:19c3a52c80c3 61
aktk 1:19c3a52c80c3 62 void setFrequency(uint32_t const arg_freq);
aktk 1:19c3a52c80c3 63
aktk 1:19c3a52c80c3 64 void setDutycycle(float const arg_duty);
aktk 1:19c3a52c80c3 65
aktk 1:19c3a52c80c3 66 bool
aktk 1:19c3a52c80c3 67 getState(); //inline
aktk 1:19c3a52c80c3 68 uint32_t
aktk 1:19c3a52c80c3 69 getFrequency(); //inline
aktk 1:19c3a52c80c3 70 float
aktk 1:19c3a52c80c3 71 getDutycycle(); //inline
aktk 1:19c3a52c80c3 72 uint32_t
aktk 1:19c3a52c80c3 73 getPeriod_us(); //inline
aktk 1:19c3a52c80c3 74 uint32_t
aktk 1:19c3a52c80c3 75 getClockperiod_us(); //inline
aktk 1:19c3a52c80c3 76
aktk 1:19c3a52c80c3 77
aktk 1:19c3a52c80c3 78 uint32_t const FREQ_MAX;
aktk 1:19c3a52c80c3 79
aktk 1:19c3a52c80c3 80 template <typename T>
aktk 1:19c3a52c80c3 81 static T velidateRange(T const arg_val, T const arg_min, T const arg_max);
aktk 1:19c3a52c80c3 82
aktk 1:19c3a52c80c3 83 private:
aktk 1:19c3a52c80c3 84 void init();
aktk 1:19c3a52c80c3 85
aktk 1:19c3a52c80c3 86 /// Frequency of the Carrier Pulse (Hz)
aktk 1:19c3a52c80c3 87 uint32_t m_freq;
aktk 1:19c3a52c80c3 88
aktk 1:19c3a52c80c3 89 /// Duty cycle
aktk 1:19c3a52c80c3 90 float m_duty;
aktk 1:19c3a52c80c3 91
aktk 1:19c3a52c80c3 92 /// Period
aktk 1:19c3a52c80c3 93 uint32_t m_period_us;
aktk 1:19c3a52c80c3 94
aktk 1:19c3a52c80c3 95 /// GCD of the pulse period and pulse width
aktk 1:19c3a52c80c3 96 uint32_t m_clock_period_us;
aktk 1:19c3a52c80c3 97
aktk 1:19c3a52c80c3 98 /** Period per clock period
aktk 1:19c3a52c80c3 99 *
aktk 1:19c3a52c80c3 100 * The unit is what times the clock tickes
aktk 1:19c3a52c80c3 101 */
aktk 1:19c3a52c80c3 102 uint32_t m_period_pcp;
aktk 1:19c3a52c80c3 103
aktk 1:19c3a52c80c3 104 /// Timing [us] a pulse rising within a period [us]
aktk 1:19c3a52c80c3 105 static uint32_t const m_raising = 0;
aktk 1:19c3a52c80c3 106
aktk 1:19c3a52c80c3 107 /** Timing [us] a pulse falling within a period [us]
aktk 1:19c3a52c80c3 108 *
aktk 1:19c3a52c80c3 109 * Calculated in init()
aktk 1:19c3a52c80c3 110 */
aktk 1:19c3a52c80c3 111 uint32_t m_falling;
aktk 1:19c3a52c80c3 112
aktk 1:19c3a52c80c3 113 /// Flag if a palse is raised (High) or not (Low)
aktk 1:19c3a52c80c3 114 bool m_pulsestate;
aktk 1:19c3a52c80c3 115
aktk 1:19c3a52c80c3 116 /** Called back as clock incremented
aktk 1:19c3a52c80c3 117 *
aktk 1:19c3a52c80c3 118 * \arg <pulsestate> indicate whther pulse
aktk 1:19c3a52c80c3 119 * (not clock pulse but one of pulse train) has risen/fallen
aktk 1:19c3a52c80c3 120 */
aktk 1:19c3a52c80c3 121 Callback<void(bool)> m_callback_asClock;
aktk 1:19c3a52c80c3 122
aktk 1:19c3a52c80c3 123 /** Called back as a pulse rising/falling
aktk 1:19c3a52c80c3 124 *
aktk 1:19c3a52c80c3 125 * \arg <pulsestate> indicate whther pulse has risen/fallen
aktk 1:19c3a52c80c3 126 */
aktk 1:19c3a52c80c3 127 Callback<void(bool)> m_callback_asPulseEdge;
aktk 1:19c3a52c80c3 128
aktk 1:19c3a52c80c3 129 static void doNothing(bool arg_b) {;}
aktk 1:19c3a52c80c3 130
aktk 1:19c3a52c80c3 131 };
aktk 1:19c3a52c80c3 132 #endif