cancel
Showing results for 
Search instead for 
Did you mean: 

Low frequency square wave with distortion

stm32bero
Associate II

Hi, I'm new with stm32 and I want to get a simple 1Hz square wave in a NUCLEO-F446RE using CubeMX for the initial config. The code is so simple that I can't figure out where the problem is.

I just do:

  while (1)
  {
	  HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_8);
	  HAL_Delay(500);
  }

and my GPIO configuration:

static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
 
  /* GPIO Ports Clock Enable */
  __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOB_CLK_ENABLE();
 
  /*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, LD2_Pin|GPIO_PIN_8, GPIO_PIN_RESET);
 
  /*Configure GPIO pin : B1_Pin */
  GPIO_InitStruct.Pin = B1_Pin;
  GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
 
  /*Configure GPIO pins : LD2_Pin PA8 */
  GPIO_InitStruct.Pin = LD2_Pin|GPIO_PIN_8;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
}

But the signal I get:

0690X00000Aqr8qQAB.jpg

As I've seen, that distortion is not that big if I increase the frequency:

0690X00000Aqr90QAB.jpg

But still there. What's going on???

Thanks!

2 REPLIES 2
Bill Dempsey
Senior

Is it April 1? You are kidding , right? Coupling should be DC, not AC.

stm32bero
Associate II

I knew it had to be something very stupid but not that much! 😂 thanks!!