电子设计大赛预选阶段,请大神帮忙解释代码意思

u010483640 2013-04-27 06:52:41
由于第一次接触这些东西,不懂的太多,烦请大神帮忙,告诉我这些程序是如何实现调波的,万谢!!!!!





#define SPEAKER_DAC DACB
#define SPEAKER_DAC_CHANNEL DAC_CH0
#define RATE_OF_CONVERSION 22050
#define NR_OF_SAMPLES 32

static const uint16_t sine[NR_OF_SAMPLES] = {
32768, 35325, 37784, 40050, 42036, 43666, 44877, 45623,//正弦波
45875, 45623, 44877, 43666, 42036, 40050, 37784, 35325,
32768, 30211, 27752, 25486, 23500, 21870, 20659, 19913,
19661, 19913, 20659, 21870, 23500, 25486, 27752, 30211,
};
/*
0, 4096, 8192, 12287, 16384, 20480, 24576, 28672,
32768, 36864, 40960, 45056, 49151, 53248, 57343, 61440,三角波
65535, 61440, 57343, 53248, 49151, 45056, 40960, 36864,
32768, 28672, 24576, 20480, 16384, 12287, 8192, 4096,
*/

static void evsys_init(void)
{
sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_EVSYS);
EVSYS.CH3MUX = EVSYS_CHMUX_TCC0_OVF_gc;
}


void tc_init(void)
{
tc_enable(&TCC0);
tc_set_wgm(&TCC0, TC_WG_NORMAL);
tc_write_period(&TCC0, (sysclk_get_per_hz() / RATE_OF_CONVERSION) - 1);
tc_write_clock_source(&TCC0, TC_CLKSEL_DIV1_gc);
}


void dac_init(void)
{
struct dac_config conf;

dac_read_configuration(&SPEAKER_DAC, &conf);
dac_set_conversion_parameters(&conf, DAC_REF_BANDGAP, DAC_ADJ_LEFT);
dac_set_active_channel(&conf, SPEAKER_DAC_CHANNEL, 0);
dac_set_conversion_trigger(&conf, SPEAKER_DAC_CHANNEL, 3);
#ifdef XMEGA_DAC_VERSION_1
dac_set_conversion_interval(&conf, 1);
#endif
dac_write_configuration(&SPEAKER_DAC, &conf);
dac_enable(&SPEAKER_DAC);
}

int main (void)
{
board_init();
sysclk_init();
evsys_init();
tc_init();
dac_init();
uint8_t i = 0;
while (1)
{

dac_wait_for_channel_ready(&SPEAKER_DAC, SPEAKER_DAC_CHANNEL);
dac_set_channel_value(&SPEAKER_DAC, SPEAKER_DAC_CHANNEL, sine[i]);

i++;
i %= NR_OF_SAMPLES;

}

}


...全文
85 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧