freetech

kinetis入门之——DAC

0
阅读(2511)

kinetis内置了12位DAC,可实现DA转换。下面详述具体步骤:

1、点“文件->新建->bareboard project”出现下面对话框:

image

为工程起个名字(该示例为k10_dac_pe),点“下一步”,出现:

clip_image003

选择你所用的芯片型号(这里是pk10x256)即可。点“下一步”,出现:

clip_image005

“Connetion to be used”中先选我们先前建好的“USBDM K10X256”,点“下一步”,一直点“下一步”直到出现:

clip_image007

选“Processor Export”,点“下一步”,出现:

clip_image009

选实际用到的芯片(我用的是144-pins LQFP),点“完成”,出现:

clip_image011

等待上面对话框消失,一个工程就建好了。

双击“Converter”下的“DAC_LDD”添加一个“DAC Bean”,如下图:

image

配置如下图:

image

点“项目”->“Generate Processor Export Code”如下图:

image

下面是“ProcessorExpert.c”的“main()”函数代码:

void main(void)
{
  /* Write your local variable definition here */
  LDD_TError Error;
  LDD_TDeviceData *MyDacPtr;
  LDD_DAC_TData datda;
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
  MyDacPtr = DA1_Init(NULL);
  datda= 3000;
  /* Initialization of DA1 component */
  Error = DA1_SetValue(MyDacPtr, datda);                    /* Set converter output */
  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

至此,代码就写完了。按以前的方法调试即可。用万用表电压档测DAC1的输出。