cancel
Showing results for 
Search instead for 
Did you mean: 

Hello Generating a Pulse Train of 0-200kHz on STM32L476 Nucleo. I Used the Timer to Generate The PWM of a specific Frequency.. That was successful

MMali.3
Associate
int main(void)
{
  /* USER CODE BEGIN 1 */
uint16_t Prescaler=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();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_TIM1_Init();
  /* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    htim1.Instance->PSC = Prescaler;
		Prescaler+=1;
		if(Prescaler>80) Prescaler=1;
		HAL_Delay(500);
  /* USER CODE END WHILE */
 
  /* USER CODE BEGIN 3 */
 
  }
  /* USER CODE END 3 */
 
}

I am trying to generate a pulse train Using the timer .

I am stuck in the task of changing the Frequency within the code in Keil micro vision 5

Need help

Thanks in advance

3 REPLIES 3
henry.dick
Senior II

Show your code and others will be more than happy to help you.​

The frequency is controlled by the ARR and PSC registers. ​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
T J
Lead

are you using PWM ?

where is the code ?

PWM can be adjusted "on the fly"