L 1 "..\Apps\OP_AmplifiesVoltage.c"
N/********************************************************************************
N * @file    OP_AmplifiesVoltage.c
N * @author  SOC AE Team
N * @version V1.1
N * @date    2025-06-27
N * @brief   配置OP ，反相放大采集后的电压信号至ADC输出
N *         通过宏定义OP_MODE选择OP的同相、反相放大模式：
N *          0：NonInvert_MODE 同相放大 1：Invert_MODE 反相放大
N *******************************************************************************/
N#if defined(SC32f12xx)
X#if 0L
S#include "sc32_conf.h"
S#include "Function_Init.h"
Sstatic volatile FlagStatus ADC_Flag;
Suint8_t offset_flag;
S/* OP 同相反相放大配置 */
S//(OP_MODE:NonInvert_MODE=0,OP_MODE:Invert_MODE=1)
S#define OP_MODE 1
S
Svoid OP_AmplifiesVoltage_Function(void)
S{
S#if defined(SC32f12xx)
S#if (OP_MODE == 0)
S#if defined(SC32f12xx)
S  GPIO_InitTypeDef GPIO_InitStruct; //定义GPIO初始化结构体变量
S  /* PA3设置为高阻输入 */
S  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
S  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_HI;
S  GPIO_Init(GPIOA, &GPIO_InitStruct);
S#endif
S#endif
S#if (OP_MODE == 1)
S#if defined(SC32f12xx)
S  GPIO_InitTypeDef GPIO_InitStruct; //定义GPIO初始化结构体变量
S  /* PA4设置为高阻输入 */
S  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
S  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_HI;
S  GPIO_Init(GPIOA, &GPIO_InitStruct);
S#endif
S#endif
S  //ADC初始化配置
S  volatile uint16_t ADC_Value;
S  RCC_APB2Cmd(ENABLE);                                //ADC、PGA外设挂载在APB2时钟上
S  
S  ADC_InitTypeDef ADC_InitStruct;                     //定义ADC初始化结构体变量
S  
S  ADC_StructInit(&ADC_InitStruct);
S  ADC_InitStruct.ADC_ConvMode = ADC_ConvMode_Single;  //ADC单次转换模式
S  ADC_InitStruct.ADC_Prescaler = ADC_Prescaler_3CLOCK;//转换时间为3个周期
S  ADC_InitStruct.ADC_VREF = ADC_VREF_VDD;             //参考电压为VDD
S  
S  ADC_Init(ADC, &ADC_InitStruct);                     //根据结构体标志位配置ADC
S  ADC_SetChannel(ADC,ADC_Channel_OP);                //选择PGA通道
S  
S  ADC_ITConfig(ADC,ADC_IT_ADCIF,ENABLE);              //使能ADC中断
S  NVIC_EnableIRQ(ADC_IRQn);
S  ADC_Cmd(ADC,ENABLE);	                              //使能ADC；
S  
S #if (OP_MODE == 0)
S  //PGA初始化配置,同相相放大
S  OP_InitTypeDef OP_InitStruct;                      //定义PGA初始化结构体变量
S  OP_InitStruct.OP_ShortCircuit = OP_ShortCircuit_OFF;//PGA同相反相不短接
S  OP_InitStruct.OP_FDBResisrance = OP_FDBResisrance_VSS; //反馈电阻端连接VSS
S  OP_InitStruct.OP_PGAGain = OP_PGAGain_NonInvert8_Invert7;//同相8倍反相7倍增益
S  OP_InitStruct.OP_Posittive = OP_Posittive_OPP0;     //同相端OP_0
S  OP_InitStruct.OP_Negative = OP_Negative_PGA;        //反相端接内部电阻
S  OP_InitStruct.OP_Output = OP_Output_ON;           //连接OP_O输出端口
S
S  OP_Init(OP,&OP_InitStruct);                             //对OP进行初始化
S #endif
S #if (OP_MODE == 1)
S  //PGA初始化配置,反相放大
S  OP_InitTypeDef OP_InitStruct;                            //定义PGA初始化结构体变量
S  OP_InitStruct.OP_ShortCircuit = OP_ShortCircuit_OFF;      //PGA同相反相不短接
S  OP_InitStruct.OP_FDBResisrance = OP_FDBResisrance_OPN;          //反馈电阻端连接OP_N口
S  OP_InitStruct.OP_PGAGain = OP_PGAGain_NonInvert8_Invert7; //同相8倍反相7倍增益
S#if defined(SC32f12xx)
S  OP_InitStruct.OP_Posittive = OP_Posittive_VSS;            //同相端接地
S#endif
S  OP_InitStruct.OP_Negative = OP_Negative_PGA;             //反相端接内部电阻
S  OP_InitStruct.OP_Output = OP_Output_ON;           //连接OP_O输出端口
S  
S  OP_Init(OP,&OP_InitStruct);                        //对OP进行初始化
S#endif
S  OP_Cmd(OP,ENABLE);                                 //OP使能
S  
S  while(1)
S  {
S		if(offset_flag==0)
S		{
S			printf("\r\n OP的校验值写入出厂设置成功 \r\n");
S		}
S		else
S		{
S				printf("\r\n OP的校验值写入出厂设置失败 \r\n");
S		}
S    ADC_SoftwareStartConv(ADC); //开启转换
S    while(ADC_Flag == RESET); //等待ADC转换完成
S    ADC_Value = ADC_GetConversionValue(ADC);  //获取ADC转换值
S    printf("\r\n ADC Conversion Value is 0x%x \r\n",ADC_Value);
S    for (int i=0;i<5000;i++);
S  }
S  
S
S#endif
S}
S#if defined(SC32f12xx)
Svoid OP_AmplifiesVoltage_ADCHandler(void)
S{
S  if(ADC_GetFlagStatus(ADC,ADC_Flag_ADCIF)) //判断ADC标志位
S  {
S    ADC_ClearFlag(ADC,ADC_Flag_ADCIF);  //清除ADC标志位
S    ADC_Flag = SET;  //自定义标志置起
S  }
S}
S#endif
N#endif
