AnsweredAssumed Answered

mk22fx512 dac config

Question asked by daixu hao on Mar 3, 2020
Latest reply on Mar 10, 2020 by Robin_Shen

MK22FX512 DAC Configuration,hardware I select pin27 as DAC0 output pin,the programme as follow,but I can't get the voltage from pin 27 when I use function DAC_SetValue(4000).I don't konw why?

 

void DAC_Configuration(void)
{
SIM_SCGC2 |= SIM_SCGC2_DAC0_MASK;//12位为1,DAC0时钟使能
DAC0_SR |=(DAC_SR_DACBFWMF_MASK|DAC_SR_DACBFRPTF_MASK|DAC_SR_DACBFRPBF_MASK);
DAC0_C1 |=DAC_C1_DACBFEN_MASK;//启用DAC buffer
DAC0_C2 |=DAC_C2_DACBFUP_MASK;
DAC0_C0 |=DAC_C0_DACTRGSEL_MASK;//软件触发有效
DAC0_C0 |=DAC_C0_DACSWTRG_MASK;//选择软件触发模式
DAC0_C0 |=DAC_C0_LPEN_MASK;//低功率控制
DAC0_C0 |=DAC_C0_DACRFS_MASK;//选择VDDA-3.3V作为DAC的参考电压
DAC0_C0 |=DAC_C0_DACEN_MASK;//DAC0使能
}
void DAC_SetValue(uint16_t Value)
{
DAC0_DAT0L=(uint8_t)(Value&0x0001);
DAC0_DAT1L=(uint8_t)((Value&0x0002)>>1);
DAC0_DAT2L=(uint8_t)((Value&0x0004)>>2);
DAC0_DAT3L=(uint8_t)((Value&0x0008)>>3);
DAC0_DAT4L=(uint8_t)((Value&0x0010)>>4);
DAC0_DAT5L=(uint8_t)((Value&0x0020)>>5);
DAC0_DAT6L=(uint8_t)((Value&0x0040)>>6);
DAC0_DAT7L=(uint8_t)((Value&0x0080)>>7);
DAC0_DAT0H=(uint8_t)((Value&0x0100)>>8);
DAC0_DAT1H=(uint8_t)((Value&0x0200)>>9);
DAC0_DAT2H=(uint8_t)((Value&0x0400)>>10);
DAC0_DAT3H=(uint8_t)((Value&0x0800)>>11);
}

Outcomes