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

沒有留言:

張貼留言

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...