简介
运算放大器(OPA)在电机控制中有在非常重要的作用,APMF035C8T7内置最多 4 个可独立使用的 OPA,它们也可以和 COMP、ADC 结合使用。放大器输出可作为 ADC 转换模块的输入。
主要特征
①运算放大器的输入输出端都开放,可通过外界电阻调整运放增益,也可以通过设置选择内部预设的增益档位。
②放大器输出可作为 ADC 转换模块的输入。
结构框图
内部增益应用示意图
外部增益应用示意图
以下是APMF035C8T7-OPA内部增益应用相关配置:
void OPA_Init(void)
{
GPIO_Config_T gpioConfigStruct;
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_SYSCFG);
RCM_EnableAHBPeriphClock(RCM_AHB_PERIPH_GPIOA | RCM_AHB_PERIPH_GPIOB);
/* OPA GPIO configuration */
gpioConfigStruct.pin = GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_15;
gpioConfigStruct.mode = GPIO_MODE_AN;
gpioConfigStruct.outtype = GPIO_OUT_TYPE_PP;
gpioConfigStruct.speed = GPIO_SPEED_50MHz;
gpioConfigStruct.pupd = GPIO_PUPD_NO;
GPIO_Config(GPIOA, &gpioConfigStruct);
gpioConfigStruct.pin = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_0 | GPIO_PIN_10;
GPIO_Config(GPIOB, &gpioConfigStruct);
/* OPA gain configuration */
/* External resistor network */
OPA_SelectGainFactor(OPA1, OPA_GAIN_FACTOR_0);
/* Internal gain */
OPA_SelectGainFactor(OPA2, OPA_GAIN_FACTOR_2);
/* Enable OPA */
OPA_Enable(OPA1);
OPA_Enable(OPA2);
}
void ADC_Init(void)
{
GPIO_Config_T gpioConfig;
ADC_Config_T adcConfig;
/* RCM Enable*/
RCM_EnableAHBPeriphClock(RCM_AHB_PERIPH_GPIOA);
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_ADC);
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_SYSCFG);
/* GPIO Configuration */
gpioConfig.pin = GPIO_PIN_4;
gpioConfig.mode = GPIO_MODE_AN;
gpioConfig.pupd = GPIO_PUPD_PU;
GPIO_Config(GPIOA, &gpioConfig);
/* ADC Configuration */
ADC_Reset();
ADC_ConfigStructInit(&adcConfig);
/* Set resolution*/
adcConfig.resolution = ADC_RESOLUTION_12B;
/* Set dataAlign*/
adcConfig.dataAlign = ADC_DATA_ALIGN_RIGHT;
/* Set scanDir*/
adcConfig.scanDir = ADC_SCAN_DIR_UPWARD;
/* Set convMode continous*/
adcConfig.convMode = ADC_CONVERSION_CONTINUOUS;
/* Set extTrigConv*/
adcConfig.extTrigConv1 = ADC_EXT_TRIG_CONV_TRG0;
/* Set TrigEdge*/
adcConfig.extTrigEdge1 = ADC_EXT_TRIG_EDGE_NONE;
ADC_Config(&adcConfig);
ADC_ConfigChannel(ADC_CHANNEL_2, ADC_SAMPLE_TIME_239_5);
/* Enable Interrupt*/
ADC_EnableInterrupt(ADC_INT_CS);
NVIC_EnableIRQRequest(ADC_COMP_IRQn, 2);
/* Calibration*/
ADC_ReadCalibrationFactor();
/* Enable ADC*/
ADC_Enable();
}
void ADC_Isr(void)
{
uint32_t adcData = 0;
uint32_t voltage = 0;
if (ADC_ReadIntFlag(ADC_INT_FLAG_CS) == SET)
{
ADC_ClearIntFlag(ADC_INT_FLAG_CS);
/* Read ADC Conversion value */
adcData = ADC_ReadConversionValue();
/* voltage(mV) = adcData * (3300mV / 4095) */
voltage = (adcData * 3300) / 4095;
/* output to serial port */
printf("OPA2 output voltage : %d mV\r\n", voltage);
}
APM_MINI_LEDToggle(LED2);
APM_MINI_DelayMs(500);
}
|