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.
sinwave.cpp
00001 /** sinwave class 00002 * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab 00003 * 00004 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00005 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00006 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00007 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00008 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00009 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00010 * THE SOFTWARE. 00011 */ 00012 #include "sinwave.h" 00013 #include "sin_table.h" 00014 00015 sinwave::sinwave(float v, int f, int d, int p) : wave(v, f, d, p) 00016 { 00017 _name = "sin" ; 00018 } 00019 00020 sinwave::~sinwave(void) {} 00021 00022 void sinwave::duty(int newvalue) 00023 { 00024 _duty = newvalue ; 00025 } 00026 00027 int sinwave::duty(void) 00028 { 00029 return( 50 ) ; 00030 } 00031 00032 int sinwave::value(void) 00033 { 00034 int result = 0 ; 00035 00036 if (_phase < 90) { 00037 result = _amp * (SIN_ZERO + sin_table[ _phase * NUM_SIN_TABLE / 90 ])/0xFFFF ; 00038 } else if (_phase < 180) { 00039 result = _amp * (SIN_ZERO + sin_table[(180 - _phase) * NUM_SIN_TABLE / 90])/0xFFFF ; 00040 } else if (_phase < 270) { 00041 result = _amp * (SIN_ZERO - sin_table[(_phase - 180) * NUM_SIN_TABLE / 90])/0xFFFF ; 00042 } else if (_phase < 360) { 00043 result = _amp * (SIN_ZERO - sin_table[(360 - _phase) * NUM_SIN_TABLE / 90])/0xFFFF ; 00044 } 00045 00046 return( result ) ; 00047 }
Generated on Wed Jul 13 2022 01:58:56 by
1.7.2