HI, i am new to stm32, i am working on the project stepper motor.
i am confused how to write a code to drive the stepper motor selecting the 2 timers with interrupt method. By setting one timer = 100khz, and another timer = 3khz. i need to display one pulse after 33 counts each on my oscilloscope. can you please help me with it. I have displayed some code below. can you please say me the mistakes i have done and what i need to add to it to work.
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == htim2.Instance) //100KHZ
{
pulse_count =__HAL_TIM_GET_COUNTER(&htim2);
if(pulse_count == 33)
{
HAL_GPIO_WritePin(GPIOA, dir_Pin, GPIO_PIN_SET); //pin PA3
for(int i=1; i<=300; i++)
{
HAL_GPIO_WritePin(GPIOA, step_Pin, GPIO_PIN_SET); //pin PA4
HAL_Delay(0.1);
HAL_GPIO_WritePin(GPIOA, step_Pin, GPIO_PIN_RESET); //pin PA4
HAL_Delay(0.1);
}
//HAL_Delay(500);
HAL_GPIO_WritePin(GPIOA, dir_Pin, GPIO_PIN_RESET); // anticlockwise
for(int i=1; i<=300; i++)
{
HAL_GPIO_WritePin(GPIOA, step_Pin, GPIO_PIN_SET); //pin PA4
HAL_Delay(0.1);
HAL_GPIO_WritePin(GPIOA, step_Pin, GPIO_PIN_RESET); //pin PA4
HAL_Delay(0.1);
}
pulse_count=0;
}
pulse_count++;
}
}
Thank you
