Skip to main content
MMali.3
Visitor II
September 4, 2018
Question

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

  • September 4, 2018
  • 3 replies
  • 771 views
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

This topic has been closed for replies.

3 replies

henry.dick
Associate II
September 4, 2018

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

Tesla DeLorean
Guru
September 4, 2018

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

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
T J
Senior III
September 5, 2018

are you using PWM ?

where is the code ?

PWM can be adjusted "on the fly"