本篇测评使用板载的ADC和DAC进行功能验证。
FM33LG0有最高采样率达到2Msps的12bit ADC,支持单端输入、差分输入,可以选择VREFP和VDDA作为REF+参考电压,非常的灵活;
1、先上原理图,看一下MCU的ADC /DAC在哪个IO口上。
ADC的接口接在MCU的58 57 56,分别是ADC 17 ADC16 ADC15通道上。
DCA是接在51脚上,PC5。
再来一个NTC与15通道接个NTC。
请忽略一下细节,画图软件死掉了,没软件画,在百度里改的一个图片将就用一下。
2、实物连接图:
各线连接
NTC
3、代码:
ADC:
FL_GPIO_InitTypeDef GPIO_InitStruct;
FL_ADC_CommonInitTypeDef ADC_CommonInitStruct;
FL_ADC_InitTypeDef ADC_InitStruct ;
FL_GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.pin = FL_GPIO_PIN_10 | FL_GPIO_PIN_11 | FL_GPIO_PIN_12;
GPIO_InitStruct.mode = FL_GPIO_MODE_ANALOG;
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
FL_GPIO_Init(GPIOC, &GPIO_InitStruct);
FL_ADC_CommonStructInit(&ADC_CommonInitStruct);
ADC_CommonInitStruct.operationSource = FL_ADC_CLK_SOURCE_ADCCLK;
ADC_CommonInitStruct.clockSource = FL_CMU_ADC_CLK_SOURCE_RCHF;
ADC_CommonInitStruct.clockPrescaler = FL_CMU_ADC_PSC_DIV8;
ADC_CommonInitStruct.APBClockPrescaler = FL_ADC_APBCLK_PSC_DIV1;
ADC_CommonInitStruct.referenceSource = FL_ADC_REF_SOURCE_VDDA;
ADC_CommonInitStruct.bitWidth = FL_ADC_BIT_WIDTH_12B;
FL_ADC_CommonInit(&ADC_CommonInitStruct);
FL_ADC_StructInit(&ADC_InitStruct);
ADC_InitStruct.conversionMode = FL_ADC_CONV_MODE_SINGLE;
ADC_InitStruct.autoMode = FL_ADC_SINGLE_CONV_MODE_AUTO;
ADC_InitStruct.waitMode = FL_ENABLE;
ADC_InitStruct.overrunMode = FL_ENABLE;
ADC_InitStruct.scanDirection = FL_ADC_SEQ_SCAN_DIR_FORWARD;
ADC_InitStruct.externalTrigConv = FL_ADC_TRIGGER_EDGE_NONE;
ADC_InitStruct.triggerSource = FL_ADC_TRGI_LUT0;
ADC_InitStruct.fastChannelTime = FL_ADC_FAST_CH_SAMPLING_TIME_2_ADCCLK;
ADC_InitStruct.lowChannelTime = FL_ADC_SLOW_CH_SAMPLING_TIME_192_ADCCLK;
ADC_InitStruct.oversamplingMode = FL_ENABLE;
ADC_InitStruct.overSampingMultiplier = FL_ADC_OVERSAMPLING_MUL_8X;
ADC_InitStruct.oversamplingShift = FL_ADC_OVERSAMPLING_SHIFT_3B;
FL_ADC_Init(ADC, &ADC_InitStruct);
TASK_Append(TASK_ID_ADC, ADC_Handler, 500);
uint16_t Data = 0;
FL_CMU_SetADCPrescaler(FL_CMU_ADC_PSC_DIV1)
FL_ADC_EnableSequencerChannel(ADC, Channel)
FL_ADC_ClearFlag_EndOfConversion(ADC)
FL_ADC_Enable(ADC)
FL_ADC_EnableSWConversion(ADC)
while(FL_ADC_IsActiveFlag_EndOfConversion(ADC) == FL_RESET)
FL_ADC_ClearFlag_EndOfConversion(ADC)
Data = FL_ADC_ReadConversionData(ADC)
FL_ADC_Disable(ADC)
FL_ADC_DisableSequencerChannel(ADC, Channel)
return Data
uint32_t CH15_Data = 0,;
CH15_Data = ADC_GetSingleChannelSample(FL_ADC_EXTERNAL_CH15);
printf("\r\nCH15采样中 : %0.1fV, ",(float)CH15_Data / 4095 * 3.3);
DAC:
FL_GPIO_InitTypeDef GPIO_InitStruct;
FL_DAC_InitTypeDef DAC_InitStruct;
FL_GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.pin = FL_GPIO_PIN_5;
GPIO_InitStruct.mode = FL_GPIO_MODE_ANALOG;
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
FL_GPIO_Init(GPIOC, &GPIO_InitStruct);
FL_DAC_StructInit(&DAC_InitStruct);
DAC_InitStruct.sampleHoldMode = FL_DISABLE;
DAC_InitStruct.sampleTime = 0xFF;
DAC_InitStruct.holdTime = 0x00;
DAC_InitStruct.triggerMode = FL_DISABLE;
DAC_InitStruct.triggerSource = FL_DAC_TRGI_SOFTWARE;
DAC_InitStruct.bufferMode = FL_DISABLE;
DAC_InitStruct.switchMode = FL_ENABLE;
FL_DAC_Init(DAC, &DAC_InitStruct);
FL_DAC_Enable(DAC);
FL_DAC_WriteData(DAC, 2047);
TASK_Append(TASK_ID_DAC, DAC_Handler, 1);
uint16_t WaveData[1284] =
{
2047,2147,2248,2347,2446,2545,2641,2737,2831,2922,
3012,3100,3185,3267,3346,3422,3495,3564,3630,3692,
3749,3803,3853,3898,3939,3975,4006,4033,4055,4072,
4085,4092,4095,4092,4085,4072,4055,4033,4006,3975,
3939,3898,3853,3803,3749,3692,3630,3564,3495,3422,
3346,3267,3185,3100,3012,2922,2831,2737,2641,2545,
2446,2347,2248,2147,2047,1947,1846,1747,1648,1549,
1453,1357,1263,1172,1082, 994, 909, 827, 748, 672,
599, 530, 464, 402, 345, 291, 241, 196, 155, 119,
88, 61, 39, 22, 9, 2, 0, 2, 9, 22,
39, 61, 88, 119, 155, 196, 241, 291, 345, 402,
464, 530, 599, 672, 748, 827, 909, 994,1082,1172,
1263,1357,1453,1549,1648,1747,1846,1947
};
static uint8_t WaveIndex = 0;
FL_DAC_WriteData(DAC, WaveData[WaveIndex]);
WaveIndex = (WaveIndex + 1) % 128;
4、实现串口输出的电压:
DAC结果:
输出波形: