[STM32U5]【NUCLEO-U575ZI-Q测评】+ 逆变器逐波限流

2024-01-25 07:30

本文主要是介绍[STM32U5]【NUCLEO-U575ZI-Q测评】+ 逆变器逐波限流,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

传统的逆变器一般是用互感器或者电阻采样电流进行峰值电流限制,其中外围需要用到运放及比较器,外围还有电阻分压进行阀值设定,还需设计迟滞电压部分电路,软件通过IO引脚进行边沿跳变或者电平检测,从而判断功率管过流,从而关断功率管驱动信号。而目前芯片自带比较器,DAC,Break功能大大的简化外围设计,而且能通过上位机软件配置阀值参数,方便生产过程参数偏差导致的限流点不一致问题。此次主要使用自带的比较器COMP1、COMP2组成窗口比较器,DAC输出给到COM1和COM2的负端输入,实现上下阀值带迟滞限制;COM1、COM2正端输入为电流采样信号,两个比较器进行比较异或输出,送入Break脚实现刹车关闭PWM驱动功能。PWM自带自恢复功能,实现每个驱动周限流。高级定时器TIM1实现2对4CH, 20KHz 820ns死区互补SPWM输出,此次测试限于示波器通道支持互补的一对驱动,上下端限压1.3V,使用2个10KΩ电阻分压接入两个比较器正端模拟电流信号。连接如下:
  
PA2作为COMP1、COMP2正端输入,PE9、PA7 (TIM1_CH1,TIM1_CH1N),PE11、PB0(TIM1_CH2,TIM1_CH2N)作为两对互补输出引脚;
如下是STM32CubeMx配置COMP1、COMP2,软件可配置迟滞,大大减少电路开销;




比较器负端输入使用DAC的两路输出,方便设置限流阀值点,配置如下:

SPWM驱动采用高级定时器带死区控制及刹车功能,中央对齐模式,配置如下:


测试SPWM驱动及刹车功能。
1.SPWM驱动波形(PA2 = 1.65V):


2.死区时间设置820ns  130/160=812.5ns,与设置相符


3.IO引脚PA2(CH3)分别为1.65V、0V,3.3V来回切换,从下面波形可以看出,当比较器正端输入为0V和3.3V时,超出了配置阀值,SPWM(CH1 CH4) 立即关闭输出,当恢复到1.65V,SPWM自动恢复输出:


代码如下,注意SPWM切换相位及中断是25us一次需要使用溢出中断时判断向上计数对比较寄存器进行赋值,仅供参考:

/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include  <stdio.h>
#include  <string.h>
#include  <ctype.h>
#include  <stdlib.h>
#include  <stdarg.h>   
#include  <math.h>
/* USER CODE END Includes *//* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
#define HalInvPwmEn()                                TIM1->CCER |= 0x55        
#define HalInvPwmDis()                                TIM1->CCER &= ~0x55               #define HalInvPwmAoeEn()                        TIM1->BDTR |= (1 << 14);        
#define HalInvPwmAoeDis()                        TIM1->BDTR &= ~(1 << 14);#define HalInvPwmMoeEn()                        TIM1->BDTR |= (1 << 15);        
#define HalInvPwmMoeDis()                        TIM1->BDTR &= ~(1 << 15);
/* USER CODE END PTD *//* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD *//* USER CODE END PD *//* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM *//* USER CODE END PM *//* Private variables ---------------------------------------------------------*/
COMP_HandleTypeDef hcomp1;
COMP_HandleTypeDef hcomp2;DAC_HandleTypeDef hdac1;TIM_HandleTypeDef htim1;/* USER CODE BEGIN PV *//* USER CODE END PV *//* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void SystemPower_Config(void);
static void MX_GPIO_Init(void);
static void MX_ICACHE_Init(void);
static void MX_COMP1_Init(void);
static void MX_COMP2_Init(void);
static void MX_DAC1_Init(void);
static void MX_TIM1_Init(void);
/* USER CODE BEGIN PFP *//* USER CODE END PFP *//* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 *//* USER CODE END 0 *//*** @brief  The application entry point.* @retval int*/
int main(void)
{/* USER CODE BEGIN 1 *//* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* Configure the System Power */SystemPower_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_ICACHE_Init();MX_COMP1_Init();MX_COMP2_Init();MX_DAC1_Init();MX_TIM1_Init();/* USER CODE BEGIN 2 */HAL_DAC_SetValue(&hdac1,DAC_CHANNEL_1,DAC_ALIGN_12B_R,(uint32_t)4096*(1650+1300)/3300);         HAL_DAC_SetValue(&hdac1,DAC_CHANNEL_2,DAC_ALIGN_12B_R,(uint32_t)4096*(1650-1300)/3300);HAL_DAC_Start(&hdac1,DAC_CHANNEL_1);HAL_DAC_Start(&hdac1,DAC_CHANNEL_2);HAL_COMP_Start(&hcomp1);HAL_COMP_Start(&hcomp2);         HalInvPwmEn();HalInvPwmAoeEn();                        //¿ªÆôSPWM__HAL_TIM_CLEAR_FLAG(&htim1,TIM_FLAG_UPDATE);__HAL_TIM_ENABLE_IT(&htim1,TIM_FLAG_UPDATE);   __HAL_TIM_ENABLE(&htim1);/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 *///HAL_DAC_SetValue(&hdac1,DAC_CHANNEL_1,DAC_ALIGN_12B_R,(uint32_t)4096*(1650+1300)/3300);         //HAL_DAC_SetValue(&hdac1,DAC_CHANNEL_2,DAC_ALIGN_12B_R,(uint32_t)4096*(1650-1300)/3300);           }/* USER CODE END 3 */
}/*** @brief System Clock Configuration* @retval None*/
void SystemClock_Config(void)
{RCC_OscInitTypeDef RCC_OscInitStruct = {0};RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};/** Configure the main internal regulator output voltage*/if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK){Error_Handler();}/** Initializes the CPU, AHB and APB buses clocks*/RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_MSI;RCC_OscInitStruct.HSIState = RCC_HSI_ON;RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;RCC_OscInitStruct.LSIState = RCC_LSI_ON;RCC_OscInitStruct.MSIState = RCC_MSI_ON;RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_4;RCC_OscInitStruct.LSIDiv = RCC_LSI_DIV1;RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;RCC_OscInitStruct.PLL.PLLM = 1;RCC_OscInitStruct.PLL.PLLN = 80;RCC_OscInitStruct.PLL.PLLP = 2;RCC_OscInitStruct.PLL.PLLQ = 2;RCC_OscInitStruct.PLL.PLLR = 2;RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_0;RCC_OscInitStruct.PLL.PLLFRACN = 0;if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK){Error_Handler();}/** Initializes the CPU, AHB and APB buses clocks*/RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2|RCC_CLOCKTYPE_PCLK3;RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK){Error_Handler();}
}/*** @brief Power Configuration* @retval None*/
static void SystemPower_Config(void)
{/** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral*/HAL_PWREx_DisableUCPDDeadBattery();/** Switch to SMPS regulator instead of LDO*/if (HAL_PWREx_ConfigSupply(PWR_SMPS_SUPPLY) != HAL_OK){Error_Handler();}
/* USER CODE BEGIN PWR */
/* USER CODE END PWR */
}/*** @brief COMP1 Initialization Function* @param None* @retval None*/
static void MX_COMP1_Init(void)
{/* USER CODE BEGIN COMP1_Init 0 *//* USER CODE END COMP1_Init 0 *//* USER CODE BEGIN COMP1_Init 1 *//* USER CODE END COMP1_Init 1 */hcomp1.Instance = COMP1;hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO3;hcomp1.Init.InputMinus = COMP_INPUT_MINUS_DAC1_CH1;hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;hcomp1.Init.WindowOutput = COMP_WINDOWOUTPUT_EACH_COMP;hcomp1.Init.Hysteresis = COMP_HYSTERESIS_HIGH;hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;hcomp1.Init.Mode = COMP_POWERMODE_HIGHSPEED;hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE;hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_NONE;if (HAL_COMP_Init(&hcomp1) != HAL_OK){Error_Handler();}/* USER CODE BEGIN COMP1_Init 2 *//* USER CODE END COMP1_Init 2 */}/*** @brief COMP2 Initialization Function* @param None* @retval None*/
static void MX_COMP2_Init(void)
{/* USER CODE BEGIN COMP2_Init 0 *//* USER CODE END COMP2_Init 0 *//* USER CODE BEGIN COMP2_Init 1 *//* USER CODE END COMP2_Init 1 */hcomp2.Instance = COMP2;hcomp2.Init.InputPlus = COMP_INPUT_PLUS_IO1;hcomp2.Init.InputMinus = COMP_INPUT_MINUS_DAC1_CH2;hcomp2.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;hcomp2.Init.WindowOutput = COMP_WINDOWOUTPUT_COMP2;hcomp2.Init.Hysteresis = COMP_HYSTERESIS_HIGH;hcomp2.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;hcomp2.Init.Mode = COMP_POWERMODE_HIGHSPEED;hcomp2.Init.WindowMode = COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON;hcomp2.Init.TriggerMode = COMP_TRIGGERMODE_NONE;if (HAL_COMP_Init(&hcomp2) != HAL_OK){Error_Handler();}/* USER CODE BEGIN COMP2_Init 2 *//* USER CODE END COMP2_Init 2 */}/*** @brief DAC1 Initialization Function* @param None* @retval None*/
static void MX_DAC1_Init(void)
{/* USER CODE BEGIN DAC1_Init 0 *//* USER CODE END DAC1_Init 0 */DAC_ChannelConfTypeDef sConfig = {0};DAC_AutonomousModeConfTypeDef sAutonomousMode = {0};/* USER CODE BEGIN DAC1_Init 1 *//* USER CODE END DAC1_Init 1 *//** DAC Initialization*/hdac1.Instance = DAC1;if (HAL_DAC_Init(&hdac1) != HAL_OK){Error_Handler();}/** DAC channel OUT1 config*/sConfig.DAC_HighFrequency = DAC_HIGH_FREQUENCY_INTERFACE_MODE_DISABLE;sConfig.DAC_DMADoubleDataMode = DISABLE;sConfig.DAC_SignedFormat = DISABLE;sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;sConfig.DAC_Trigger = DAC_TRIGGER_NONE;sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_INTERNAL;sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK){Error_Handler();}/** Configure Autonomous Mode*/sAutonomousMode.AutonomousModeState = DAC_AUTONOMOUS_MODE_DISABLE;if (HAL_DACEx_SetConfigAutonomousMode(&hdac1, &sAutonomousMode) != HAL_OK){Error_Handler();}/** DAC channel OUT2 config*/if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK){Error_Handler();}/* USER CODE BEGIN DAC1_Init 2 *//* USER CODE END DAC1_Init 2 */}/*** @brief ICACHE Initialization Function* @param None* @retval None*/
static void MX_ICACHE_Init(void)
{/* USER CODE BEGIN ICACHE_Init 0 *//* USER CODE END ICACHE_Init 0 *//* USER CODE BEGIN ICACHE_Init 1 *//* USER CODE END ICACHE_Init 1 *//** Enable instruction cache in 1-way (direct mapped cache)*/if (HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY) != HAL_OK){Error_Handler();}if (HAL_ICACHE_Enable() != HAL_OK){Error_Handler();}/* USER CODE BEGIN ICACHE_Init 2 *//* USER CODE END ICACHE_Init 2 */}/*** @brief TIM1 Initialization Function* @param None* @retval None*/
static void MX_TIM1_Init(void)
{/* USER CODE BEGIN TIM1_Init 0 *//* USER CODE END TIM1_Init 0 */TIM_MasterConfigTypeDef sMasterConfig = {0};TIMEx_BreakInputConfigTypeDef sBreakInputConfig = {0};TIM_OC_InitTypeDef sConfigOC = {0};TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};/* USER CODE BEGIN TIM1_Init 1 *//* USER CODE END TIM1_Init 1 */htim1.Instance = TIM1;htim1.Init.Prescaler = 0;htim1.Init.CounterMode = TIM_COUNTERMODE_CENTERALIGNED2;htim1.Init.Period = 4000;htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;htim1.Init.RepetitionCounter = 0;htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;if (HAL_TIM_PWM_Init(&htim1) != HAL_OK){Error_Handler();}sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK){Error_Handler();}sBreakInputConfig.Source = TIM_BREAKINPUTSOURCE_COMP2;sBreakInputConfig.Enable = TIM_BREAKINPUTSOURCE_ENABLE;sBreakInputConfig.Polarity = TIM_BREAKINPUTSOURCE_POLARITY_HIGH;if (HAL_TIMEx_ConfigBreakInput(&htim1, TIM_BREAKINPUT_BRK, &sBreakInputConfig) != HAL_OK){Error_Handler();}sConfigOC.OCMode = TIM_OCMODE_PWM1;sConfigOC.Pulse = 0;sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK){Error_Handler();}if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK){Error_Handler();}sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_ENABLE;sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_ENABLE;sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;sBreakDeadTimeConfig.DeadTime = 130;sBreakDeadTimeConfig.BreakState = TIM_BREAK_ENABLE;sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_LOW;sBreakDeadTimeConfig.BreakFilter = 0;sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT;sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_LOW;sBreakDeadTimeConfig.Break2Filter = 0;sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT;sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK){Error_Handler();}/* USER CODE BEGIN TIM1_Init 2 *//* USER CODE END TIM1_Init 2 */HAL_TIM_MspPostInit(&htim1);}/*** @brief GPIO Initialization Function* @param None* @retval None*/
static void MX_GPIO_Init(void)
{GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 *//* GPIO Ports Clock Enable */__HAL_RCC_GPIOA_CLK_ENABLE();__HAL_RCC_GPIOB_CLK_ENABLE();__HAL_RCC_GPIOE_CLK_ENABLE();/*Configure GPIO pin Output Level */HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);/*Configure GPIO pin : PB7 */GPIO_InitStruct.Pin = GPIO_PIN_7;GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}/* USER CODE BEGIN 4 *//* USER CODE END 4 *//*** @brief  This function is executed in case of error occurrence.* @retval None*/
void Error_Handler(void)
{/* USER CODE BEGIN Error_Handler_Debug *//* User can add his own implementation to report the HAL error return state */__disable_irq();while (1){}/* USER CODE END Error_Handler_Debug */
}#ifdef  USE_FULL_ASSERT
/*** @brief  Reports the name of the source file and the source line number*         where the assert_param error has occurred.* @param  file: pointer to the source file name* @param  line: assert_param error line source number* @retval None*/
void assert_failed(uint8_t *file, uint32_t line)
{/* USER CODE BEGIN 6 *//* User can add his own implementation to report the file name and line number,ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) *//* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/**
* @brief COMP MSP Initialization
* This function configures the hardware resources used in this example
* @param hcomp: COMP handle pointer
* @retval None
*/
void HAL_COMP_MspInit(COMP_HandleTypeDef* hcomp)
{GPIO_InitTypeDef GPIO_InitStruct = {0};if(hcomp->Instance==COMP1){/* USER CODE BEGIN COMP1_MspInit 0 *//* USER CODE END COMP1_MspInit 0 *//* Peripheral clock enable */HAL_RCC_COMP_CLK_ENABLED++;if(HAL_RCC_COMP_CLK_ENABLED==1){__HAL_RCC_COMP_CLK_ENABLE();}__HAL_RCC_GPIOA_CLK_ENABLE();/**COMP1 GPIO ConfigurationPA2     ------> COMP1_INP*/GPIO_InitStruct.Pin = GPIO_PIN_2;GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;GPIO_InitStruct.Pull = GPIO_NOPULL;HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);/* USER CODE BEGIN COMP1_MspInit 1 *//* USER CODE END COMP1_MspInit 1 */}else if(hcomp->Instance==COMP2){/* USER CODE BEGIN COMP2_MspInit 0 *//* USER CODE END COMP2_MspInit 0 *//* Peripheral clock enable */HAL_RCC_COMP_CLK_ENABLED++;if(HAL_RCC_COMP_CLK_ENABLED==1){__HAL_RCC_COMP_CLK_ENABLE();}/* USER CODE BEGIN COMP2_MspInit 1 *//* USER CODE END COMP2_MspInit 1 */}}/**
* @brief COMP MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hcomp: COMP handle pointer
* @retval None
*/
void HAL_COMP_MspDeInit(COMP_HandleTypeDef* hcomp)
{if(hcomp->Instance==COMP1){/* USER CODE BEGIN COMP1_MspDeInit 0 *//* USER CODE END COMP1_MspDeInit 0 *//* Peripheral clock disable */HAL_RCC_COMP_CLK_ENABLED--;if(HAL_RCC_COMP_CLK_ENABLED==0){__HAL_RCC_COMP_CLK_DISABLE();}/**COMP1 GPIO ConfigurationPA2     ------> COMP1_INP*/HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2);/* USER CODE BEGIN COMP1_MspDeInit 1 *//* USER CODE END COMP1_MspDeInit 1 */}else if(hcomp->Instance==COMP2){/* USER CODE BEGIN COMP2_MspDeInit 0 *//* USER CODE END COMP2_MspDeInit 0 *//* Peripheral clock disable */HAL_RCC_COMP_CLK_ENABLED--;if(HAL_RCC_COMP_CLK_ENABLED==0){__HAL_RCC_COMP_CLK_DISABLE();}/* USER CODE BEGIN COMP2_MspDeInit 1 *//* USER CODE END COMP2_MspDeInit 1 */}}/**
* @brief DAC MSP Initialization
* This function configures the hardware resources used in this example
* @param hdac: DAC handle pointer
* @retval None
*/
void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)
{RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};if(hdac->Instance==DAC1){/* USER CODE BEGIN DAC1_MspInit 0 *//* USER CODE END DAC1_MspInit 0 *//** Initializes the peripherals clock*/PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADCDAC|RCC_PERIPHCLK_DAC1;PeriphClkInit.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HSI;PeriphClkInit.Dac1ClockSelection = RCC_DAC1CLKSOURCE_LSI;if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK){Error_Handler();}/* Peripheral clock enable */__HAL_RCC_DAC1_CLK_ENABLE();/* USER CODE BEGIN DAC1_MspInit 1 *//* USER CODE END DAC1_MspInit 1 */}}/**
* @brief DAC MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hdac: DAC handle pointer
* @retval None
*/
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
{if(hdac->Instance==DAC1){/* USER CODE BEGIN DAC1_MspDeInit 0 *//* USER CODE END DAC1_MspDeInit 0 *//* Peripheral clock disable */__HAL_RCC_DAC1_CLK_DISABLE();/* USER CODE BEGIN DAC1_MspDeInit 1 *//* USER CODE END DAC1_MspDeInit 1 */}}/**
* @brief TIM_PWM MSP Initialization
* This function configures the hardware resources used in this example
* @param htim_pwm: TIM_PWM handle pointer
* @retval None
*/
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
{if(htim_pwm->Instance==TIM1){/* USER CODE BEGIN TIM1_MspInit 0 *//* USER CODE END TIM1_MspInit 0 *//* Peripheral clock enable */__HAL_RCC_TIM1_CLK_ENABLE();/* TIM1 interrupt Init */HAL_NVIC_SetPriority(TIM1_UP_IRQn, 0, 0);HAL_NVIC_EnableIRQ(TIM1_UP_IRQn);/* USER CODE BEGIN TIM1_MspInit 1 *//* USER CODE END TIM1_MspInit 1 */}}void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
{GPIO_InitTypeDef GPIO_InitStruct = {0};if(htim->Instance==TIM1){/* USER CODE BEGIN TIM1_MspPostInit 0 *//* USER CODE END TIM1_MspPostInit 0 */__HAL_RCC_GPIOA_CLK_ENABLE();__HAL_RCC_GPIOB_CLK_ENABLE();__HAL_RCC_GPIOE_CLK_ENABLE();/**TIM1 GPIO ConfigurationPA7     ------> TIM1_CH1NPB0     ------> TIM1_CH2NPE9     ------> TIM1_CH1PE11     ------> TIM1_CH2*/GPIO_InitStruct.Pin = GPIO_PIN_7;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);GPIO_InitStruct.Pin = GPIO_PIN_0;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_11;GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;GPIO_InitStruct.Pull = GPIO_NOPULL;GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;GPIO_InitStruct.Alternate = GPIO_AF1_TIM1;HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);/* USER CODE BEGIN TIM1_MspPostInit 1 *//* USER CODE END TIM1_MspPostInit 1 */}}
/**
* @brief TIM_PWM MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param htim_pwm: TIM_PWM handle pointer
* @retval None
*/
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* htim_pwm)
{if(htim_pwm->Instance==TIM1){/* USER CODE BEGIN TIM1_MspDeInit 0 *//* USER CODE END TIM1_MspDeInit 0 *//* Peripheral clock disable */__HAL_RCC_TIM1_CLK_DISABLE();/* TIM1 interrupt DeInit */HAL_NVIC_DisableIRQ(TIM1_UP_IRQn);/* USER CODE BEGIN TIM1_MspDeInit 1 *//* USER CODE END TIM1_MspDeInit 1 */}}/*** @brief This function handles TIM1 Update interrupt.*/
void TIM1_UP_IRQHandler(void)
{/* USER CODE BEGIN TIM1_UP_IRQn 0 */static uint16_t SineCnt;static uint16_t GpioFlashCnt = 0x00;int32_t Spwm_Duty;/* USER CODE END TIM1_UP_IRQn 0 *///HAL_TIM_IRQHandler(&htim1);/* USER CODE BEGIN TIM1_UP_IRQn 1 */if((TIM1->SR & TIM_FLAG_UPDATE) == TIM_FLAG_UPDATE){//__HAL_TIM_CLEAR_FLAG(&htim1,TIM_FLAG_UPDATE);TIM1->SR = ~TIM_FLAG_UPDATE;if((TIM1->CR1 & TIM_CR1_DIR) == TIM_CR1_DIR)  {GpioFlashCnt++;if(GpioFlashCnt >= 10000){GpioFlashCnt = 0x00;HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_7);}Spwm_Duty = (int32_t)Sine[SineCnt] * 3600 >> 12;if(Spwm_Duty >= 0){HalSetInvPwmPosDuty(Spwm_Duty);  //Õý°ëÖÜHalSetInvPwmNegDuty(0);         }else{HalSetInvPwmPosDuty(0);                  //¸º°ëÖÜHalSetInvPwmNegDuty(abs(Spwm_Duty));                                 }SineCnt++;if(SineCnt >= 400)SineCnt = 0x00;}}/* USER CODE END TIM1_UP_IRQn 1 */
}

---------------------
作者:416775364TP
链接:https://bbs.21ic.com/icview-3290434-1-1.html
来源:21ic.com
此文章已获得原创/原创奖标签,著作权归21ic所有,任何人未经允许禁止转载。

这篇关于[STM32U5]【NUCLEO-U575ZI-Q测评】+ 逆变器逐波限流的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/642521

相关文章

Java后端微服务架构下的API限流策略:Guava RateLimiter

Java后端微服务架构下的API限流策略:Guava RateLimiter 大家好,我是微赚淘客返利系统3.0的小编,是个冬天不穿秋裤,天冷也要风度的程序猿! 在微服务架构中,API限流是保护服务不受过度使用和拒绝服务攻击的重要手段。Guava RateLimiter是Google开源的Java库中的一个组件,提供了简单易用的限流功能。 API限流概述 API限流通过控制请求的速率来防止

RT-Thread(Nano版本)的快速移植(基于NUCLEO-F446RE)

目录 概述 1 RT-Thread 1.1 RT-Thread的版本  1.2 认识Nano版本 2 STM32F446U上移植RT-Thread  2.1 STM32Cube创建工程 2.2 移植RT-Thread 2.2.1 安装RT-Thread Packet  2.2.2 加载RT-Thread 2.2.3 匹配相关接口 2.2.3.1 初次编译代码  2.2.3.

微服务之网关安全基于Zuul并实现网关限流

微服务网关安全 微服务架构下的问题 处理安全和业务逻辑耦合,增加了复杂性和变更成本 随着业务节点增加,认证服务器压力增大 多个微服务同时暴露,增加了外部访问的复杂性 通过网关处理流程 1、请求令牌。2、转发请求。3、返回令牌。4、转发令牌各客户端应用。5、携带令牌发送请求。6、校验令牌。7、返回校验结果信息。8、访问微服务。 实例 引入依赖 <dependencies><depe

等保测评中的安全审计与监控

等保测评中的安全审计与监控是确保信息系统安全的关键环节。安全审计主要通过记录和审查用户活动、系统操作及安全事件来帮助管理员及时发现潜在的安全威胁和漏洞。监控则涉及对信息系统的持续观察,以确保安全措施得到有效执行,并能够及时响应安全事件。         在等保测评中,安全审计的要求包括提供覆盖到每个用户的安全审计功能,保证无法单独中断审计进程,无法删除、修改或覆盖审计记录,以及提

网络安全评测评技术与标准

网络安全测评概况 概念 参照一定的标准规范要求,通过一系列技术和管理方法,获取评估对象网络安全状况信息,对其给出相应网络安全情况综合判定 测评对象:信息系统的组成要素或信息系统自身 CC(Common Criteria)标准:提出了“保护轮廓”概念,将评估过程分为“功能”和“保证”两部分,是目前最前面的信息技术安全评估标准 网络安全测评类型 网络安全测评流程与内容

等保测评:如何构建安全的远程工作环境

在构建安全的远程工作环境时,等保测评是一个重要的参考标准。根据等保测评的要求,企业应采取以下措施来确保远程工作环境的安全性: 身份鉴别和访问控制:确保所有远程访问都通过双向身份验证机制,并实施基于角色的访问控制策略,以限制对敏感资源的访问。 数据加密:对传输和存储的数据进行加密,以防止数据在传输过程中被窃取或在设备上被未授权访问。 安全审计:收集和分析审计数据,以监控和记录

谈谈经典限流方法—漏桶、令牌桶与Guava RateLimiter的实现

大数据技术与架构 点击右侧关注,大数据开发领域最强公众号! 暴走大数据 点击右侧关注,暴走大数据! 高并发的业务系统经常要接受大流量的考验,为了保证系统的响应度和稳定性,往往都需要对有风险的接口实施限流(rate limiting),更高大上的说法则是“流量整形”(traffic shaping)。限流的思想最初来源于计算机网络,有两种经典的方法:漏桶和令牌桶。本文先来稍微研究一下它们。

经典限流方法——漏桶、令牌桶与Guava RateLimiter的实现

点击上方蓝色字体,选择“设为星标” 回复”资源“获取更多资源 大数据技术与架构 点击右侧关注,大数据开发领域最强公众号! 暴走大数据 点击右侧关注,暴走大数据! 高并发的业务系统经常要接受大流量的考验,为了保证系统的响应度和稳定性,往往都需要对有风险的接口实施限流(rate limiting),更高大上的说法则是“流量整形”(traffic shaping)。限流的思想最初来源于计算机

骨传导耳机哪个牌子好用?精选五款黄金畅销骨传导机型测评

随着消费者对健康聆听方式的日益重视,骨传导耳机的市场需求持续高涨。众多耳机厂商在耳机的外观设计上倾注了大量心血,但在此过程中,部分品牌却忽视了产品的核心音质与佩戴舒适度,导致市场上涌现出一些外观时尚但内在品质不尽如人意的产品,这些耳机虽然有着高颜值的外观设计,但在后面的长期佩戴中,使用体却并不好,经常会出现佩戴不适、音质刺耳的情况,甚至严重的话还会对用户的听力健康造成潜在影响。那么,究竟哪些品牌的

lazada自养号秘籍:一次成号测评环境系统全解析

lazada自养号一次成号测评环境系统对于卖家来说算是一种低成本、高回报的推广营销方式,旨在通过模拟真实买家的行为来提升lazada平台上店铺的权重、排名和销量。以下是对该系统的详细介绍: 一、系统概述 lazada自养号测评环境系统是指卖家通过自行创建和管理买家账号,在模拟真实购物环境的基础上,进行产品浏览、收藏、加购、下单及评价等操作,以提升店铺的综合表现。该系统要求高度的稳定性和安全