I am trying to utilize PowerQuad to copy 16-bit buffer to 32-bit buffer and scale in process.
It works fine except every 8th output value is wrong...
Rows = 16, Cols = 8
void arm_mat_q15_to_q31_scaled(
const arm_matrix_instance_q15* pSrc,
int32_t shift,
arm_matrix_instance_q31* pDst)
{
pq_config_t config;
PQ_GetDefaultConfig(&config);
config.inputAFormat = kPQ_16Bit;
config.outputFormat = kPQ_32Bit;
config.outputPrescale = (int8_t)shift;
PQ_SetConfig(POWERQUAD, &config);
float factor = 1.0f; // (float)(1L << shift);
PQ_MatrixScale(POWERQUAD,
POWERQUAD_MAKE_MATRIX_LEN(pSrc->numRows, pSrc->numCols, pDst->numCols),
factor,
(void *)pSrc->pData,
(void *)pDst->pData);
PQ_WaitDone(POWERQUAD);
}
Input | Output | Ref |
0 | 0 822272 1636608 2435072 3210240 3954432 4660480 5321728 32767 6484480 | 0 822272 1636608 2435072 3210240 3954432 4660480 5321728 5931520 6484480 |
Hello @Peter19
please refer to SDK example:
static void arm_mat_scale_q31Test(void)
{
uint32_t srcRows, srcColumns; /* Temporary variables */
arm_matrix_instance_q31 scaleMatrix;
arm_matrix_instance_q31 scaleMatrixR;float floatInput;
float floatScaler = 0.5f;
q31_t scaler = FLOAT_2_Q31(floatScaler);
q31_t scale[MATRIX_LEN];
q31_t scaleResult[MATRIX_LEN] = {0};
q31_t scaleRel[MATRIX_LEN] = {0};for (uint32_t i = 0; i < MATRIX_LEN; i++)
{
floatInput = (float)i / (float)MATRIX_LEN;
scale[i] = FLOAT_2_Q31(floatInput);
scaleRel[i] = FLOAT_2_Q31(floatInput * floatScaler);
}/* Initialise Matrix Instance scaleMatrix with numRows, numCols and data array(scale) */
srcRows = MATRIX_ROW;
srcColumns = MATRIX_COL;
arm_mat_init_q31(&scaleMatrix, srcRows, srcColumns, scale);uint32_t oldTime = TEST_GetTime();
for (uint32_t i = 0; i < MATRIX_TEST_LOOP; i++)
{
arm_mat_init_q31(&scaleMatrixR, srcRows, srcColumns, scaleResult);
arm_mat_scale_q31(&scaleMatrix, scaler, 0, &scaleMatrixR);
}PRINTF("%s: %d ms\r\n", __func__, TEST_GetTime() - oldTime);
for (uint32_t i = 0; i < ARRAY_SIZE(scale); i++)
{
EXAMPLE_ASSERT_TRUE(scaleRel[i] == scaleMatrixR.pData[i]);
}
}
BR
Alice
Hi
Please find attached file.
I import frdmmcxn947_powerquad_math example and replace powerquad_cmsis.c with attached file with content inspired from original example.
Place a debug breakpoint after call and check output.
Hello @Peter19
Thanks for your sharing.
I have checked the function of your code. How about replacing the function arm_mat_q15_to_q31_scaled()
with the PowerQuad SDK driver PQ_MatrixScale()
?
/*!
* @brief Processing function for the matrix scale.
*
* @param base POWERQUAD peripheral base address
* @param length rows and cols for matrix. LENGTH register configuration:
* LENGTH[23:16] = M2 cols
* LENGTH[15:8] = M1 cols
* LENGTH[7:0] = M1 rows
* This could be constructed using macro @ref POWERQUAD_MAKE_MATRIX_LEN.
* @param misc scaling parameters
* @param pData input matrix
* @param pResult array for the output data.
*/
void PQ_MatrixScale(POWERQUAD_Type *base, uint32_t length, float misc, const void *pData, void *pResult);
Best Regards,
Alice