1. Configure Clock And DAC
Note up clock to 216 Mhz in clock configuration
2.Generation Source and edit code
In Src/main.c
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DAC_Init();
HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
HAL_DAC_Start(&hdac, DAC_CHANNEL_2);
float i=0.0;
while (1)
{
i+=1;
if(i>2047){
i=0;
}
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R,(int)(2048*(1+sin(i/4095*4*3.14))));
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R,(int)i*2);
HAL_Delay(1);
}
}
Note up clock to 216 Mhz in clock configuration
2.Generation Source and edit code
In Src/main.c
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_DAC_Init();
HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
HAL_DAC_Start(&hdac, DAC_CHANNEL_2);
float i=0.0;
while (1)
{
i+=1;
if(i>2047){
i=0;
}
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R,(int)(2048*(1+sin(i/4095*4*3.14))));
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_R,(int)i*2);
HAL_Delay(1);
}
}
abc
Trả lờiXóa