cancel
Showing results for 
Search instead for 
Did you mean: 

Signa A and B with 90 degree phase shift

HA.5
Associate III

Hello dear friends,

does any one know how i can have 2 signal with 90 degree phase shift? but i want to use this easy bit pattern to have it and not pwm, just with this bit pattern 00, 01, 11, 10, and also a sleep time for delay, it shouldn't be difficult, i know that i just need one timer, for example TIM16, but i have no idea any more.

here are my codes and so i have 70 degree phase shift, do you have any idea?

Thank you

 while (1)

 {

    HAL_TIM_Base_Start(&htim16);

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);

    HAL_TIM_Base_Stop(&htim16);

    HAL_TIM_Base_Start(&htim16);

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET);

    HAL_TIM_Base_Stop(&htim16);

    HAL_TIM_Base_Start(&htim16);

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET);

    HAL_TIM_Base_Stop(&htim16);

    HAL_TIM_Base_Start(&htim16);

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET);

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);

    HAL_TIM_Base_Stop(&htim16);

static void MX_TIM16_Init(void)

{

 /* USER CODE BEGIN TIM16_Init 0 */

 /* USER CODE END TIM16_Init 0 */

 /* USER CODE BEGIN TIM16_Init 1 */

 /* USER CODE END TIM16_Init 1 */

 htim16.Instance = TIM16;

 htim16.Init.Prescaler = 8;

 htim16.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim16.Init.Period = 1000;

 htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim16.Init.RepetitionCounter = 0;

 htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

 if (HAL_TIM_Base_Init(&htim16) != HAL_OK)

 {

   Error_Handler();

 }

 /* USER CODE BEGIN TIM16_Init 2 */

 /* USER CODE END TIM16_Init 2 */

}

    

3 REPLIES 3

Period and Prescaler expect N-1 value

ie DIV8 is 7 (0..7 counts)

Phase shifted 50/50 duty quadrature, might consider Toggle Mode with different phase angles expressed via CCRx registers. Period = 399, CCR1 = 0, CCR2 = 100

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
HA.5
Associate III

i don't get it, i think i should use a counter maybe, but i don't know how!!! i am sure that i need just one Timer, but how i can generate these pulses i have no idea!!

HA.5
Associate III

i did it with interrupts, thanks freinds