You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/03/30 16:31:26 UTC

[GitHub] [incubator-nuttx] raiden00pl commented on a change in pull request #3244: Improvements for libdsp and support for fixed16 libdsp implementation

raiden00pl commented on a change in pull request #3244:
URL: https://github.com/apache/incubator-nuttx/pull/3244#discussion_r604254627



##########
File path: include/dspb16.h
##########
@@ -0,0 +1,480 @@
+/****************************************************************************
+ * include/dspb16.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_DSPB16_H
+#define __INCLUDE_DSPB16_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/compiler.h>
+
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdbool.h>
+#include <fixedmath.h>
+
+#include <assert.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Disable DEBUGASSERT macro if LIBDSP debug is not enabled */
+
+#ifdef CONFIG_LIBDSP_DEBUG
+#  ifndef CONFIG_DEBUG_ASSERTIONS
+#    warning "Need CONFIG_DEBUG_ASSERTIONS to work properly"
+#  endif
+#  define LIBDSP_DEBUGASSERT(x) DEBUGASSERT(x)
+#else
+#  undef LIBDSP_DEBUGASSERT
+#  define LIBDSP_DEBUGASSERT(x)
+#endif
+
+#ifndef CONFIG_LIBDSP_PRECISION
+#  define CONFIG_LIBDSP_PRECISION 0
+#endif
+
+/* Phase rotation direction */
+
+#define DIR_NONE_B16 ftob16(0.0f)
+#define DIR_CW_B16   ftob16(1.0f)
+#define DIR_CCW_B16  ftob16(-1.0f)
+
+/* Some math constants ******************************************************/
+
+#define SQRT3_BY_TWO_B16     ftob16(0.866025f)
+#define SQRT3_BY_THREE_B16   ftob16(0.57735f)
+#define ONE_BY_SQRT3_B16     ftob16(0.57735f)
+#define TWO_BY_SQRT3_B16     ftob16(1.15470f)
+
+/* Some lib constants *******************************************************/
+
+/* Motor electrical angle is in range 0.0 to 2*PI */
+
+#define MOTOR_ANGLE_E_MAX_B16    (b16TWOPI)
+#define MOTOR_ANGLE_E_MIN_B16    (0)
+#define MOTOR_ANGLE_E_RANGE_B16  (MOTOR_ANGLE_E_MAX_B16 - MOTOR_ANGLE_E_MIN_B16)
+
+/* Motor mechanical angle is in range 0.0 to 2*PI */
+
+#define MOTOR_ANGLE_M_MAX_B16    (b16TWOPI)
+#define MOTOR_ANGLE_M_MIN_B16    (0)
+#define MOTOR_ANGLE_M_RANGE_B16  (MOTOR_ANGLE_M_MAX_B16 - MOTOR_ANGLE_M_MIN_B16)
+
+/* Some useful macros *******************************************************/
+
+/****************************************************************************
+ * Name: LP_FILTER_B16
+ *
+ * Description:
+ *   Simple single-pole digital low pass filter:
+ *     Y(n) = (1-beta)*Y(n-1) + beta*X(n) = (beta * (Y(n-1) - X(n)))
+ *
+ *     filter - (0.0 - 1.0) where 1.0 gives unfiltered values
+ *     filter = T * (2*PI) * f_c
+ *
+ *     phase shift = -arctan(f_in/f_c)
+ *
+ *     T    - period at which the digital filter is being calculated
+ *     f_in - input frequency of the filter
+ *     f_c  - cutoff frequency of the filter
+ *
+ * REFERENCE: https://www.embeddedrelated.com/showarticle/779.php
+ *
+ ****************************************************************************/
+
+#define LP_FILTER_B16(val, sample, filter) val -= (b16mulb16(filter, (val - sample)))
+
+/****************************************************************************
+ * Name: SVM3_BASE_VOLTAGE_GET_B16
+ *
+ * Description:
+ *  Get maximum voltage for SVM3 without overmodulation
+ *
+ *  Notes:
+ *   max possible phase voltage for 3-phase power inwerter:

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org