Skip to main content
Visitor
July 23, 2026
Question

pwm generation on stm32f051c8t6

  • July 23, 2026
  • 3 replies
  • 35 views
/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>© Copyright (c) 2022 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "seven_seg.h"
#include "timer.h"
#include "74HC595.h"
#include "led.h"
#include "welding_mode.h"
#include "adc.h"
#include "led_data_update.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
unsigned char led_cmp;
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* 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 ---------------------------*/

ADC_HandleTypeDef hadc;
DAC_HandleTypeDef hdac1;
TIM_HandleTypeDef htim3;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_ADC_Init(void);
static void MX_DAC1_Init(void);
static void MX_TIM3_Init(void);


/* USER CODE BEGIN PFP */
void increment_led_mode();            //LED shifting sequentially(increment order)when encoder rotates in clock wise direction
void decrement_led_mode();            //LED shifting in increment order when encoder rotates in counter clock wise direction
void increment_7seg();                //Digit increment mode in 7-segment
void decrement_7seg();                //Digit decrement mode in 7-segment
/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/****************************************INTERRUPT CALL BACK FUNCTION**************************************************/

/**
 *
  */

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)//Interrupt call back function
{


  HAL_NVIC_DisableIRQ(EXTI4_15_IRQn);//Disable Interrupt
  //standby_value=0x01;
    if(GPIO_Pin == GPIO_PIN_10) // Check Interrupt from ENCODER input Pin-A
    {
    if(HAL_GPIO_ReadPin (GPIOB, GPIO_PIN_11))
      {
    if(HAL_GPIO_ReadPin (GPIOB, GPIO_PIN_10)==0)
          {
    if(led_mode==1)
          {
            decrement_led_mode();//shifting LED in counter clock wise direction
          }
    else if(seg_mode==1)
          {
            decrement_7seg();//Seven-segment Digit decrement mode
          }
        }


      }
    else if(HAL_GPIO_ReadPin (GPIOB, GPIO_PIN_11)==0) //check input signal from Encoder pin-B
    {
        if(HAL_GPIO_ReadPin (GPIOB, GPIO_PIN_10)==0)//check input signal from Encoder pin-A
          {
        if(led_mode==1)
          {
            increment_led_mode();//shifting LED in clock wise direction
          }


    else if(seg_mode==1)
          {
            increment_7seg();//Seven-segment Digit increment mode

          }
     }

    }


    }

    /*if(GPIO_Pin == GPIO_PIN_12)// Check Interrupt from ENCODER(when act as switch)
      {
    led_cmp=led_mode;
    led_mode=seg_mode;
    seg_mode=led_cmp;


      }*/
    HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
    //timer_reg=0x00;
    //HAL_TIM_Base_Start_IT(&htim3);//Timer start

}


/********************************************CALL BACK FUNCTION END****************************************************/


/* 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();
  LATCH_LOW;
  CLK_LOW;
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC_Init();
  MX_DAC1_Init();
  MX_TIM3_Init();


  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */


  led_reg1=0x01;
  led_reg2=0x00;
  led_reg3=0x01;
  led_mode=0x01;
  seg_mode=0x00;
  mma_mode_reg=0x01;
  tig_mode_reg=0x01;
  pulse_tig_mode_reg=0x01;

  mma_preflow=0x05;
  mma_current_1=0x05;
  mma_up_slope=0x00;
  mma_weld_curr=0x05;

  tig_preflow=0x01;
  tig_current_1=0x00;
  tig_up_slope=0x00;
  tig_weld_curr=0x00;
  tig_down_slope=0x00;
  tig_crater_curr=0x00;
  tig_post_flow=0x00;

  pulse_tig_preflow=0x01;
  pulse_tig_current_1=0x05;
  pulse_tig_up_slope=0x01;
  pulse_tig_weld_curr=0x05;
  pulse_tig_frequency=0x02;
  pulse_tig_duty=0x00;
  pulse_tig_base_curr=0x05;
  pulse_tig_down_slope=0x01;
  pulse_tig_crater_curr=0x00;
  pulse_tig_post_flow=0x01;
  HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);
  HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R,3720);//eee


  while (1)
  {

    sequence1_led_control_unit(led_reg1);
    sequence2_led_control_unit(led_reg2);
    Display_led();
    Display_7seg();
//      if(standby_value==0x01)
//        {
//          Display_7seg();
//        }
//      else
//
//          Display_amp_volt();
//if(timer_reg>5000)
//  {
//    HAL_TIM_Base_Stop_IT(&htim3);//Timer stop
//    standby_value=0x00;
//    timer_reg=0x00;
//  }
if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6)==0)//check switch press status of SW1
    {
    first3_led_update();
    }
if(HAL_GPIO_ReadPin(GPIOF, GPIO_PIN_6)==0)//check switch press status of SW2
    {
    second2_led_update();
    }
if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12)==0)//check encoder switch press status of SW3
     {
    led_cmp=led_mode;
    led_mode=seg_mode;
    seg_mode=led_cmp;
    //standby_value=0x01;
    while(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12)==0)
      {
          sequence1_led_control_unit(led_reg1);
          sequence2_led_control_unit(led_reg2);
          Display_led();
          Display_7seg();
          HAL_Delay(1);
       }
        //timer_reg=0x00;
        HAL_TIM_Base_Start_IT(&htim3);//Timer start
     }

if(led_reg1==1)//if mma mode then
  {
    arc_sence_value=read_arc_sence_value();
    if(arc_sence_value>1000)//check arc sense signal(add microcontroller pin)
      {
    mma_mode_welding();//welding in MMA mode
      }
  }
/*if(led_reg1==2)///if tig mode then
  {
    if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12)==1)
      {
    tig_mode_welding();///Welding in TIG mode
      }
  }*/
//if(led_reg1==3)//if pulse tig mode then
//  {
//    ///future implement
//  }

/*
if(HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_9)==0)//Check Torch Trigger Switch
    {

    }*/
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

void increment_7seg()
{
  if(led_reg1==0x01)
       {

       switch(mma_mode_reg)
       {
         case 1:if(mma_preflow<400)//LED-6
         mma_preflow++;//Arc Force
             break;

         case 2:if(mma_current_1<400)//LED-7
         mma_current_1++;//Hot Start Current (MMA)

             break;

         case 3:if(mma_up_slope<10)//LED-8
         mma_up_slope++;//Hot Start Time (MMA)
             break;

         case 4:if(mma_weld_curr<400)//LED-9
         mma_weld_curr++;//Weld Current (TIG/PTIG/MMA
             break;
       }
       }
     if(led_reg1==0x02)
       {
         switch(tig_mode_reg)
         {
           case 1:if(tig_preflow<200)//LED-6
         tig_preflow++;
               break;
           case 2:if(tig_current_1<400)//LED-7
         tig_current_1++;
               break;
           case 3:if(tig_up_slope<200)//LED-8
         tig_up_slope++;
               break;
           case 4:if(tig_weld_curr<400)//LED-9
         tig_weld_curr++;
               break;
           case 5:if(tig_down_slope<200)//LED-13
         tig_down_slope++;
               break;
           case 6:if(tig_crater_curr<400)//LED-14
         tig_crater_curr++;
               break;
           case 7:if(tig_post_flow<400)//LED-15
         tig_post_flow++;
               break;
         }
       }
     if(led_reg1==0x03)
       {
         switch(pulse_tig_mode_reg)
         {
           case 1:if(pulse_tig_preflow<200)//LED-6
           pulse_tig_preflow++;
               break;
           case 2:if(pulse_tig_current_1<400)//LED-7
           pulse_tig_current_1++;
               break;
           case 3:if(pulse_tig_up_slope<200)//LED-8
           pulse_tig_up_slope++;
               break;
           case 4:if(pulse_tig_weld_curr<400)//LED-9
           pulse_tig_weld_curr++;
               break;
           case 5:if(pulse_tig_frequency<1899)//LED-10
           pulse_tig_frequency++;
               break;
           case 6:if(pulse_tig_duty<90)//LED-11
           pulse_tig_duty++;
               break;
           case 7:if(pulse_tig_base_curr<400)//LED-12
           pulse_tig_base_curr++;
               break;
           case 8:if(pulse_tig_down_slope<200)//LED-13
           pulse_tig_down_slope++;
               break;
           case 9:if(pulse_tig_crater_curr<400)//LED-14
           pulse_tig_crater_curr++;
               break;
           case 10:if(pulse_tig_post_flow<400)//LED-15
           pulse_tig_post_flow++;
               break;
         }
       }
}

void decrement_7seg()
{
  if(led_reg1==0x01)
       {
       switch(mma_mode_reg)
       {
         case 1:if(mma_preflow>5)
         mma_preflow--;
             break;

         case 2:if(mma_current_1>5)
         mma_current_1--;
             break;

         case 3:if(mma_up_slope>0)
         mma_up_slope--;
             break;

         case 4:if(mma_weld_curr>5)
         mma_weld_curr--;
             break;
       }
       }
     if(led_reg1==0x02)
       {
         switch(tig_mode_reg)
         {
           case 1:if(tig_preflow>1)
         tig_preflow--;
               break;
           case 2:if(tig_current_1>5)
         tig_current_1--;
               break;
           case 3:if(tig_up_slope>1)
         tig_up_slope--;
               break;
           case 4:if(tig_weld_curr>5)
         tig_weld_curr--;
               break;
           case 5:if(tig_down_slope>1)
         tig_down_slope--;
               break;
           case 6:if(tig_crater_curr>5)
         tig_crater_curr--;
               break;
           case 7:if(tig_post_flow>1)
         tig_post_flow--;
               break;
         }
       }
     if(led_reg1==0x03)
       {
         switch(pulse_tig_mode_reg)
         {
           case 1:if(pulse_tig_preflow>1)
         pulse_tig_preflow--;
               break;
           case 2:if(pulse_tig_current_1>5)
         pulse_tig_current_1--;
               break;
           case 3:if(pulse_tig_up_slope>1)
         pulse_tig_up_slope--;
               break;
           case 4:if(pulse_tig_weld_curr>5)
         pulse_tig_weld_curr--;
               break;
           case 5:if(pulse_tig_frequency>2)
         pulse_tig_frequency--;
               break;
           case 6:if(pulse_tig_duty>0)
         pulse_tig_duty--;
               break;
           case 7:if(pulse_tig_base_curr>5)
         pulse_tig_base_curr--;
               break;
           case 8:if(pulse_tig_down_slope>1)
         pulse_tig_down_slope--;
               break;
           case 9:if(pulse_tig_crater_curr>5)
         pulse_tig_crater_curr--;
               break;
           case 10:if(pulse_tig_post_flow>1)
         pulse_tig_post_flow--;
               break;
         }
       }
}

void increment_led_mode()
{
  //for(unsigned int delay_reg=0x00;delay_reg<1000;delay_reg++);
  if(led_reg1==0x01)
    {
    if(mma_mode_reg<4)
      mma_mode_reg++;
    }
  else if(led_reg1==0x02)
    {
    if(tig_mode_reg<7)
      tig_mode_reg++;
    }
  else if(led_reg1==0x03)
    {
    if(pulse_tig_mode_reg<10)
    pulse_tig_mode_reg++;
    }
}
void decrement_led_mode()
{
  //for(unsigned int delay_reg=0x00;delay_reg<1000;delay_reg++);
  if(led_reg1==0x01)
    {
    if(mma_mode_reg>1)
     mma_mode_reg--;
    }
  else if(led_reg1==0x02)
    {
    if(tig_mode_reg>1)
    tig_mode_reg--;
    }
  else if(led_reg1==0x03)
    {
    if(pulse_tig_mode_reg>1)
    pulse_tig_mode_reg--;
    }

}
/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
  RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
  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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief ADC Initialization Function
  * @param None
  * @retval None
  */
static void MX_ADC_Init(void)
{

  /* USER CODE BEGIN ADC_Init 0 */

  /* USER CODE END ADC_Init 0 */

  ADC_ChannelConfTypeDef sConfig = {0};

  /* USER CODE BEGIN ADC_Init 1 */

  /* USER CODE END ADC_Init 1 */
  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  */
  hadc.Instance = ADC1;
  hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  hadc.Init.Resolution = ADC_RESOLUTION_12B;
  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc.Init.LowPowerAutoWait = DISABLE;
  hadc.Init.LowPowerAutoPowerOff = DISABLE;
  hadc.Init.ContinuousConvMode = ENABLE;
  hadc.Init.DiscontinuousConvMode = DISABLE;
  hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc.Init.DMAContinuousRequests = DISABLE;
  hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  if (HAL_ADC_Init(&hadc) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure for the selected ADC regular channel to be converted.
  */
  sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES_5;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure for the selected ADC regular channel to be converted.
  */
  sConfig.Channel = ADC_CHANNEL_1;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC_Init 2 */

  /* USER CODE END ADC_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};

  /* USER CODE BEGIN DAC1_Init 1 */

  /* USER CODE END DAC1_Init 1 */
  /** DAC Initialization
  */
  hdac1.Instance = DAC;
  if (HAL_DAC_Init(&hdac1) != HAL_OK)
  {
    Error_Handler();
  }
  /** DAC channel OUT1 config
  */
  sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
  sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
  if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN DAC1_Init 2 */

  /* USER CODE END DAC1_Init 2 */

}

/**
  * @brief TIM3 Initialization Function
  * @param None
  * @retval None
  */
static void MX_TIM3_Init(void)
{

  /* USER CODE BEGIN TIM3_Init 0 */

  /* USER CODE END TIM3_Init 0 */

  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};

  /* USER CODE BEGIN TIM3_Init 1 */

  /* USER CODE END TIM3_Init 1 */
  htim3.Instance = TIM3;
  htim3.Init.Prescaler = 4800-1;
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim3.Init.Period = 10-1;
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
  if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
  {
    Error_Handler();
  }
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
  {
    Error_Handler();
  }
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM3_Init 2 */

  /* USER CODE END TIM3_Init 2 */

}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOF_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_SET);

  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);

  /*Configure GPIO pins : PF1 PF6 */
  GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_6;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);

  /*Configure GPIO pin : PA3 */
  GPIO_InitStruct.Pin = GPIO_PIN_3;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pins : PA5 PA6 PA7 */
  GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : PB10 */
  GPIO_InitStruct.Pin = GPIO_PIN_10;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pins : PB11 PB12 PB6 PB9 */
  GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_6|GPIO_PIN_9;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /*Configure GPIO pin : PB14 */
  GPIO_InitStruct.Pin = GPIO_PIN_14;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* EXTI interrupt init*/
  HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);

  }

/* 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 */


in my code i want to generate a pwm 

For TIG 400J1 - Continuously shortJ2 - act as trigger J3 - as J2 gets short pwm signal will work in TIG mode ,Pulse TIG mode and in MMA mode no requirement of J2 on off directly pwm signal will get 

Post edited by ST moderator to follow the community rule to post a code snippet: How to write your question to maximize your chances to find a solution

3 replies

Andrew Neil
Super User
July 23, 2026

Welcome to the forum.

You need to provide more details of your setup, what you’re trying to achieve, and what problem(s) you’re experiencing.

Please see:

 

Also see:

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
SiddhiAuthor
Visitor
July 23, 2026

Is there any problem in the code please check 

 

ST Technical Moderator
July 23, 2026

Hello ​@Siddhi 

As ​@Andrew Neil mentioned you need to provide a clear description of the issue you are encountering.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
SiddhiAuthor
Visitor
July 23, 2026

I want to generate a pwm my project name For TIG 400

J1 - Continuously short

J2 - act as trigger 

J3 - as J2 gets short pwm signal will work in TIG mode ,Pulse TIG mode and in MMA mode no requirement of J2 on off directly pwm signal will get  I also have a ppt of this project 

 

Andrew Neil
Super User
July 23, 2026

What is “TIG 400” ?

What are J1, J2, J3 ?

etc, etc ...

 

Again, you need to give a clear and complete description of what you have, what you’re trying to achieve, and what problem(s) you’re facing.

 

Please read the article:

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.