2017年5月26日 星期五

NANO100: MCU Sine wave generator - using MCU DAC(Look up table with adjustable amplitude)

1.Generate sample point use octave.

x = 0 : pi/64 : 2*pi;
y = 0.5*(sin(x)+1);
plot(y);
view raw gistfile1.txt hosted with ❤ by GitHub
2.Create look up table.use const to store look up table in ROM for less latency.

#define SINE_LUT_SIZE (127)
const float sine_lut[SINE_LUT_SIZE] =
{
0.500, 0.524, 0.549, 0.573, 0.597, 0.621, 0.645 ,0.664 ,0.694 ,0.718 ,0.730 ,0.755 ,0.779 ,0.795 ,0.810,
0.835, 0.853, 0.870 ,0.881 ,0.900, 0.915, 0.928, 0.940, 0.951, 0.961, 0.970, 0.978, 0.985, 0.990, 0.994,
0.997, 0.999, 1.000, 0.999, 0.997, 0.994, 0.990, 0.985, 0.978, 0.970, 0.961, 0.951, 0.940, 0.928, 0.915,
0.901, 0.886, 0.870, 0.853, 0.835, 0.817, 0.797, 0.777, 0.757, 0.735, 0.713, 0.691, 0.668, 0.645, 0.621,
0.597, 0.573, 0.549, 0.524, 0.500, 0.475, 0.450, 0.426, 0.402, 0.378, 0.354, 0.331, 0.308, 0.286, 0.264,
0.242, 0.222, 0.202, 0.182, 0.164, 0.146, 0.129, 0.113, 0.098, 0.084, 0.071, 0.059, 0.048, 0.038, 0.029,
0.021, 0.014, 0.009, 0.005, 0.002, 0.000, 0.000, 0.000, 0.002, 0.005, 0.009, 0.014, 0.021, 0.029, 0.038,
0.048, 0.059, 0.071, 0.084, 0.098, 0.113, 0.129, 0.146, 0.164, 0.182, 0.202, 0.222, 0.242, 0.264, 0.286,
0.308, 0.331, 0.354, 0.378, 0.402, 0.426, 0.450
};
view raw gistfile1.txt hosted with ❤ by GitHub
3.Scale to real data function (for 12 bits DAC the max value is 4096)

#define AMPLITUDE (4000.0)
#define SINE_SCALE(x) (AMPLITUDE*(x))
uint32_t index0 = 0;
DAC_WRITE_DATA(DAC, 0, SINE_SCALE(sine_lut[index0]));
view raw gistfile1.txt hosted with ❤ by GitHub

2017年5月11日 星期四

nrf52 : Add CMSIS_DSP package in Keil 5

1.Open Manage Run-Time Environment and check the DSP














2.Include arm_math.h
  and  path in your project:Keil_v5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include

3.Add symbol ARM_MATH_CM4 since nrf52832 use Cortex M4F






4.Simple matrix multiplication code

const q31_t A[9] =
{
3, 3, 3,
3, 3, 3,
3, 3, 3
};
const q31_t X[9] =
{
1, 0, 0,
0, 1, 0,
0, 0, 1,
};
const q31_t Y[9] =
{
0, 0, 0,
0, 0, 0,
0, 0, 0,
};
int main(void)
{
arm_matrix_instance_q31 A_F;
arm_matrix_instance_q31 X_F;
arm_matrix_instance_q31 Y_F;
arm_status status;
uint32_t srcRows = 3,srcColumns = 3;
arm_mat_init_q31(&A_F, srcRows, srcColumns, (q31_t *)A);
arm_mat_init_q31(&X_F, srcRows, srcColumns, (q31_t *)X);
arm_mat_init_q31(&Y_F, srcRows, srcColumns, (q31_t *)Y);
status = arm_mat_mult_q31(&A_F, &X_F, &Y_F);
while(status != ARM_MATH_SUCCESS);
}
view raw gistfile1.txt hosted with ❤ by GitHub
Ref:
    1. CMSIS DSP Software Library







Linux driver: How to enable dynamic debug at booting time for built-in driver.

 Dynamic debug is useful for debug driver, and can be enable by: 1. Mount debug fs #>mount -t debugfs none /sys/kernel/debug 2. Enable dy...