Skip to content

Commit

Permalink
examples/foc: support svm3 state with nxscope
Browse files Browse the repository at this point in the history
  • Loading branch information
raiden00pl authored and xiaoxiang781216 committed Oct 5, 2023
1 parent a56f092 commit b88057f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
20 changes: 19 additions & 1 deletion examples/foc/foc_fixed16_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int foc_handler_run(FAR struct foc_motor_b16_s *motor,

foc_handler_state_b16(&motor->handler,
&motor->foc_state,
NULL);
&motor->mod_state);

return ret;
}
Expand Down Expand Up @@ -259,6 +259,24 @@ static void foc_fixed16_nxscope(FAR struct foc_nxscope_s *nxs,
ptr = (FAR b16_t *)&motor->vdq_comp;
nxscope_put_vb16_t(&nxs->nxs, i++, ptr, 2);
#endif
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SVM3)
b16_t svm3_tmp[4];

/* Convert sector to b16_t.
* Normally, a sector value is an integer in the range 1-6 but we convert
* it to b16_t and range to 0.1-0.6. This is to send the entire SVM3 state
* as b16_t array and scale the sector value closer to PWM duty values
* (range 0.0 to 0.5) which makes it easier to visualize the data later.
*/

svm3_tmp[0] = b16mulb16(itob16(motor->mod_state.sector), ftob16(0.1f));
svm3_tmp[1] = motor->mod_state.d_u;
svm3_tmp[2] = motor->mod_state.d_v;
svm3_tmp[3] = motor->mod_state.d_w;

ptr = svm3_tmp;
nxscope_put_vfloat(&nxs->nxs, i++, ptr, 4);
#endif

nxscope_unlock(&nxs->nxs);
}
Expand Down
20 changes: 19 additions & 1 deletion examples/foc/foc_float_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int foc_handler_run(FAR struct foc_motor_f32_s *motor,

foc_handler_state_f32(&motor->handler,
&motor->foc_state,
NULL);
&motor->mod_state);

return ret;
}
Expand Down Expand Up @@ -260,6 +260,24 @@ static void foc_float_nxscope(FAR struct foc_nxscope_s *nxs,
ptr = (FAR float *)&motor->vdq_comp;
nxscope_put_vfloat(&nxs->nxs, i++, ptr, 2);
#endif
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SVM3)
float svm3_tmp[4];

/* Convert sector to float.
* Normally, a sector value is an integer in the range 1-6 but we convert
* it to float and range to 0.1-0.6. This is to send the entire SVM3 state
* as float array and scale the sector value closer to PWM duty values
* (range 0.0 to 0.5) which makes it easier to visualize the data later.
*/

svm3_tmp[0] = (float)motor->mod_state.sector * 0.1f;
svm3_tmp[1] = motor->mod_state.d_u;
svm3_tmp[2] = motor->mod_state.d_v;
svm3_tmp[3] = motor->mod_state.d_w;

ptr = svm3_tmp;
nxscope_put_vfloat(&nxs->nxs, i++, ptr, 4);
#endif

nxscope_unlock(&nxs->nxs);
}
Expand Down
3 changes: 3 additions & 0 deletions examples/foc/foc_motor_b16.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ struct foc_motor_b16_s
/* FOC data ***************************************************************/

struct foc_state_b16_s foc_state; /* FOC controller sate */
#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3
struct svm3_state_b16_s mod_state; /* Modulation state */
#endif
foc_handler_b16_t handler; /* FOC controller */
dq_frame_b16_t dq_ref; /* DQ reference */
dq_frame_b16_t vdq_comp; /* DQ voltage compensation */
Expand Down
3 changes: 3 additions & 0 deletions examples/foc/foc_motor_f32.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ struct foc_motor_f32_s
/* FOC data ***************************************************************/

struct foc_state_f32_s foc_state; /* FOC controller sate */
#ifdef CONFIG_INDUSTRY_FOC_MODULATION_SVM3
struct svm3_state_f32_s mod_state; /* Modulation state */
#endif
foc_handler_f32_t handler; /* FOC controller */
dq_frame_f32_t dq_ref; /* DQ reference */
dq_frame_f32_t vdq_comp; /* DQ voltage compensation */
Expand Down
3 changes: 3 additions & 0 deletions examples/foc/foc_nxscope.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ int foc_nxscope_init(FAR struct foc_nxscope_s *nxs)
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_VDQCOMP)
nxscope_chan_init(&nxs->nxs, i++, "vdqcomp", u.u8, 2, 0);
#endif
#if (CONFIG_EXAMPLES_FOC_NXSCOPE_CFG & FOC_NXSCOPE_SVM3)
nxscope_chan_init(&nxs->nxs, i++, "svm3", u.u8, 4, 0);
#endif

if (i > CONFIG_EXAMPLES_FOC_NXSCOPE_CHANNELS)
{
Expand Down
1 change: 1 addition & 0 deletions examples/foc/foc_nxscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define FOC_NXSCOPE_SPPOS (1 << 13) /* Position setpoint */
#define FOC_NXSCOPE_DQREF (1 << 14) /* DQ reference */
#define FOC_NXSCOPE_VDQCOMP (1 << 15) /* VDQ compensation */
#define FOC_NXSCOPE_SVM3 (1 << 16) /* Space-vector modulation sector */
/* Max 32-bit */

/****************************************************************************
Expand Down

0 comments on commit b88057f

Please sign in to comment.