【N32L43x评测】OPAMP内部运算放大器使用
[复制链接]
内部运放功能,这个功能我感觉在采集热电偶那种微弱信号的时候比较有用,可以进行放大,本次的N32L436上就有,而且可以调节增益倍数,可以说比较方便了。下面我看下我们测试。
从上两幅图我们大致可以看到内部运放连接到了什么口上,还有一些什么样的特性。本次正好两个口连接到了ADC口上,我们可以直接接上电,然后用内部ADC采集下。
我是先移植了ADC的功能。如下:
- #include "adc.h"
-
-
-
-
-
-
-
-
-
- void ADC_Initial(void)
-
- {
-
-
-
- ADC_InitType ADC_InitStructure;
-
-
-
-
-
- GPIO_InitType GPIO_InitStructure;
-
-
-
-
-
-
-
-
-
- RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
-
-
-
- RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_ADC, ENABLE);
-
-
-
-
-
- ADC_ConfigClk(ADC_CTRL3_CKMOD_AHB, RCC_ADCHCLK_DIV16);
-
- RCC_ConfigAdc1mClk(RCC_ADC1MCLK_SRC_HSE, RCC_ADC1MCLK_DIV8);
-
-
-
- GPIO_InitStruct(&GPIO_InitStructure);
-
-
-
- GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_6;
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Analog;
-
- GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
-
-
-
-
-
- ADC_InitStructure.MultiChEn = DISABLE;
-
- ADC_InitStructure.ContinueConvEn = DISABLE;
-
- ADC_InitStructure.ExtTrigSelect = ADC_EXT_TRIGCONV_NONE;
-
- ADC_InitStructure.DatAlign = ADC_DAT_ALIGN_R;
-
- ADC_InitStructure.ChsNumber = 1;
-
- ADC_Init(ADC, &ADC_InitStructure);
-
-
-
-
-
- ADC_Enable(ADC, ENABLE);
-
-
-
- while(ADC_GetFlagStatusNew(ADC,ADC_FLAG_RDY) == RESET)
-
- ;
-
-
-
- ADC_StartCalibration(ADC);
-
-
-
- while (ADC_GetCalibrationStatus(ADC))
-
- ;
-
- }
-
-
-
-
-
- uint16_t ADC_GetData(uint8_t ADC_Channel)
-
- {
-
- uint16_t dat;
-
- ADC_ConfigRegularChannel(ADC, ADC_Channel, 1, ADC_SAMP_TIME_55CYCLES5);
-
-
-
- ADC_EnableSoftwareStartConv(ADC,ENABLE);
-
- while(ADC_GetFlagStatus(ADC,ADC_FLAG_ENDC)==0){
-
- }
-
- ADC_ClearFlag(ADC,ADC_FLAG_ENDC);
-
- ADC_ClearFlag(ADC,ADC_FLAG_STR);
-
- dat=ADC_GetDat(ADC);
-
- return dat;
-
- }
然后仿真就能看结果。接到地ADC数值基本不动。
- #include "opamp.h"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- void OPAMP_Configuration(void)
-
- {
-
-
-
- RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_COMP | RCC_APB1_PERIPH_OPAMP | RCC_APB1_PERIPH_COMP_FILT, ENABLE);
-
- RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | RCC_APB2_PERIPH_GPIOA | RCC_APB2_PERIPH_GPIOB | RCC_APB2_PERIPH_GPIOC
-
- | RCC_APB2_PERIPH_GPIOD , ENABLE);
-
-
-
-
-
- GPIO_InitType GPIO_InitStructure;
-
-
-
-
-
- OPAMP_InitType OPAMP_Initial;
-
-
-
- GPIO_InitStruct(&GPIO_InitStructure);
-
-
-
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Analog;
-
- GPIO_InitStructure.GPIO_Current = GPIO_DC_4mA;
-
- GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_7;
-
- GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
-
-
-
-
-
-
-
-
- GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_6;
-
- GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);
-
-
-
-
-
- OPAMP_StructInit(&OPAMP_Initial);
-
- OPAMP_Initial.Gain = OPAMP_CS_PGA_GAIN_4;
-
-
-
- OPAMP_Init(OPAMP1, &OPAMP_Initial);
-
- OPAMP_SetVpSel(OPAMP1, OPAMP1_CS_VPSEL_PA1);
-
- OPAMP_Enable(OPAMP1, ENABLE);
-
-
-
- OPAMP_Init(OPAMP2, &OPAMP_Initial);
-
- OPAMP_SetVpSel(OPAMP2, OPAMP2_CS_VPSEL_PA7);
-
- OPAMP_Enable(OPAMP2, ENABLE);
-
-
-
-
-
- }
然后弄了下运算放大器,一切都是按照其demo来的,我试了改增益,不改输入,ADC输出就变了,同理采集的电压也基本是增益倍数。不过有些跳动。
- adc_val[0] = (ADCConvertedValue[0]*3.3)/4096;
-
- adc_val[1] = (ADCConvertedValue[1]*3.3)/4096;
中间我直接增加了一个电压值转换。如果使用后期应该需要进行滤波处理,让ADC数值稳定一些。
|